List of usage examples for io.netty.buffer PooledByteBufAllocator DEFAULT
PooledByteBufAllocator DEFAULT
To view the source code for io.netty.buffer PooledByteBufAllocator DEFAULT.
Click Source Link
From source file:com.ibasco.agql.protocols.valve.steam.master.packets.MasterServerRequestPacket.java
License:Open Source License
@Override public byte[] getPayload() { String filterString = this.filter.toString(); int payloadSize = (3 + filterString.length() + (this.startIp.length())); final ByteBuf payload = PooledByteBufAllocator.DEFAULT.buffer(payloadSize); try {/*w ww. j av a 2s. c o m*/ payload.writeByte(getRegion()); payload.writeBytes(getStartIp().getBytes()); payload.writeByte(0); //terminating byte payload.writeBytes(filterString.getBytes()); byte[] payloadBytes = new byte[payload.readableBytes()]; payload.readBytes(payloadBytes); return payloadBytes; } finally { payload.release(); } }
From source file:com.ict.dtube.remoting.netty.NettyRemotingServer.java
License:Apache License
@Override public void start() { this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(// nettyServerConfig.getServerWorkerThreads(), // new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); @Override//from ww w.j av a2 s . c o m public Thread newThread(Runnable r) { return new Thread(r, "NettyServerWorkerThread_" + this.threadIndex.incrementAndGet()); } }); ServerBootstrap childHandler = // this.serverBootstrap.group(this.eventLoopGroupBoss, this.eventLoopGroupWorker) .channel(NioServerSocketChannel.class) // .option(ChannelOption.SO_BACKLOG, 1024) // .option(ChannelOption.SO_REUSEADDR, true) // .childOption(ChannelOption.TCP_NODELAY, true) // .childOption(ChannelOption.SO_SNDBUF, NettySystemConfig.SocketSndbufSize) // .childOption(ChannelOption.SO_RCVBUF, NettySystemConfig.SocketRcvbufSize) .localAddress(new InetSocketAddress(this.nettyServerConfig.getListenPort())) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast( // defaultEventExecutorGroup, // new NettyEncoder(), // new NettyDecoder(), // new IdleStateHandler(0, 0, nettyServerConfig.getServerChannelMaxIdleTimeSeconds()), // new NettyConnetManageHandler(), // new NettyServerHandler()); } }); if (NettySystemConfig.NettyPooledByteBufAllocatorEnable) { // ???? childHandler.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)// ; } try { ChannelFuture sync = this.serverBootstrap.bind().sync(); InetSocketAddress addr = (InetSocketAddress) sync.channel().localAddress(); this.port = addr.getPort(); } catch (InterruptedException e1) { throw new RuntimeException("this.serverBootstrap.bind().sync() InterruptedException", e1); } if (this.channelEventListener != null) { this.nettyEventExecuter.start(); } // ?1?? this.timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { try { NettyRemotingServer.this.scanResponseTable(); } catch (Exception e) { log.error("scanResponseTable exception", e); } } }, 1000 * 3, 1000); }
From source file:com.imaginarycode.minecraft.bungeejson.impl.httpserver.NettyBootstrap.java
License:Open Source License
public void initialize() { group = new NioEventLoopGroup(5, factory); int port = 7432; // CONFIG ServerBootstrap b = new ServerBootstrap(); b.group(group).channel(NioServerSocketChannel.class) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childHandler(new ChannelInitializer<SocketChannel>() { @Override//from w w w . j a v a 2 s.c o m public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("messageCodec", new HttpServerCodec()); pipeline.addLast("messageHandler", new HttpServerHandler()); } }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true); channelFuture = b.bind(port).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture channelFuture) throws Exception { BungeeJSONPlugin.getPlugin().getLogger() .info("BungeeJSON server started on " + channelFuture.channel().localAddress()); } }); }
From source file:com.l2jmobius.commons.network.NetworkManager.java
License:Open Source License
public NetworkManager(EventLoopGroup bossGroup, EventLoopGroup workerGroup, ChannelInitializer<SocketChannel> clientInitializer, String host, int port) { // @formatter:off _serverBootstrap = new ServerBootstrap().group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .childHandler(clientInitializer) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); // @formatter:on _host = host;// www .jav a2 s .c o m _port = port; }
From source file:com.lambdaworks.redis.protocol.RedisStateMachineBenchmark.java
License:Apache License
@Setup(Level.Trial) public void setup() { masterBuffer = PooledByteBufAllocator.DEFAULT.ioBuffer(32); masterBuffer.writeBytes(payload); }
From source file:com.linecorp.armeria.common.stream.AbstractStreamMessageAndWriterTest.java
License:Apache License
@Test public void releaseWhenWritingToClosedStream_ByteBuf() { StreamMessageAndWriter<Object> stream = newStreamWriter(ImmutableList.of()); final ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer().retain(); stream.close();/* ww w . j a v a2 s. c o m*/ await().untilAsserted(() -> assertThat(stream.isOpen()).isFalse()); assertThat(stream.tryWrite(buf)).isFalse(); assertThat(buf.refCnt()).isOne(); assertThatThrownBy(() -> stream.write(buf)).isInstanceOf(ClosedPublisherException.class); assertThat(buf.refCnt()).isZero(); }
From source file:com.linecorp.armeria.common.stream.AbstractStreamMessageAndWriterTest.java
License:Apache License
@Test public void releaseWhenWritingToClosedStream_ByteBuf_Supplier() { StreamMessageAndWriter<Object> stream = newStreamWriter(ImmutableList.of()); final ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer().retain(); stream.close();/*from w w w.java2 s .c o m*/ await().untilAsserted(() -> assertThat(stream.isOpen()).isFalse()); assertThat(stream.tryWrite(() -> buf)).isFalse(); assertThat(buf.refCnt()).isOne(); assertThatThrownBy(() -> stream.write(() -> buf)).isInstanceOf(ClosedPublisherException.class); assertThat(buf.refCnt()).isZero(); }
From source file:com.linecorp.armeria.common.stream.AbstractStreamMessageTest.java
License:Apache License
protected static ByteBuf newPooledBuffer() { return PooledByteBufAllocator.DEFAULT.buffer().writeByte(0); }
From source file:com.linecorp.armeria.common.stream.DefaultStreamMessageTest.java
License:Apache License
@Test public void releaseWhenWritingToClosedStream_ByteBuf() { final DefaultStreamMessage<Object> m = new DefaultStreamMessage<>(); final ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer(); m.close();/*from w w w. j ava2s .c om*/ assertThat(m.write(buf)).isFalse(); assertThat(buf.refCnt()).isZero(); }
From source file:com.linecorp.armeria.common.stream.DefaultStreamMessageTest.java
License:Apache License
private static ByteBuf newPooledBuffer() { return PooledByteBufAllocator.DEFAULT.buffer().writeByte(0); }