下面列出了javax.websocket.Session#equals ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 关闭文件读取流
*
* @param fileName 文件名
*/
static void offlineFile(File fileName, Session session) {
AgentFileTailWatcher<Session> agentFileTailWatcher = CONCURRENT_HASH_MAP.get(fileName);
if (null == agentFileTailWatcher) {
return;
}
Set<Session> socketSessions = agentFileTailWatcher.socketSessions;
for (Session socketSession : socketSessions) {
if (socketSession.equals(session)) {
offline(socketSession);
break;
}
}
if (agentFileTailWatcher.socketSessions.isEmpty()) {
agentFileTailWatcher.close();
}
}
/**
* If there was something wrong with the connection, put it into logs.
*/
@OnClose
public void unregisterUser(Session websocket, CloseReason reason) {
Long lessonId = (Long) websocket.getUserProperties().get(AttributeNames.PARAM_LESSON_ID);
Set<Session> lessonWebsockets = PresenceWebsocketServer.websockets.get(lessonId);
Iterator<Session> sessionIterator = lessonWebsockets.iterator();
while (sessionIterator.hasNext()) {
Session storedSession = sessionIterator.next();
if (storedSession.equals(websocket)) {
sessionIterator.remove();
break;
}
}
if (PresenceWebsocketServer.log.isDebugEnabled()) {
PresenceWebsocketServer.log.debug("User " + websocket.getUserProperties().get(PARAM_NICKNAME)
+ " left Presence Chat with lessonId: " + lessonId
+ (!(reason.getCloseCode().equals(CloseCodes.GOING_AWAY)
|| reason.getCloseCode().equals(CloseCodes.NORMAL_CLOSURE))
? ". Abnormal close. Code: " + reason.getCloseCode() + ". Reason: "
+ reason.getReasonPhrase()
: "(unknown)"));
}
}
@OnMessage
public void onMessage(Session session, String msg, boolean last) {
try {
if (session.isOpen()) {
synchronized (clients) {
for(Session client : clients){
if (!client.equals(session)){
client.getBasicRemote().sendText(msg);
}
}
}
}
} catch (IOException e) {
try {
session.close();
} catch (IOException ioe) {
Debug.logError(ioe.getMessage(), module);
}
}
}
/**
* This method is invoked when a new message is received
*
* @param message Received string message
* @param session Client reference
* @throws IOException
*/
@OnMessage
public void onMessage(String message, Session session)
throws IOException {
P.out("New message: " + message + " from client: " + session);
synchronized (clients) {
for (Session client : clients) {
if (!client.equals(session)) {
client.getBasicRemote().sendText(message);
}
}
}
}
private boolean isUser1Session(Session userSession) {
return userSession != null && userSession1 != null && userSession.equals(userSession1.getUserSession());
}