use of io.netty.buffer.PooledByteBufAllocator in project pulsar by yahoo.
the class AllocatorStatsGenerator method generate.
public static AllocatorStats generate(String allocatorName) {
PooledByteBufAllocator allocator = null;
if ("default".equals(allocatorName)) {
allocator = PooledByteBufAllocator.DEFAULT;
} else if ("ml-cache".equals(allocatorName)) {
allocator = EntryCacheImpl.allocator;
} else {
throw new IllegalArgumentException("Invalid allocator name : " + allocatorName);
}
AllocatorStats stats = new AllocatorStats();
stats.directArenas = allocator.directArenas().stream().map(x -> newPoolArenaStats(x)).collect(Collectors.toList());
stats.heapArenas = allocator.heapArenas().stream().map(x -> newPoolArenaStats(x)).collect(Collectors.toList());
stats.numDirectArenas = allocator.numDirectArenas();
stats.numHeapArenas = allocator.numHeapArenas();
stats.numThreadLocalCaches = allocator.numThreadLocalCaches();
stats.normalCacheSize = allocator.normalCacheSize();
stats.smallCacheSize = allocator.smallCacheSize();
stats.tinyCacheSize = allocator.tinyCacheSize();
return stats;
}
use of io.netty.buffer.PooledByteBufAllocator in project redisson by redisson.
the class JsonJacksonMapValueCodecTest method shouldDeserializeTheMapCorrectly.
@Test
public void shouldDeserializeTheMapCorrectly() throws Exception {
ByteBuf buf = new PooledByteBufAllocator(true).buffer();
buf.writeBytes(new ObjectMapper().writeValueAsBytes(map));
assertThat(mapCodec.getMapValueDecoder().decode(buf, new State(false))).isInstanceOf(Map.class).isEqualTo(map);
}
use of io.netty.buffer.PooledByteBufAllocator in project bookkeeper by apache.
the class BookieNettyServer method listenOn.
private void listenOn(InetSocketAddress address, BookieSocketAddress bookieAddress) throws InterruptedException {
if (!conf.isDisableServerSocketBind()) {
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(true));
bootstrap.group(eventLoopGroup, eventLoopGroup);
bootstrap.childOption(ChannelOption.TCP_NODELAY, conf.getServerTcpNoDelay());
bootstrap.childOption(ChannelOption.SO_LINGER, conf.getServerSockLinger());
bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(conf.getRecvByteBufAllocatorSizeMin(), conf.getRecvByteBufAllocatorSizeInitial(), conf.getRecvByteBufAllocatorSizeMax()));
if (eventLoopGroup instanceof EpollEventLoopGroup) {
bootstrap.channel(EpollServerSocketChannel.class);
} else {
bootstrap.channel(NioServerSocketChannel.class);
}
bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
synchronized (suspensionLock) {
while (suspended) {
suspensionLock.wait();
}
}
BookieSideConnectionPeerContextHandler contextHandler = new BookieSideConnectionPeerContextHandler();
ChannelPipeline pipeline = ch.pipeline();
// For ByteBufList, skip the usual LengthFieldPrepender and have the encoder itself to add it
pipeline.addLast("bytebufList", ByteBufList.ENCODER_WITH_SIZE);
pipeline.addLast("lengthbaseddecoder", new LengthFieldBasedFrameDecoder(maxFrameSize, 0, 4, 0, 4));
pipeline.addLast("lengthprepender", new LengthFieldPrepender(4));
pipeline.addLast("bookieProtoDecoder", new BookieProtoEncoding.RequestDecoder(registry));
pipeline.addLast("bookieProtoEncoder", new BookieProtoEncoding.ResponseEncoder(registry));
pipeline.addLast("bookieAuthHandler", new AuthHandler.ServerSideHandler(contextHandler.getConnectionPeer(), authProviderFactory));
ChannelInboundHandler requestHandler = isRunning.get() ? new BookieRequestHandler(conf, requestProcessor, allChannels) : new RejectRequestHandler();
pipeline.addLast("bookieRequestHandler", requestHandler);
pipeline.addLast("contextHandler", contextHandler);
}
});
// Bind and start to accept incoming connections
Channel listen = bootstrap.bind(address.getAddress(), address.getPort()).sync().channel();
if (listen.localAddress() instanceof InetSocketAddress) {
if (conf.getBookiePort() == 0) {
conf.setBookiePort(((InetSocketAddress) listen.localAddress()).getPort());
}
}
}
if (conf.isEnableLocalTransport()) {
ServerBootstrap jvmBootstrap = new ServerBootstrap();
jvmBootstrap.childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(true));
jvmBootstrap.group(jvmEventLoopGroup, jvmEventLoopGroup);
jvmBootstrap.childOption(ChannelOption.TCP_NODELAY, conf.getServerTcpNoDelay());
jvmBootstrap.childOption(ChannelOption.SO_KEEPALIVE, conf.getServerSockKeepalive());
jvmBootstrap.childOption(ChannelOption.SO_LINGER, conf.getServerSockLinger());
jvmBootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(conf.getRecvByteBufAllocatorSizeMin(), conf.getRecvByteBufAllocatorSizeInitial(), conf.getRecvByteBufAllocatorSizeMax()));
if (jvmEventLoopGroup instanceof DefaultEventLoopGroup) {
jvmBootstrap.channel(LocalServerChannel.class);
} else if (jvmEventLoopGroup instanceof EpollEventLoopGroup) {
jvmBootstrap.channel(EpollServerSocketChannel.class);
} else {
jvmBootstrap.channel(NioServerSocketChannel.class);
}
jvmBootstrap.childHandler(new ChannelInitializer<LocalChannel>() {
@Override
protected void initChannel(LocalChannel ch) throws Exception {
synchronized (suspensionLock) {
while (suspended) {
suspensionLock.wait();
}
}
BookieSideConnectionPeerContextHandler contextHandler = new BookieSideConnectionPeerContextHandler();
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("lengthbaseddecoder", new LengthFieldBasedFrameDecoder(maxFrameSize, 0, 4, 0, 4));
pipeline.addLast("lengthprepender", new LengthFieldPrepender(4));
pipeline.addLast("bookieProtoDecoder", new BookieProtoEncoding.RequestDecoder(registry));
pipeline.addLast("bookieProtoEncoder", new BookieProtoEncoding.ResponseEncoder(registry));
pipeline.addLast("bookieAuthHandler", new AuthHandler.ServerSideHandler(contextHandler.getConnectionPeer(), authProviderFactory));
ChannelInboundHandler requestHandler = isRunning.get() ? new BookieRequestHandler(conf, requestProcessor, allChannels) : new RejectRequestHandler();
pipeline.addLast("bookieRequestHandler", requestHandler);
pipeline.addLast("contextHandler", contextHandler);
}
});
// use the same address 'name', so clients can find local Bookie still discovering them using ZK
jvmBootstrap.bind(bookieAddress.getLocalAddress()).sync();
LocalBookiesRegistry.registerLocalBookieAddress(bookieAddress);
}
}
use of io.netty.buffer.PooledByteBufAllocator in project jocean-http by isdom.
the class DefaultHttpClientTestCase method testInitiatorInteractionSuccessAsHttpReuseChannel.
@Test(timeout = 5000)
public void testInitiatorInteractionSuccessAsHttpReuseChannel() throws Exception {
// 配置 池化分配器 为 取消缓存,使用 Heap
configDefaultAllocator();
final PooledByteBufAllocator allocator = defaultAllocator();
final BlockingQueue<HttpTrade> trades = new ArrayBlockingQueue<>(1);
final String addr = UUID.randomUUID().toString();
final Subscription server = TestHttpUtil.createTestServerWith(addr, trades, Feature.ENABLE_LOGGING);
final DefaultHttpClient client = new DefaultHttpClient(new TestChannelCreator(), Feature.ENABLE_LOGGING);
assertEquals(0, allActiveAllocationsCount(allocator));
try {
final Channel ch1 = (Channel) startInteraction(client.initiator().remoteAddress(new LocalAddress(addr)), Observable.just(fullHttpRequest()), standardInteraction(allocator, trades)).transport();
assertEquals(0, allActiveAllocationsCount(allocator));
final Channel ch2 = (Channel) startInteraction(client.initiator().remoteAddress(new LocalAddress(addr)), Observable.just(fullHttpRequest()), standardInteraction(allocator, trades)).transport();
assertEquals(0, allActiveAllocationsCount(allocator));
assertSame(ch1, ch2);
} finally {
client.close();
server.unsubscribe();
}
}
use of io.netty.buffer.PooledByteBufAllocator in project jocean-http by isdom.
the class DefaultHttpClientTestCase method testInitiatorInteractionNo1NotSendNo2SuccessReuseChannelAsHttps.
@Test(timeout = 5000)
public void testInitiatorInteractionNo1NotSendNo2SuccessReuseChannelAsHttps() throws Exception {
// 配置 池化分配器 为 取消缓存,使用 Heap
configDefaultAllocator();
final PooledByteBufAllocator allocator = defaultAllocator();
final BlockingQueue<HttpTrade> trades = new ArrayBlockingQueue<>(1);
final String addr = UUID.randomUUID().toString();
final Subscription server = TestHttpUtil.createTestServerWith(addr, trades, enableSSL4ServerWithSelfSigned(), Feature.ENABLE_LOGGING_OVER_SSL);
final DefaultHttpClient client = new DefaultHttpClient(new TestChannelCreator(), enableSSL4Client(), Feature.ENABLE_LOGGING_OVER_SSL);
assertEquals(0, allActiveAllocationsCount(allocator));
try {
final Channel ch1 = (Channel) startInteraction(client.initiator().remoteAddress(new LocalAddress(addr)), Observable.<HttpObject>error(new RuntimeException("test error")), new Interaction() {
@Override
public void interact(final HttpInitiator initiator, final Observable<DisposableWrapper<FullHttpResponse>> getresp) throws Exception {
final TestSubscriber<DisposableWrapper<FullHttpResponse>> subscriber = new TestSubscriber<>();
getresp.subscribe(subscriber);
subscriber.awaitTerminalEvent();
subscriber.assertError(RuntimeException.class);
subscriber.assertNoValues();
}
}).transport();
assertEquals(0, allActiveAllocationsCount(allocator));
final Channel ch2 = (Channel) startInteraction(client.initiator().remoteAddress(new LocalAddress(addr)), Observable.just(fullHttpRequest()), standardInteraction(allocator, trades)).transport();
assertEquals(0, allActiveAllocationsCount(allocator));
assertSame(ch1, ch2);
} finally {
client.close();
server.unsubscribe();
}
}
Aggregations