예제 #1
0
  @SuppressWarnings("unchecked")
  @Override
  public void addMessageHandler(MessageHandler listener) {

    checkState();

    // Message handlers that require decoders may map to text messages,
    // binary messages, both or neither.

    // The frame processing code expects binary message handlers to
    // accept ByteBuffer

    // Use the POJO message handler wrappers as they are designed to wrap
    // arbitrary objects with MessageHandlers and can wrap MessageHandlers
    // just as easily.

    Set<MessageHandlerResult> mhResults = Util.getMessageHandlers(listener, endpointConfig, this);

    for (MessageHandlerResult mhResult : mhResults) {
      switch (mhResult.getType()) {
        case TEXT:
          {
            if (textMessageHandler != null) {
              throw MESSAGES.duplicateHandlerText();
            }
            textMessageHandler = mhResult.getHandler();
            break;
          }
        case BINARY:
          {
            if (binaryMessageHandler != null) {
              throw MESSAGES.duplicateHandlerBinary();
            }
            binaryMessageHandler = mhResult.getHandler();
            break;
          }
        case PONG:
          {
            if (pongMessageHandler != null) {
              throw MESSAGES.duplicateHandlerPong();
            }
            MessageHandler handler = mhResult.getHandler();
            if (handler instanceof MessageHandler.Whole<?>) {
              pongMessageHandler = (MessageHandler.Whole<PongMessage>) handler;
            } else {
              throw MESSAGES.invalidHandlerPong();
            }

            break;
          }
        default:
          {
            throw MESSAGES.invalidMessageHandler(listener, mhResult.getType());
          }
      }
    }
  }
예제 #2
0
 @Override
 public Set<MessageHandler> getMessageHandlers() {
   checkState();
   Set<MessageHandler> result = new HashSet<MessageHandler>();
   if (binaryMessageHandler != null) {
     result.add(binaryMessageHandler);
   }
   if (textMessageHandler != null) {
     result.add(textMessageHandler);
   }
   if (pongMessageHandler != null) {
     result.add(pongMessageHandler);
   }
   return result;
 }
예제 #3
0
  @Override
  public void removeMessageHandler(MessageHandler listener) {
    checkState();
    if (listener == null) {
      return;
    }

    MessageHandler wrapped = null;

    if (listener instanceof WrappedMessageHandler) {
      wrapped = ((WrappedMessageHandler) listener).getWrappedHandler();
    }

    if (wrapped == null) {
      wrapped = listener;
    }

    boolean removed = false;
    if (wrapped.equals(textMessageHandler) || listener.equals(textMessageHandler)) {
      textMessageHandler = null;
      removed = true;
    }

    if (listener.equals(binaryMessageHandler) || listener.equals(binaryMessageHandler)) {
      binaryMessageHandler = null;
      removed = true;
    }

    if (listener.equals(pongMessageHandler) || listener.equals(pongMessageHandler)) {
      pongMessageHandler = null;
      removed = true;
    }

    if (!removed) {
      // ISE for now. Could swallow this silently / log this if the ISE
      // becomes a problem
      throw MESSAGES.cannotRemoveHandler(listener);
    }
  }
예제 #4
0
 @Override
 public RemoteEndpoint.Basic getBasicRemote() {
   checkState();
   return remoteEndpointBasic;
 }
예제 #5
0
 @Override
 public RemoteEndpoint.Async getAsyncRemote() {
   checkState();
   return remoteEndpointAsync;
 }
예제 #6
0
 @Override
 public Set<Session> getOpenSessions() {
   checkState();
   return webSocketContainer.getOpenSessions(localEndpoint.getClass());
 }
예제 #7
0
 @Override
 public int getMaxTextMessageBufferSize() {
   checkState();
   return maxTextMessageBufferSize;
 }
예제 #8
0
 @Override
 public Map<String, String> getPathParameters() {
   checkState();
   return pathParameters;
 }
예제 #9
0
 @Override
 public String getQueryString() {
   checkState();
   return queryString;
 }
예제 #10
0
 @Override
 public boolean isSecure() {
   checkState();
   return secure;
 }
예제 #11
0
 @Override
 public List<Extension> getNegotiatedExtensions() {
   checkState();
   return Collections.emptyList();
 }
예제 #12
0
 @Override
 public String getNegotiatedSubprotocol() {
   checkState();
   return subProtocol;
 }
예제 #13
0
 @Override
 public String getProtocolVersion() {
   checkState();
   return Constants.WS_VERSION_HEADER_VALUE;
 }
예제 #14
0
 @Override
 public URI getRequestURI() {
   checkState();
   return requestUri;
 }
예제 #15
0
 @Override
 public long getMaxIdleTimeout() {
   checkState();
   return maxIdleTimeout;
 }
예제 #16
0
 @Override
 public Map<String, List<String>> getRequestParameterMap() {
   checkState();
   return requestParameterMap;
 }
예제 #17
0
 @Override
 public void setMaxIdleTimeout(long timeout) {
   checkState();
   this.maxIdleTimeout = timeout;
 }
예제 #18
0
 @Override
 public Principal getUserPrincipal() {
   checkState();
   return userPrincipal;
 }
예제 #19
0
 @Override
 public void setMaxTextMessageBufferSize(int max) {
   checkState();
   this.maxTextMessageBufferSize = max;
 }
예제 #20
0
 @Override
 public Map<String, Object> getUserProperties() {
   checkState();
   return userProperties;
 }
예제 #21
0
 @Override
 public WebSocketContainer getContainer() {
   checkState();
   return webSocketContainer;
 }