本文整理匯總了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); // 廣播
}