当前位置: 首页>>代码示例>>Java>>正文


Java OnClose类代码示例

本文整理汇总了Java中javax.websocket.OnClose的典型用法代码示例。如果您正苦于以下问题:Java OnClose类的具体用法?Java OnClose怎么用?Java OnClose使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OnClose类属于javax.websocket包,在下文中一共展示了OnClose类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: unregisterUser

import javax.websocket.OnClose; //导入依赖的package包/类
/**
    * 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()
			    : ""));
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:LearningWebsocketServer.java

示例2: unregisterUser

import javax.websocket.OnClose; //导入依赖的package包/类
/**
    * 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()
			    : ""));
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:LearningWebsocketServer.java

示例3: unregisterUser

import javax.websocket.OnClose; //导入依赖的package包/类
/**
    * 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()
				    : ""));
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:PresenceWebsocketServer.java

示例4: unregisterUser

import javax.websocket.OnClose; //导入依赖的package包/类
@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);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:KumaliveWebsocketServer.java

示例5: unregisterUser

import javax.websocket.OnClose; //导入依赖的package包/类
/**
    * 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);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:CommandWebsocketServer.java

示例6: unregisterUser

import javax.websocket.OnClose; //导入依赖的package包/类
/**
    * 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()
				    : ""));
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:LearningWebsocketServer.java

示例7: unregisterUser

import javax.websocket.OnClose; //导入依赖的package包/类
/**
    * 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()
			    : ""));
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:LearningWebsocketServer.java

示例8: unregisterUser

import javax.websocket.OnClose; //导入依赖的package包/类
/**
    * 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()
			    : ""));
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:LearningWebsocketServer.java

示例9: onClose

import javax.websocket.OnClose; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:instruritesh,项目名称:ZStreamingQuote,代码行数:30,代码来源:WebsocketClientEndpoint.java

示例10: onClose

import javax.websocket.OnClose; //导入依赖的package包/类
@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);
}
 
开发者ID:DanielKrawisz,项目名称:Shufflepuff,代码行数:24,代码来源:WebsocketServerChannel.java

示例11: onClose

import javax.websocket.OnClose; //导入依赖的package包/类
@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");
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:BasicWebSocketEndpoint.java

示例12: closedConnection

import javax.websocket.OnClose; //导入依赖的package包/类
/**
 * 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();
    }
}
 
开发者ID:cerberustesting,项目名称:cerberus-source,代码行数:23,代码来源:TestCaseExecutionEndPoint.java

示例13: onClose

import javax.websocket.OnClose; //导入依赖的package包/类
@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());
}
 
开发者ID:envirover,项目名称:SPLGroundControl,代码行数:12,代码来源:WSEndpoint.java

示例14: onClose

import javax.websocket.OnClose; //导入依赖的package包/类
@OnClose
public void onClose() {
	// show dialog when the web socket is disconnected
	Platform.runLater(() -> {
		dialog = new PlainDialog("�������� ������ ������ϴ�.", true);
		dialog.showAndWait();
	});
}
 
开发者ID:Team-Sprout,项目名称:Clipcon-Client,代码行数:9,代码来源:Endpoint.java

示例15: onClose

import javax.websocket.OnClose; //导入依赖的package包/类
/**
 * 连接关闭调用的方法-与前端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); // 广播
}
 
开发者ID:butter-fly,项目名称:belling-admin,代码行数:14,代码来源:OnlineNoticeServer.java


注:本文中的javax.websocket.OnClose类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。