/** 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; }
@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); } }
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()); } } } }