本文整理汇总了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()
: ""));
}
}
示例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()
: ""));
}
}
示例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()
: ""));
}
}
示例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);
}
示例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);
}
示例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()
: ""));
}
}
示例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()
: ""));
}
}
示例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()
: ""));
}
}
示例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);
}
示例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);
}
示例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");
}
}
示例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();
}
}
示例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());
}
示例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();
});
}
示例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); // 广播
}