Java Code Examples for org.xnio.Pooled#getResource()

The following examples show how to use org.xnio.Pooled#getResource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebSocketTtyConnection.java    From termd with Apache License 2.0 6 votes vote down vote up
private void registerWebSocketChannelListener(WebSocketChannel webSocketChannel) {
  ChannelListener<WebSocketChannel> listener = new AbstractReceiveListener() {

    @Override
    protected void onFullBinaryMessage(WebSocketChannel channel, BufferedBinaryMessage message) throws IOException {
      log.trace("Server received full binary message");
      Pooled<ByteBuffer[]> pulledData = message.getData();
      try {
        ByteBuffer[] resource = pulledData.getResource();
        ByteBuffer byteBuffer = WebSockets.mergeBuffers(resource);
        String msg = new String(byteBuffer.array());
        log.trace("Sending message to decoder: {}", msg);
        writeToDecoder(msg);
      } finally {
        pulledData.discard();
      }
    }
  };
  webSocketChannel.getReceiveSetter().set(listener);
}
 
Example 2
Source File: XnioByteBufferPool.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public PooledByteBuffer allocate() {
    final Pooled<ByteBuffer> buf = pool.allocate();
    return new PooledByteBuffer() {

        private boolean open = true;

        @Override
        public ByteBuffer getBuffer() {
            return buf.getResource();
        }

        @Override
        public void close() {
            open = false;
            buf.free();
        }

        @Override
        public boolean isOpen() {
            return open;
        }
    };
}
 
Example 3
Source File: WebSocketTtyConnection.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
private void registerWebSocketChannelListener(WebSocketChannel webSocketChannel) {
    ChannelListener<WebSocketChannel> listener = new AbstractReceiveListener() {

        @Override
        protected void onFullBinaryMessage(WebSocketChannel channel, BufferedBinaryMessage message) throws IOException {
            log.log(Level.FINE, "Server received full binary message");
            Pooled<ByteBuffer[]> pulledData = message.getData();
            try {
                ByteBuffer[] resource = pulledData.getResource();
                ByteBuffer byteBuffer = WebSockets.mergeBuffers(resource);
                String msg = new String(byteBuffer.array());
                log.log(Level.FINE, "Sending message to decoder: "+ msg);
                writeToDecoder(msg);
            }
            finally {
                pulledData.discard();
            }
        }
    };
    webSocketChannel.getReceiveSetter().set(listener);
}
 
Example 4
Source File: WebSocketTtyConnection.java    From termd with Apache License 2.0 6 votes vote down vote up
private void registerWebSocketChannelListener(WebSocketChannel webSocketChannel) {
  ChannelListener<WebSocketChannel> listener = new AbstractReceiveListener() {

    @Override
    protected void onFullBinaryMessage(WebSocketChannel channel, BufferedBinaryMessage message) throws IOException {
      log.trace("Server received full binary message");
      Pooled<ByteBuffer[]> pulledData = message.getData();
      try {
        ByteBuffer[] resource = pulledData.getResource();
        ByteBuffer byteBuffer = WebSockets.mergeBuffers(resource);
        String msg = new String(byteBuffer.array());
        log.trace("Sending message to decoder: {}", msg);
        writeToDecoder(msg);
      } finally {
        pulledData.discard();
      }
    }
  };
  webSocketChannel.getReceiveSetter().set(listener);
}
 
Example 5
Source File: AbstractReceiveListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected void onFullCloseMessage(final WebSocketChannel channel, BufferedBinaryMessage message) throws IOException {
    Pooled<ByteBuffer[]> data = message.getData();
    try {
        CloseMessage cm = new CloseMessage(data.getResource());
        onCloseMessage(cm, channel);
        if (!channel.isCloseFrameSent()) {
            WebSockets.sendClose(cm, channel, null);
        }
    } finally {
        data.close();
    }
}
 
Example 6
Source File: UndertowWebSocketAdapter.java    From pippo with Apache License 2.0 5 votes vote down vote up
@Override
protected void onFullBinaryMessage(WebSocketChannel channel, BufferedBinaryMessage message) throws IOException {
    Pooled<ByteBuffer[]> pulledData = message.getData();
    try {
        ByteBuffer[] resource = pulledData.getResource();
        ByteBuffer buffer = WebSockets.mergeBuffers(resource);
        handler.onMessage(context, buffer.array());
    } finally {
        pulledData.discard();
    }
}
 
Example 7
Source File: XnioUnsafeDirectByteBuf.java    From netty-xnio-transport with Apache License 2.0 5 votes vote down vote up
@Override
protected ByteBuffer allocateDirect(int initialCapacity) {
    Pooled<ByteBuffer> pooled = XnioByteBufUtil.allocateDirect(
            ((XnioByteBufAllocator) alloc()).pool, initialCapacity);
    this.pooled = pooled;
    return pooled.getResource();
}
 
Example 8
Source File: XnioDirectByteBuf.java    From netty-xnio-transport with Apache License 2.0 5 votes vote down vote up
@Override
protected ByteBuffer allocateDirect(int initialCapacity) {
    Pooled<ByteBuffer> pooled = XnioByteBufUtil.allocateDirect(
            ((XnioByteBufAllocator) alloc()).pool, initialCapacity);
    this.pooled = pooled;
    return pooled.getResource();
}