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


Java SessionDisconnectEvent类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:scionaltera,项目名称:emergentmud,代码行数:17,代码来源:StompDisconnectListener.java

示例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));
}
 
开发者ID:SourceLabOrg,项目名称:kafka-webview,代码行数:22,代码来源:PresenceEventListenerTest.java

示例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));
    }

}
 
开发者ID:Coding,项目名称:WebIDE-Backend,代码行数:23,代码来源:EventExchange.java

示例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);
}
 
开发者ID:ralscha,项目名称:wampspring,代码行数:19,代码来源:UserSessionWebSocketHandlerDecoratorFactory.java

示例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()));
    }
 
开发者ID:bjornharvold,项目名称:bearchoke,代码行数:26,代码来源:WebSocketDisconnectHandler.java

示例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);
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:8,代码来源:ActivityService.java

示例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
    );
}
 
开发者ID:scionaltera,项目名称:emergentmud,代码行数:28,代码来源:StompDisconnectListenerTest.java

示例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);
}
 
开发者ID:SourceLabOrg,项目名称:kafka-webview,代码行数:13,代码来源:PresenceEventListener.java

示例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());
    }

}
 
开发者ID:peterjurkovic,项目名称:travel-agency,代码行数:16,代码来源:WebsocketSessionListener.java

示例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()));

}
 
开发者ID:xianrendzw,项目名称:CodeMaster,代码行数:16,代码来源:WebSocketDisconnectHandler.java

示例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));
}
 
开发者ID:HeroXXiv,项目名称:Robocode,代码行数:15,代码来源:DisconnectHandler.java

示例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));
}
 
开发者ID:dzhw,项目名称:metadatamanagement,代码行数:12,代码来源:WebSocketConnectionListener.java

示例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);
}
 
开发者ID:kumpelblase2,项目名称:jhipster-websocket-example,代码行数:9,代码来源:ActivityService.java

示例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);
}
 
开发者ID:priitl,项目名称:p2p-webtv,代码行数:8,代码来源:ActivityService.java


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