Example #1
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);
     }
   }
 }
Example #2
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());
        }
      }
    }
  }