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);
     }
   }
 }
  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());
        }
      }
    }
  }
Exemple #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);
    }
  }