예제 #1
0
 /** Return a safe copy of all registered {@link MessageHandler}s. */
 public final Set<MessageHandler> getHandlers() {
   Set<MessageHandler> msgHandlers = new HashSet<MessageHandler>();
   for (HandlerWrapper handler : handlers.values()) {
     msgHandlers.add(handler.getHandler());
   }
   return msgHandlers;
 }
예제 #2
0
  @Override
  protected void onBinary(
      WebSocketChannel webSocketChannel, StreamSourceFrameChannel messageChannel)
      throws IOException {
    final HandlerWrapper handler = getHandler(FrameType.BYTE);
    if (handler != null && handler.isPartialHandler()) {
      BufferedBinaryMessage data =
          new BufferedBinaryMessage(session.getMaxBinaryMessageBufferSize(), false);
      data.read(
          messageChannel,
          new WebSocketCallback<BufferedBinaryMessage>() {
            @Override
            public void complete(WebSocketChannel channel, BufferedBinaryMessage context) {
              invokeBinaryHandler(context, handler, context.isComplete());
            }

            @Override
            public void onError(
                WebSocketChannel channel, BufferedBinaryMessage context, Throwable throwable) {
              invokeOnError(throwable);
            }
          });
    } else {
      bufferFullMessage(messageChannel);
    }
  }
예제 #3
0
 public final void removeHandler(MessageHandler handler) {
   Map<Class<?>, Boolean> types = ClassUtils.getHandlerTypes(handler.getClass());
   for (Entry<Class<?>, Boolean> e : types.entrySet()) {
     Class<?> type = e.getKey();
     HandlerWrapper handlerWrapper = createHandlerWrapper(type, handler, e.getValue());
     FrameType frameType = handlerWrapper.getFrameType();
     HandlerWrapper wrapper = handlers.get(frameType);
     if (wrapper != null && wrapper.getMessageType() == type) {
       handlers.remove(frameType, wrapper);
     }
   }
 }
예제 #4
0
  public final void addHandler(MessageHandler handler) {
    Map<Class<?>, Boolean> types = ClassUtils.getHandlerTypes(handler.getClass());
    for (Entry<Class<?>, Boolean> e : types.entrySet()) {
      Class<?> type = e.getKey();
      verify(type, handler);

      HandlerWrapper handlerWrapper = createHandlerWrapper(type, handler, e.getValue());

      if (handlers.containsKey(handlerWrapper.getFrameType())) {
        throw JsrWebSocketMessages.MESSAGES.handlerAlreadyRegistered(handlerWrapper.getFrameType());
      } else {
        if (handlers.putIfAbsent(handlerWrapper.getFrameType(), handlerWrapper) != null) {
          throw JsrWebSocketMessages.MESSAGES.handlerAlreadyRegistered(
              handlerWrapper.getFrameType());
        }
      }
    }
  }