Example usage for javax.websocket Session getUserProperties

List of usage examples for javax.websocket Session getUserProperties

Introduction

In this page you can find the example usage for javax.websocket Session getUserProperties.

Prototype

Map<String, Object> getUserProperties();

Source Link

Usage

From source file:com.mycompany.wolf.Game.java

public void playerVote(Session session, String votedPlayerId) {
    String playerId = (String) session.getUserProperties().get("playerId");
    rooms.values().stream().filter(r -> r.contains(playerId)).findAny().ifPresent(room -> {
        room.playerVote(session, votedPlayerId);
    });/*ww w  .java  2 s  .c  o  m*/
}

From source file:com.mycompany.wolf.Game.java

public void hunterKill(Session session, String killedPlayerId) {
    String playerId = (String) session.getUserProperties().get("playerId");
    rooms.values().stream().filter(r -> r.contains(playerId)).findAny().ifPresent(room -> {
        room.hunterKills(session, killedPlayerId);
    });//  w  ww.  ja  v a2  s  .com
}

From source file:com.mycompany.wolf.Game.java

public void witchPoison(Session session, String poisonedPlayerId) {
    String playerId = (String) session.getUserProperties().get("playerId");
    rooms.values().stream().filter(r -> r.contains(playerId)).findAny().ifPresent(room -> {
        room.witchPoison(session, poisonedPlayerId);
    });/*from  w  ww  .ja va 2  s. c  o  m*/
}

From source file:com.mycompany.wolf.Game.java

public void seerForcast(Session session, String forcastedPlayerId) {
    String playerId = (String) session.getUserProperties().get("playerId");
    rooms.values().stream().filter(r -> r.contains(playerId)).findAny().ifPresent(room -> {
        room.seerForecasts(session, forcastedPlayerId);
    });// w w w  .j  av a 2 s.c o m
}

From source file:com.almende.eve.transport.ws.WsServerTransport.java

@Override
public void onClose(final Session session, final CloseReason closeReason) {
    super.onClose(session, closeReason);
    if (session.getUserProperties().containsKey("remoteId")) {
        final String remoteId = (String) session.getUserProperties().get("remoteId");
        final URI key = URIUtil.create("wsclient:" + remoteId);
        remotes.remove(key);/* w w w .  jav a 2s. co m*/
    }
}

From source file:org.jboss.aerogear.sync.server.wildfly.SyncEndpoint.java

@OnClose
public void onClose(CloseReason reason, Session webSocketSession) {
    logger.info("Closing a WebSocket due to " + reason.getReasonPhrase());
    WildflySubscriber subscriber = (WildflySubscriber) webSocketSession.getUserProperties()
            .get(WILDFLY_SUBSCRIBER);/*from  www.ja v  a  2  s . c o  m*/
    String documentId = (String) webSocketSession.getUserProperties().get(DOCUMENT_ID);
    syncEngine.removeSubscriber(subscriber, documentId);

}

From source file:hr.ws4is.websocket.WebSocketEndpoint.java

public final void onOpen(final Session session, final EndpointConfig config) {

    try {//from   w ww . java2s.  c om
        final HttpSession httpSession = (HttpSession) config.getUserProperties()
                .get(HttpSession.class.getName());
        final WebSocketSession wsession = new WebSocketSession(session, httpSession);

        session.getUserProperties().put(WS4ISConstants.WEBSOCKET_PATH,
                config.getUserProperties().get(WS4ISConstants.WEBSOCKET_PATH));

        websocketContextThreadLocal.set(wsession);
        webSocketEvent.fire(new WebsocketEvent(wsession, WebSocketEventStatus.START));

        if (!wsession.isValidHttpSession()) {
            LOGGER.error(WS4ISConstants.HTTP_SEESION_REQUIRED);
            final IllegalStateException ise = new IllegalStateException(WS4ISConstants.HTTP_SEESION_REQUIRED);
            final WebSocketResponse wsResponse = getErrorResponse(ise);
            final String responseString = JsonDecoder.getJSONEngine().writeValueAsString(wsResponse);
            session.close(new CloseReason(CloseCodes.VIOLATED_POLICY, responseString));
        }

    } catch (IOException exception) {
        LOGGER.error(exception.getMessage(), exception);
    } finally {
        websocketContextThreadLocal.remove();
    }

}

From source file:org.jboss.aerogear.sync.server.wildfly.SyncEndpoint.java

@OnMessage
public String onMessage(String message, Session webSocketSession) {
    final JsonNode json = JsonMapper.asJsonNode(message);

    switch (MessageType.from(json.get("msgType").asText())) {
    case ADD:// ww w.  j  av a  2 s  . c om
        final Document<JsonNode> doc = syncEngine.documentFromJson(json);
        final String clientId = json.get("clientId").asText();
        final PatchMessage<JsonPatchEdit> patchMessage = addSubscriber(doc, clientId, webSocketSession);
        webSocketSession.getUserProperties().put(DOC_ADD, true);
        return (patchMessage.asJson());

    case PATCH:
        final PatchMessage<JsonPatchEdit> clientPatchMessage = syncEngine.patchMessageFromJson(json.toString());
        checkForReconnect(clientPatchMessage.documentId(), clientPatchMessage.clientId(), webSocketSession);
        patch(clientPatchMessage);
        break;
    case DETACH:
        // detach the client from a specific document.
        break;
    case UNKNOWN:
        return "{\"result\": \"Unknown msgType '" + json.get("msgType").asText() + "'\"}";

    }

    return message;
}

From source file:com.mycompany.wolf.Room.java

public void wolfVote(Session session, String votedPlayerId) {
    final String playerId = getPlayerId(session);
    if (WOLF.equals(session.getUserProperties().get("role")) && !dead.contains(playerId)) {
        wolfVotings.put(playerId, new WolfVoting(votedPlayerId));
    }/*w ww  . j a  v  a2  s.c  o  m*/
}

From source file:com.mycompany.wolf.Room.java

public void witchSave(Session session, String savedPlayerId) {
    final String playerId = getPlayerId(session);
    if (WITCH.equals(session.getUserProperties().get("role")) && !dead.contains(playerId)) {
        witchSavings.put(playerId, new WitchSaving(savedPlayerId));
    }//from   w w w.  j a  va2  s.  c  om
}