Java Code Examples for javax.websocket.Session#equals()

The following examples show how to use javax.websocket.Session#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AgentFileTailWatcher.java    From Jpom with MIT License 6 votes vote down vote up
/**
 * 关闭文件读取流
 *
 * @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();
    }

}
 
Example 2
Source File: PresenceWebsocketServer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
    * 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)"));
}
   }
 
Example 3
Source File: ExampleWebSockets.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
@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);
        }
    }
}
 
Example 4
Source File: Demo_JettyWebSocketServer.java    From haxademic with MIT License 5 votes vote down vote up
/**
 * 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);
			}
		}
	}
}
 
Example 5
Source File: Room.java    From eplmp with Eclipse Public License 1.0 4 votes vote down vote up
private boolean isUser1Session(Session userSession) {
    return userSession != null && userSession1 != null && userSession.equals(userSession1.getUserSession());
}
 
Example 6
Source File: Room.java    From eplmp with Eclipse Public License 1.0 4 votes vote down vote up
private boolean isUser2Session(Session userSession) {
    return userSession != null && userSession2 != null && userSession.equals(userSession2.getUserSession());
}