Java 类javax.websocket.OnClose 实例源码

项目:lams    文件:LearningWebsocketServer.java   
/**
    * When user leaves the activity.
    */
   @OnClose
   public void unregisterUser(Session websocket, CloseReason reason) {
Long toolContentID = Long
    .valueOf(websocket.getRequestParameterMap().get(AttributeNames.PARAM_TOOL_CONTENT_ID).get(0));
websockets.get(toolContentID).remove(websocket);

if (log.isDebugEnabled()) {
    // If there was something wrong with the connection, put it into logs.
    log.debug("User " + websocket.getUserPrincipal().getName() + " left Dokumaran with Tool Content ID: "
        + toolContentID
        + (!(reason.getCloseCode().equals(CloseCodes.GOING_AWAY)
            || reason.getCloseCode().equals(CloseCodes.NORMAL_CLOSURE))
                ? ". Abnormal close. Code: " + reason.getCloseCode() + ". Reason: "
                    + reason.getReasonPhrase()
                : ""));
}
   }
项目:lams    文件:LearningWebsocketServer.java   
/**
    * When user leaves the activity.
    */
   @OnClose
   public void unregisterUser(Session websocket, CloseReason reason) {
Long toolSessionId = Long
    .valueOf(websocket.getRequestParameterMap().get(AttributeNames.PARAM_TOOL_SESSION_ID).get(0));
websockets.get(toolSessionId).remove(websocket);

if (log.isDebugEnabled()) {
    // If there was something wrong with the connection, put it into logs.
    log.debug("User " + websocket.getUserPrincipal().getName() + " left Leader Selection with Tool Session ID: "
        + toolSessionId
        + (!(reason.getCloseCode().equals(CloseCodes.GOING_AWAY)
            || reason.getCloseCode().equals(CloseCodes.NORMAL_CLOSURE))
                ? ". Abnormal close. Code: " + reason.getCloseCode() + ". Reason: "
                    + reason.getReasonPhrase()
                : ""));
}
   }
项目:lams    文件:PresenceWebsocketServer.java   
/**
    * If there was something wrong with the connection, put it into logs.
    */
   @OnClose
   public void unregisterUser(Session session, CloseReason reason) {
Long lessonId = Long.valueOf(session.getRequestParameterMap().get(AttributeNames.PARAM_LESSON_ID).get(0));
Set<Websocket> lessonWebsockets = PresenceWebsocketServer.websockets.get(lessonId);
Iterator<Websocket> websocketIterator = lessonWebsockets.iterator();
while (websocketIterator.hasNext()) {
    Websocket websocket = websocketIterator.next();
    if (websocket.session.equals(session)) {
    websocketIterator.remove();
    break;
    }
}

if (PresenceWebsocketServer.log.isDebugEnabled()) {
    PresenceWebsocketServer.log.debug(
        "User " + session.getUserPrincipal().getName() + " 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()
                    : ""));
}
   }
项目:lams    文件:KumaliveWebsocketServer.java   
@OnClose
   public void unregisterUser(Session websocket, CloseReason reason) throws JSONException, IOException {
String login = websocket.getUserPrincipal().getName();
if (login == null) {
    return;
}

Integer organisationId = Integer
    .valueOf(websocket.getRequestParameterMap().get(AttributeNames.PARAM_ORGANISATION_ID).get(0));
KumaliveDTO kumalive = kumalives.get(organisationId);
if (kumalive == null) {
    return;
}
KumaliveUser user = kumalive.learners.remove(login);
if (user != null) {
    Integer userId = user.userDTO.getUserID();
    if (kumalive.raisedHand != null) {
    kumalive.raisedHand.remove(userId);
    }
    if (userId.equals(kumalive.speaker)) {
    kumalive.speaker = null;
    }
}

sendRefresh(kumalive);
   }
项目:lams    文件:CommandWebsocketServer.java   
/**
    * Removes Learner websocket from the collection.
    */
   @OnClose
   public void unregisterUser(Session session, CloseReason reason) {
String login = session.getUserPrincipal().getName();
if (login == null) {
    return;
}

Long lessonId = Long.valueOf(session.getRequestParameterMap().get(AttributeNames.PARAM_LESSON_ID).get(0));
Map<String, Session> lessonWebsockets = CommandWebsocketServer.websockets.get(lessonId);
if (lessonWebsockets == null) {
    return;
}

lessonWebsockets.remove(login);
   }
项目:lams    文件:LearningWebsocketServer.java   
/**
    * When user leaves the activity.
    */
   @OnClose
   public void unregisterUser(Session session, CloseReason reason) {
Long toolSessionId = Long
    .valueOf(session.getRequestParameterMap().get(AttributeNames.PARAM_TOOL_SESSION_ID).get(0));
Set<Websocket> sessionWebsockets = LearningWebsocketServer.websockets.get(toolSessionId);
Iterator<Websocket> websocketIterator = sessionWebsockets.iterator();
while (websocketIterator.hasNext()) {
    Websocket websocket = websocketIterator.next();
    if (websocket.session.equals(session)) {
    websocketIterator.remove();
    break;
    }
}

if (LearningWebsocketServer.log.isDebugEnabled()) {
    LearningWebsocketServer.log.debug(
        "User " + session.getUserPrincipal().getName() + " left Chat with toolSessionId: " + toolSessionId
            + (!(reason.getCloseCode().equals(CloseCodes.GOING_AWAY)
                || reason.getCloseCode().equals(CloseCodes.NORMAL_CLOSURE))
                    ? ". Abnormal close. Code: " + reason.getCloseCode() + ". Reason: "
                        + reason.getReasonPhrase()
                    : ""));
}
   }
项目:lams    文件:LearningWebsocketServer.java   
/**
    * When user leaves the activity.
    */
   @OnClose
   public void unregisterUser(Session websocket, CloseReason reason) {
Long toolSessionId = Long
    .valueOf(websocket.getRequestParameterMap().get(AttributeNames.PARAM_TOOL_SESSION_ID).get(0));
LearningWebsocketServer.websockets.get(toolSessionId).remove(websocket);

if (LearningWebsocketServer.log.isDebugEnabled()) {
    // If there was something wrong with the connection, put it into logs.
    LearningWebsocketServer.log.debug("User " + websocket.getUserPrincipal().getName()
        + " left Scratchie with Tool Session ID: " + toolSessionId
        + (!(reason.getCloseCode().equals(CloseCodes.GOING_AWAY)
            || reason.getCloseCode().equals(CloseCodes.NORMAL_CLOSURE))
                ? ". Abnormal close. Code: " + reason.getCloseCode() + ". Reason: "
                    + reason.getReasonPhrase()
                : ""));
}
   }
项目:lams    文件:LearningWebsocketServer.java   
/**
    * When user leaves the activity.
    */
   @OnClose
   public void unregisterUser(Session websocket, CloseReason reason) {
Long toolSessionId = Long
    .valueOf(websocket.getRequestParameterMap().get(AttributeNames.PARAM_TOOL_SESSION_ID).get(0));
LearningWebsocketServer.websockets.get(toolSessionId).remove(websocket);

if (LearningWebsocketServer.log.isDebugEnabled()) {
    // If there was something wrong with the connection, put it into logs.
    LearningWebsocketServer.log.debug("User " + websocket.getUserPrincipal().getName()
        + " left Scribe with Tool Session ID: " + toolSessionId
        + (!(reason.getCloseCode().equals(CloseCodes.GOING_AWAY)
            || reason.getCloseCode().equals(CloseCodes.NORMAL_CLOSURE))
                ? ". Abnormal close. Code: " + reason.getCloseCode() + ". Reason: "
                    + reason.getReasonPhrase()
                : ""));
}
   }
项目:ZStreamingQuote    文件:WebsocketClientEndpoint.java   
/**
 * Callback hook for Connection close events.
 * 
 * @param userSession
 *            the userSession which is getting closed.
 * @param reason
 *            the reason for connection close
 */
@OnClose
public void onClose(Session userSession, CloseReason reason) {
    System.out.println(
            "WebsocketClientEndpoint.onClose(): Closing Websocket.... Reason[" + reason.getReasonPhrase() + "]");
    try {
        this.userSession.close();
    } catch (IOException e) {
        System.out.println("WebsocketClientEndpoint.onClose(): ERROR: IOException on userSession close!!!");
        e.printStackTrace();
    }
    this.userSession = null;

    // stop timer if running
    if (hbTimer != null) {
        hbTimer.cancel();
        hbTimer = null;
    }

    // Notify session closed
    sessionNotifier.notifyWsSessionClosed(terminate);
}
项目:Shufflepuff    文件:WebsocketServerChannel.java   
@OnClose
public void onClose(Session userSession, CloseReason reason) throws InterruptedException {

    String sessionIp = ((TyrusSession)userSession).getRemoteAddr();
    InetAddress identity;

    try {
        identity = InetAddress.getByName(sessionIp);
    } catch (UnknownHostException er) {
        return;
    }

    try {
        userSession.close();
    } catch (IOException e) {
        return;
    }

    localOpenSessions.remove(identity);
    localPeers.remove(identity);
    receiveMap.get(userSession).close();
    receiveMap.remove(userSession);
}
项目:che    文件:BasicWebSocketEndpoint.java   
@OnClose
public void onClose(CloseReason closeReason, Session session) {
  Optional<String> endpointIdOptional = registry.get(session);

  String combinedEndpointId;
  if (endpointIdOptional.isPresent()) {
    combinedEndpointId = endpointIdOptional.get();

    LOG.debug("Web socket session closed");
    LOG.debug("Endpoint: {}", combinedEndpointId);
    LOG.debug("Close reason: {}:{}", closeReason.getReasonPhrase(), closeReason.getCloseCode());

    registry.remove(combinedEndpointId);
    sessionMessagesBuffer.remove(session);
  } else {
    LOG.warn("Closing unidentified session");
  }
}
项目:cerberus-source    文件:TestCaseExecutionEndPoint.java   
/**
 * Callback when receiving closed connection from client side
 *
 * @param session     the client {@link Session}
 * @param executionId the execution identifier from the {@link ServerEndpoint} path
 */
@OnClose
public void closedConnection(Session session, @PathParam("execution-id") long executionId) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Session " + session.getId() + " closed connection to execution " + executionId);
    }
    mainLock.lock();
    try {
        sessions.remove(session.getId());
        Set<String> registeredSessions = executions.get(executionId);
        if (registeredSessions != null) {
            registeredSessions.remove(session.getId());
        }
    } finally {
        mainLock.unlock();
    }
}
项目:SPLGroundControl    文件:WSEndpoint.java   
@OnClose
public void onClose(Session session) throws InterruptedException {
    ClientSession clientSession = sessions.get(session.getId());

    if (clientSession != null) {
        clientSession.onClose();
        sessions.remove(session.getId());
    }

    System.out.printf("webSocket %s session closed.", session.getId());
}
项目:Clipcon-Client    文件:Endpoint.java   
@OnClose
public void onClose() {
    // show dialog when the web socket is disconnected
    Platform.runLater(() -> {
        dialog = new PlainDialog("�������� ������ ������ϴ�.", true);
        dialog.showAndWait();
    });
}
项目:belling-admin    文件:OnlineNoticeServer.java   
/**
 * 连接关闭调用的方法-与前端JS代码对应
 */
@OnClose
public void onClose() {
    webSocketSet.remove(this); // 从set中删除
    routetabMap.remove(userid); 
    OnlineUserlist.remove(userid);
    System.out.println(userid + " -> 已下线");
    String message = getMessage(userid + " -> 已下线", "notice", OnlineUserlist);
    broadcast(message);
    //singleSend(message, sn); // 广播
}
项目:Clipcon-Server    文件:UserController.java   
@OnClose
public void handleClose(Session userSession) {
    if (userSession == null) {
        System.out.println("Session is null");
    }
    System.err.println("[UserController] Session is closed. User terminated the program.");
    session = null;
    exitUserAtGroup();
    System.out.println("[handleClose] " + UploadServlet.uploadTime());
    // System.out.println("session open: " + session.isOpen());

}
项目:websocket-chat    文件:ChatServer.java   
@OnClose
public void onCloseCallback() {
    if(!dupUserDetected){
        processLogout();
    }

}
项目:apache-tomcat-7.0.73-with-comment    文件:ChatAnnotation.java   
@OnClose
public void end() {
    connections.remove(this);
    String message = String.format("* %s %s",
            nickname, "has disconnected.");
    broadcast(message);
}
项目:apache-tomcat-7.0.73-with-comment    文件:ChatAnnotation.java   
@OnClose
public void end() {
    connections.remove(this);
    String message = String.format("* %s %s",
            nickname, "has disconnected.");
    broadcast(message);
}
项目:maintain-robot    文件:WebSocketModule.java   
@OnClose
public void end(Session session) {
    log.info("*** WebSocket closed from sessionId " + session.getId());
    for (Map.Entry<String, Session> entry : sessionMap.entrySet()) {
        if (entry.getValue().getId().equals(session.getId())) {
            sessionMap.remove(entry.getKey());
        }
    }
}
项目:scalable-websocket-chat-with-hazelcast    文件:ChatServer.java   
@OnClose
public void onCloseCallback() {
    if (!dupUserDetected) {
        USERS.remove(this.user);
        SESSIONS.remove(s);
        processLogout();
    }

}
项目:BasicsProject    文件:WSMI.java   
/**连接关闭调用的方法*/
@OnClose
public void onClose(Session session){
    if(mapSU.get(session)!=null){
        Long userId=mapSU.get(session);
        mapUS.remove(userId);
        mapSU.remove(session);
        onlineCount--;
        System.out.println("用户"+userId+"退出WebSocket!当前在线人数为" + onlineCount);
    }
}
项目:cjs_ssms    文件:WebSocketController.java   
/**
 * 连接关闭调用的方法
 */
@OnClose
public void onClose() {
  webSocketSet.remove(this);  //从set中删除
  subOnlineCount();           //在线数减1
  log.debug("有一连接关闭!当前在线人数为" + getOnlineCount());
}
项目:grain    文件:WebSocketServer.java   
@OnClose
public void onClose(Session session, CloseReason closeReason) {
    try {
        ThreadMsgManager.dispatchThreadMsg(WSMsg.WEBSOCKET_CLIENT_DISCONNECT, null, session);
    } catch (Exception e) {
        if (WSManager.log != null) {
            WSManager.log.error("MsgManager.dispatchMsg error", e);
        }
    }
}
项目:grain    文件:WebSocketServer.java   
@OnClose
public void onClose(Session session, CloseReason closeReason) {
    try {
        MsgManager.dispatchMsg(WSMsg.WEBSOCKET_CLIENT_DISCONNECT, null, session);
    } catch (Exception e) {
        if (WSManager.log != null) {
            WSManager.log.error("MsgManager.dispatchMsg error", e);
        }
    }
}
项目:bluetag    文件:WSLocationResource.java   
@OnClose
public void onClose(Session session, CloseReason reason) {
    System.out.println("Session " + session.getId() + " has ended. Reason: " + reason);


    if (user != null) {
        locationService.sendClosingLocation(user);
        System.out.println("Closed out user: " + user);
    } else {
        System.out.println("Something went wrong with setting the user");

    }
}
项目:cito    文件:AbstractEndpoint.java   
@OnClose
@Override
public void onClose(Session session, CloseReason reason) {
    this.log.info("WebSocket connection closed. [id={},principle={},code={},reason={}]", session.getId(), session.getUserPrincipal(), reason.getCloseCode(), reason.getReasonPhrase());
    final WebSocketContext ctx = webSocketContext(this.beanManager);
    try (QuietClosable c = ctx.activate(session)) {
        this.registry.unregister(session);
        this.sessionEvent.select(cito.annotation.OnClose.Literal.onClose()).fire(session);
    }
    ctx.dispose(session);
}
项目:mycore    文件:MCRProcessingEndpoint.java   
@OnClose
public void close(Session session) {
    SessionListener sessionListener = SESSIONS.get(session.getId());
    if (sessionListener != null) {
        sessionListener.detachListeners(this.registry);
        SESSIONS.remove(session.getId());
    }
}
项目:OpenChatAlytics    文件:RealtimeResource.java   
/**
 * Closes a session
 *
 * @param session
 *            The session to close
 * @param reason
 *            The reason for closing
 */
@OnClose
public void close(Session session, CloseReason reason) {
    LOG.info("Closing session {}. Reason {}", session.getId(), reason);
    try {
        session.close();
    } catch (IOException e) {
        LOG.warn("Couldn't close {}. Reason {}", session.getId(), e.getMessage());
    }
    sessions.remove(session);
}
项目:OpenChatAlytics    文件:EventsResource.java   
/**
 * Closes a session
 *
 * @param session
 *            The session to close
 * @param reason
 *            The reason for closing
 */
@OnClose
public void close(Session session, CloseReason reason) {
    if (session.getRequestURI().getPath().startsWith(RT_EVENT_ENDPOINT)) {
        LOG.info("Closing session {}. Reason {}", session.getId(), reason);
        try {
            sessions.remove(session);
            session.close();
        } catch (IOException e) {
            LOG.warn("Couldn't close {}", session.getId());
        }
    } else {
        connectedToCompute = false;
    }
}
项目:mdswriter    文件:MDSWriterEndpoint.java   
/** The user closes the connection.
   *  Note: you can't send messages to the client from this method. */
  @OnClose
  public void onClose(final Session session) {
    Date now = new Date();
    log(now, session, "-- Session closed --");
try {
    saveInteraction(new Interaction(now, session, "CBYE", ""));
} catch (SQLException e) {
    // Ignore this exception.
    e.printStackTrace();
}
  }
项目:JavaWeb    文件:ChartController.java   
@OnClose
public void onClose(Session session,@PathParam("username") String username) {
    try{
        client.remove(session);
        user.remove(URLEncoder.encode(username, "UTF-8"));
        session.close();
    }catch(Exception e){
        //do nothing
    }
}
项目:mdw    文件:WebSocketMessenger.java   
@OnClose
public void unsubscribe(Session session, CloseReason reason) {
    synchronized(topicSubscribers) {
        // remove session
        for (List<Session> sessions : topicSubscribers.values()) {
            if (sessions.contains(session))
                sessions.remove(session);
        }
        // remove topics without any sessions
        for (String topic : topicSubscribers.keySet()) {
            if (topicSubscribers.get(topic).isEmpty())
                topicSubscribers.remove(topic);
        }
    }
}
项目:SpringBootUnity    文件:MyWebSocket.java   
/**
 * 有人离开房间
 */
@OnClose
public void onClose() {
    webSocketSet.remove(this);
    subOnlineCount();
    System.out.println("有一用户关闭!当前在线人数为" + getOnlineCount());
}
项目:guacamole-client    文件:GuacamoleWebSocketTunnelEndpoint.java   
@Override
@OnClose
public void onClose(Session session, CloseReason closeReason) {

    try {
        if (tunnel != null)
            tunnel.close();
    }
    catch (GuacamoleException e) {
        logger.debug("Unable to close WebSocket tunnel.", e);
    }

}
项目:StreamUp    文件:StreamingEndpoint.java   
@OnClose
public void onClose(Session session) {
    sessions.remove(session);

    Message message = new Message(Json.createObjectBuilder().add("type", "text").add("data", "User has disconnected").build());

    for (Session s : sessions) {
        try {
            s.getBasicRemote().sendObject(message);
        } catch (IOException | EncodeException ex) {
            ex.printStackTrace();
        }
    }
    log.debug("User disconnected");
}
项目:iote2e    文件:ServerSideSocketIote2eRequest.java   
/**
 * On web socket close.
 *
 * @param reason the reason
 */
@OnClose
public void onWebSocketClose(CloseReason reason) {
    boolean isRemove = ThreadEntryPointIote2eRequest.serverSideSocketIote2eRequest.remove(keyCommon, this);
    logger.info("Socket Closed: " + reason + ", isRemove=" + isRemove);
    shutdownThreadIgniteSubscribe();
}
项目:iote2e    文件:ServerSideSocketNearRealTime.java   
/**
 * On web socket close.
 *
 * @param reason the reason
 */
@OnClose
public void onWebSocketClose(CloseReason reason) {
    boolean isRemove = ThreadEntryPointNearRealTime.serverSideSocketNearRealTimes.remove(Iote2eConstants.SOCKET_KEY_NRT, this);
    logger.info("Socket Closed: " + reason + ", isRemove=" + isRemove);
    shutdownThreadIgniteSubscribe();
}
项目:Purifinity    文件:PurifinityServerStatusSocket.java   
@OnClose
   public void close(CloseReason reason) {
String reasonPhrase = reason != null ? reason.getReasonPhrase()
    : "<no reason provided>";
eventLogger.logEvent(PurifinityServerStatusSocketEvents
    .createSocketCloseEvent(reasonPhrase));
   }
项目:Purifinity    文件:PurifinityJobsSocket.java   
@OnClose
public void close(CloseReason reason) {
    String reasonPhrase = reason != null ? reason.getReasonPhrase()
            : "<no reason provided>";
    eventLogger.logEvent(PurifinityJobsSocketEvents
            .createSocketCloseEvent(reasonPhrase));
}