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