org.xnio.Pooled Java Examples
The following examples show how to use
org.xnio.Pooled.
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 |
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: XnioBufferPoolAdaptor.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public Pooled<ByteBuffer> allocate() { final PooledByteBuffer buf = byteBufferPool.allocate(); return new Pooled<ByteBuffer>() { @Override public void discard() { buf.close(); } @Override public void free() { buf.close(); } @Override public ByteBuffer getResource() throws IllegalStateException { return buf.getBuffer(); } @Override public void close() { buf.close(); } }; }
Example #3
Source File: XnioByteBufferPool.java From lams with GNU General Public License v2.0 | 6 votes |
@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 #4
Source File: WebSocketTtyConnection.java From aesh-readline with Apache License 2.0 | 6 votes |
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 #5
Source File: WebSocketTtyConnection.java From termd with Apache License 2.0 | 6 votes |
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 #6
Source File: XnioByteBufferPool.java From lams with GNU General Public License v2.0 | 5 votes |
public XnioByteBufferPool(Pool<ByteBuffer> pool) { this.pool = pool; Pooled<ByteBuffer> buf = pool.allocate(); bufferSize = buf.getResource().remaining(); direct = !buf.getResource().hasArray(); buf.free(); if(direct) { arrayBackedPool = new DefaultByteBufferPool(false, bufferSize); } else { arrayBackedPool = this; } }
Example #7
Source File: AbstractReceiveListener.java From lams with GNU General Public License v2.0 | 5 votes |
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 #8
Source File: UndertowWebSocketAdapter.java From pippo with Apache License 2.0 | 5 votes |
@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 #9
Source File: XnioUnsafeDirectByteBuf.java From netty-xnio-transport with Apache License 2.0 | 5 votes |
@Override public ByteBuf capacity(int newCapacity) { ensureAccessible(); if (newCapacity < 0 || newCapacity > maxCapacity()) { throw new IllegalArgumentException("newCapacity: " + newCapacity); } Pooled<ByteBuffer> oldPooled = this.pooled; super.capacity(newCapacity); if (oldPooled != pooled) { oldPooled.free(); } return this; }
Example #10
Source File: XnioUnsafeDirectByteBuf.java From netty-xnio-transport with Apache License 2.0 | 5 votes |
@Override protected ByteBuffer allocateDirect(int initialCapacity) { Pooled<ByteBuffer> pooled = XnioByteBufUtil.allocateDirect( ((XnioByteBufAllocator) alloc()).pool, initialCapacity); this.pooled = pooled; return pooled.getResource(); }
Example #11
Source File: XnioDirectByteBuf.java From netty-xnio-transport with Apache License 2.0 | 5 votes |
@Override public ByteBuf capacity(int newCapacity) { ensureAccessible(); if (newCapacity < 0 || newCapacity > maxCapacity()) { throw new IllegalArgumentException("newCapacity: " + newCapacity); } Pooled<ByteBuffer> oldPooled = this.pooled; super.capacity(newCapacity); if (oldPooled != pooled) { oldPooled.free(); } return this; }
Example #12
Source File: XnioDirectByteBuf.java From netty-xnio-transport with Apache License 2.0 | 5 votes |
@Override protected ByteBuffer allocateDirect(int initialCapacity) { Pooled<ByteBuffer> pooled = XnioByteBufUtil.allocateDirect( ((XnioByteBufAllocator) alloc()).pool, initialCapacity); this.pooled = pooled; return pooled.getResource(); }
Example #13
Source File: XnioByteBufUtil.java From netty-xnio-transport with Apache License 2.0 | 5 votes |
static Pooled<ByteBuffer> allocateDirect(ByteBufferSlicePool pool, int initialCapacity) { Pooled<ByteBuffer> pooled; if (initialCapacity <= pool.getBufferSize()) { pooled = pool.allocate(); } else { pooled = new PooledByteBuf(ByteBuffer.allocateDirect(initialCapacity)); } return pooled; }
Example #14
Source File: AbstractReceiveListener.java From lams with GNU General Public License v2.0 | 4 votes |
protected void onFullPingMessage(final WebSocketChannel channel, BufferedBinaryMessage message) throws IOException { final Pooled<ByteBuffer[]> data = message.getData(); WebSockets.sendPong(data.getResource(), channel, new FreeDataCallback(data)); }
Example #15
Source File: AbstractReceiveListener.java From lams with GNU General Public License v2.0 | 4 votes |
FreeDataCallback(Pooled<ByteBuffer[]> data) { this.data = data; }