Ejemplo n.º 1
0
  public OutgoingSentinelExtension(final WsURLConnectionImpl connection) {
    this.closePayloadRO = new ClosePayloadRO();
    this.closePayload = ByteBuffer.allocate(MAX_CLOSE_PAYLOAD_LENGTH_LIMIT);
    this.frameBuffer = ByteBuffer.allocate(connection.getMaxFrameLength() + 4);

    super.onBinarySent =
        new WebSocketFrameConsumer() {
          @Override
          public void accept(WebSocketContext context, Frame frame) throws IOException {
            assert frame.opcode() == BINARY;
            encodeFrame(connection, frame);
          }
        };

    super.onContinuationSent =
        new WebSocketFrameConsumer() {
          @Override
          public void accept(WebSocketContext context, Frame frame) throws IOException {
            assert frame.opcode() == CONTINUATION;
            encodeFrame(connection, frame);
          }
        };

    super.onCloseSent =
        new WebSocketFrameConsumer() {
          @Override
          public void accept(WebSocketContext context, Frame frame) throws IOException {
            assert frame.opcode() == CLOSE;
            validateAndEncodeCloseFrame(connection, frame);
          }
        };

    super.onPongSent =
        new WebSocketFrameConsumer() {
          @Override
          public void accept(WebSocketContext context, Frame frame) throws IOException {
            assert frame.opcode() == PONG;
            encodeFrame(connection, frame);
          }
        };

    super.onTextSent =
        new WebSocketFrameConsumer() {
          @Override
          public void accept(WebSocketContext context, Frame frame) throws IOException {
            assert frame.opcode() == TEXT;
            encodeFrame(connection, frame);
          }
        };
  }