use of io.netty.buffer.ByteBufAllocator in project neo4j by neo4j.
the class BoltProtocolV1Test method closesInputAndOutput.
@Test
public void closesInputAndOutput() {
Channel outputChannel = mock(Channel.class);
ByteBufAllocator allocator = mock(ByteBufAllocator.class);
ByteBuf buffer = mock(ByteBuf.class);
when(outputChannel.alloc()).thenReturn(allocator);
when(allocator.buffer(anyInt(), anyInt())).thenReturn(buffer);
BoltStateMachine machine = mock(BoltStateMachine.class);
BoltProtocolV1 protocol = new BoltProtocolV1(new SynchronousBoltWorker(machine), outputChannel, NullLogService.getInstance());
protocol.close();
verify(machine).close();
verify(buffer).release();
}
use of io.netty.buffer.ByteBufAllocator in project x-pipe by ctripcorp.
the class NettySimpleTest method testNettyInternalBuffer.
@Test
public void testNettyInternalBuffer() throws IOException {
ByteBufAllocator allocator = new PooledByteBufAllocator(true);
final ByteBuf byteBuf = allocator.buffer(1 << 10);
byteBuf.writeBytes("1234567890".getBytes());
System.out.println(byteBuf.readableBytes());
scheduled.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
// ByteBuffer byteBuffer = byteBuf.internalNioBuffer(0, byteBuf.readableBytes());
byteBuf.nioBuffers();
}
}, 0, 100, TimeUnit.MICROSECONDS);
System.out.println(byteBuf.readableBytes());
waitForAnyKeyToExit();
}
use of io.netty.buffer.ByteBufAllocator in project jocean-http by isdom.
the class StreamUtil method allocStateableDWB.
public static DisposableWrapper<ByteBuf> allocStateableDWB(final int bufSize) {
final ByteBufAllocator allocator = PooledByteBufAllocator.DEFAULT;
final ByteBuf buf = allocator.buffer(bufSize, bufSize);
return Proxys.mixin().mix(DisposableWrapper.class, RxNettys.wrap4release(buf)).mix(Stateable.class, new StateableSupport()).build();
}
use of io.netty.buffer.ByteBufAllocator in project ratpack by ratpack.
the class ServerSentEvents method render.
/**
* {@inheritDoc}
*/
@Override
public void render(Context context) throws Exception {
ByteBufAllocator bufferAllocator = context.get(ByteBufAllocator.class);
Response response = context.getResponse();
response.getHeaders().add(HttpHeaderConstants.CONTENT_TYPE, HttpHeaderConstants.TEXT_EVENT_STREAM_CHARSET_UTF_8);
response.getHeaders().add(HttpHeaderConstants.TRANSFER_ENCODING, HttpHeaderConstants.CHUNKED);
response.getHeaders().add(HttpHeaderConstants.CACHE_CONTROL, HttpHeaderConstants.NO_CACHE_FULL);
response.getHeaders().add(HttpHeaderConstants.PRAGMA, HttpHeaderConstants.NO_CACHE);
response.sendStream(Streams.map(publisher, i -> ServerSentEventEncoder.INSTANCE.encode(i, bufferAllocator)));
}
use of io.netty.buffer.ByteBufAllocator in project ratpack by ratpack.
the class WebSockets method websocketBroadcast.
/**
* Sets up a websocket that sends the published Strings to a client.
* <p>
* This takes the place of a {@link Streams#bindExec(Publisher)} call.
*
* @param context the request handling context
* @param broadcaster a {@link Publisher} of Strings to send to the websocket client
*/
public static void websocketBroadcast(final Context context, final Publisher<String> broadcaster) {
ByteBufAllocator bufferAllocator = context.get(ByteBufAllocator.class);
websocketByteBufBroadcast(context, Streams.map(broadcaster, s -> ByteBufUtil.encodeString(bufferAllocator, CharBuffer.wrap(s), CharsetUtil.UTF_8)));
}
Aggregations