本文整理汇总了Java中org.springframework.web.socket.messaging.SessionDisconnectEvent类的典型用法代码示例。如果您正苦于以下问题:Java SessionDisconnectEvent类的具体用法?Java SessionDisconnectEvent怎么用?Java SessionDisconnectEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SessionDisconnectEvent类属于org.springframework.web.socket.messaging包,在下文中一共展示了SessionDisconnectEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onApplicationEvent
import org.springframework.web.socket.messaging.SessionDisconnectEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(SessionDisconnectEvent event) {
Entity entity = entityRepository.findByStompSessionIdAndStompUsername(event.getSessionId(), event.getUser().getName());
if (entity != null) {
if (entity.getX() != null || entity.getY() != null || entity.getZ() != null) {
GameOutput enterMessage = new GameOutput(String.format("[yellow]%s has left the game.", entity.getName()));
entityService.sendMessageToRoom(entity.getX(), entity.getY(), entity.getZ(), entity, enterMessage);
LOGGER.info("{} has disconnected from the game", entity.getName());
}
worldManager.remove(entity);
}
}
示例2: testDisconnectListner
import org.springframework.web.socket.messaging.SessionDisconnectEvent; //导入依赖的package包/类
/**
* Tests that we request to disconnect based on the session id.
*/
@Test
public void testDisconnectListner() {
final String sessionId = "my-session-id";
final SessionDisconnectEvent mockEvent = mock(SessionDisconnectEvent.class);
when(mockEvent.getSessionId()).thenReturn(sessionId);
// Create mock Manager
final WebSocketConsumersManager mockManager = mock(WebSocketConsumersManager.class);
// Create our listener
final PresenceEventListener eventListener = new PresenceEventListener(mockManager);
// Call method
eventListener.handleSessionDisconnect(mockEvent);
// validate
verify(mockManager, times(1)).removeConsumersForSessionId(eq(sessionId));
}
示例3: onSessionDisConnected
import org.springframework.web.socket.messaging.SessionDisconnectEvent; //导入依赖的package包/类
@EventListener
public void onSessionDisConnected(SessionDisconnectEvent event) {
Message msg = event.getMessage();
StompHeaderAccessor accessor = StompHeaderAccessor.wrap(msg);
String sessionId = accessor.getSessionId();
String spaceKey = (String) webSocketSessionStore.getAttribute(sessionId, "spaceKey");
log.debug("Session disconnect: spaceKey => {}, sessionId => {} ", spaceKey, sessionId);
if (spaceKey == null) {
return;
}
onlineWorkspaceStore.removeSession(spaceKey, sessionId);
boolean isToBeOffline = onlineWorkspaceStore.isEmpty(spaceKey);
if (isToBeOffline) {
eventPublisher.publishEvent(new WorkspaceOfflineEvent(event, spaceKey));
}
}
示例4: afterConnectionClosed
import org.springframework.web.socket.messaging.SessionDisconnectEvent; //导入依赖的package包/类
@Override
public void afterConnectionClosed(WebSocketSession webSocketSession,
CloseStatus closeStatus) throws Exception {
Principal principal = webSocketSession.getPrincipal();
if (principal != null) {
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor
.create(SimpMessageType.MESSAGE);
accessor.setSessionId(webSocketSession.getId());
publishEvent(new SessionDisconnectEvent(this,
MessageBuilder.createMessage(new byte[0],
accessor.getMessageHeaders()),
webSocketSession.getId(), closeStatus, principal));
}
super.afterConnectionClosed(webSocketSession, closeStatus);
}
示例5: onApplicationEvent
import org.springframework.web.socket.messaging.SessionDisconnectEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(SessionDisconnectEvent event) {
if (log.isDebugEnabled()) {
log.debug("Caught Web Socket disconnect event");
}
String id = event.getSessionId();
if (StringUtils.isBlank(id)) {
return;
}
if (log.isDebugEnabled()) {
log.debug("Current web socket session id: " + id);
}
ActiveWebSocketUser user = repository.findUserBySessionId(id);
if (user == null) {
return;
}
repository.delete(user.getId());
// messagingTemplate.convertAndSend("/topic/friends/signout", Arrays.asList(user.getUsername()));
}
示例6: onApplicationEvent
import org.springframework.web.socket.messaging.SessionDisconnectEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(SessionDisconnectEvent event) {
ActivityDTO activityDTO = new ActivityDTO();
activityDTO.setSessionId(event.getSessionId());
activityDTO.setPage("logout");
messagingTemplate.convertAndSend("/topic/tracker", activityDTO);
}
示例7: setUp
import org.springframework.web.socket.messaging.SessionDisconnectEvent; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
entityRepository = mock(EntityRepository.class);
worldManager = mock(WorldManager.class);
entityService = mock(EntityService.class);
principal = mock(OAuth2Authentication.class);
event = mock(SessionDisconnectEvent.class);
entity = mock(Entity.class);
room = mock(Room.class);
when(event.getSessionId()).thenReturn(simpSessionId);
when(event.getUser()).thenReturn(principal);
when(principal.getName()).thenReturn(socialUserName);
when(entityRepository.findByStompSessionIdAndStompUsername(
eq(simpSessionId),
eq(socialUserName)
)).thenReturn(entity);
when(entity.getX()).thenReturn(0L);
when(entity.getY()).thenReturn(0L);
when(entity.getZ()).thenReturn(0L);
stompDisconnectListener = new StompDisconnectListener(
entityRepository,
worldManager,
entityService
);
}
示例8: handleSessionDisconnect
import org.springframework.web.socket.messaging.SessionDisconnectEvent; //导入依赖的package包/类
/**
* Called when a web socket disconnects. We'll close out any consumers that web socket client had running
* based on their sessionId.
*/
@EventListener
void handleSessionDisconnect(final SessionDisconnectEvent event) {
// Grab sessionId from event
final String sessionId = event.getSessionId();
// Disconnect that sessionId's consumers
webSocketConsumersManager.removeConsumersForSessionId(sessionId);
}
示例9: handleSessionDisconnect
import org.springframework.web.socket.messaging.SessionDisconnectEvent; //导入依赖的package包/类
@EventListener
private void handleSessionDisconnect(SessionDisconnectEvent event) {
Optional<SessionConversations> removeSession = sessionRepository.remove(event.getSessionId());
if(removeSession.isPresent()){
removeSession.get().getConversations().forEach( conversation -> {
notifyUserLeft(conversation, removeSession.get().getParticipantId());
});
log.debug("User {} disconnected No conversations {}",
removeSession.get().getParticipantId(),
removeSession.get().getNumberOfConversations());
}
}
示例10: onApplicationEvent
import org.springframework.web.socket.messaging.SessionDisconnectEvent; //导入依赖的package包/类
public void onApplicationEvent(SessionDisconnectEvent event) {
String id = event.getSessionId();
if (id == null) {
return;
}
ActiveWebSocketUser user = this.repository.findOne(id);
if (user == null) {
return;
}
this.repository.delete(id);
this.messagingTemplate.convertAndSend("/topic/friends/signout",
Arrays.asList(user.getUsername()));
}
示例11: onApplicationEvent
import org.springframework.web.socket.messaging.SessionDisconnectEvent; //导入依赖的package包/类
public void onApplicationEvent(SessionDisconnectEvent event) {
String sessionId = event.getSessionId();
if (sessionId == null) {
return;
}
ActiveWebSocketUser activeUser = this.activeWebSocketUserRepository.findOne(sessionId);
if (activeUser == null) {
return;
}
this.activeWebSocketUserRepository.delete(sessionId);
this.messagingTemplate.convertAndSend("/su/disconnected", Lists.newArrayList(activeUser));
}
示例12: onApplicationEvent
import org.springframework.web.socket.messaging.SessionDisconnectEvent; //导入依赖的package包/类
public void onApplicationEvent(SessionDisconnectEvent event) {
String id = event.getSessionId();
if (id == null) {
return;
}
ActiveWebSocketUser user = this.repository.findOne(id);
if (user == null) {
return;
}
this.repository.delete(id);
this.messagingTemplate.convertAndSend(WS_API.TOPIC_FRIENDS_SIGNOUT,
Collections.singletonList(user.getUsername()));
}
开发者ID:Pivopil,项目名称:spring-boot-oauth2-rest-service-password-encoding,代码行数:16,代码来源:WebSocketDisconnectHandler.java
示例13: onSessionDisconnectEvent
import org.springframework.web.socket.messaging.SessionDisconnectEvent; //导入依赖的package包/类
/**
* React on closed web socket connections.
* @param event The application event.
*/
@EventListener
public void onSessionDisconnectEvent(SessionDisconnectEvent event) {
StompHeaderAccessor sha = StompHeaderAccessor.wrap(event.getMessage());
activeWebSocketSessionRepository.delete(sha.getSessionId());
log.debug("Closed websocket connection {}",
sha.getSessionAttributes().get(WebSocketConfig.IP_ADDRESS));
}
示例14: onApplicationEvent
import org.springframework.web.socket.messaging.SessionDisconnectEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(SessionDisconnectEvent event) {
ActivityDTO activityDTO = new ActivityDTO();
Message message = event.getMessage();
activityDTO.setSessionId(event.getSessionId());
activityDTO.setPage("logout");
messagingTemplate.convertAndSend("/topic/activity", activityDTO);
}
示例15: onApplicationEvent
import org.springframework.web.socket.messaging.SessionDisconnectEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(SessionDisconnectEvent event) {
ActivityDTO activityDTO = new ActivityDTO();
activityDTO.setSessionId(event.getSessionId());
activityDTO.setPage("logout");
messagingTemplate.convertAndSend("/topic/tracker", activityDTO);
}