Example #1
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);
    }
  }
Example #2
0
  @Override
  protected void onFullCloseMessage(
      final WebSocketChannel channel, final BufferedBinaryMessage message) {
    final Pooled<ByteBuffer[]> pooled = message.getData();
    final ByteBuffer singleBuffer = toBuffer(pooled.getResource());
    final ByteBuffer toSend = singleBuffer.duplicate();

    session
        .getContainer()
        .invokeEndpointMethod(
            executor,
            new Runnable() {
              @Override
              public void run() {
                WebSockets.sendClose(toSend, channel, null);
                try {
                  if (singleBuffer.remaining() > 2) {
                    final int code = singleBuffer.getShort();
                    session.close(
                        new javax.websocket.CloseReason(
                            javax.websocket.CloseReason.CloseCodes.getCloseCode(code),
                            new UTF8Output(singleBuffer).extract()));
                  } else {
                    session.close();
                  }
                } catch (IOException e) {
                  invokeOnError(e);
                } finally {
                  pooled.free();
                }
              }
            });
  }
Example #3
0
  @Override
  protected void onFullPongMessage(
      WebSocketChannel webSocketChannel, BufferedBinaryMessage bufferedBinaryMessage) {
    final HandlerWrapper handler = getHandler(FrameType.PONG);
    if (handler != null) {
      final Pooled<ByteBuffer[]> pooled = bufferedBinaryMessage.getData();
      final PongMessage message = DefaultPongMessage.create(toBuffer(pooled.getResource()));

      session
          .getContainer()
          .invokeEndpointMethod(
              executor,
              new Runnable() {
                @Override
                public void run() {
                  try {
                    ((MessageHandler.Whole) handler.getHandler()).onMessage(message);
                  } finally {
                    pooled.free();
                  }
                }
              });
    }
  }