use of org.apache.flink.shaded.netty4.io.netty.channel.socket.nio.NioSocketChannel in project dubbo by alibaba.
the class NettyServer method doOpen.
@Override
protected void doOpen() throws Throwable {
NettyHelper.setNettyLoggerFactory();
bootstrap = new ServerBootstrap();
bossGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("NettyServerBoss", true));
workerGroup = new NioEventLoopGroup(getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS), new DefaultThreadFactory("NettyServerWorker", true));
final NettyServerHandler nettyServerHandler = new NettyServerHandler(getUrl(), this);
channels = nettyServerHandler.getChannels();
bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childOption(ChannelOption.TCP_NODELAY, Boolean.TRUE).childOption(ChannelOption.SO_REUSEADDR, Boolean.TRUE).childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT).childHandler(new ChannelInitializer<NioSocketChannel>() {
@Override
protected void initChannel(NioSocketChannel ch) throws Exception {
NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyServer.this);
// .addLast("logging",new LoggingHandler(LogLevel.INFO))//for debug
ch.pipeline().addLast("decoder", adapter.getDecoder()).addLast("encoder", adapter.getEncoder()).addLast("handler", nettyServerHandler);
}
});
// bind
ChannelFuture channelFuture = bootstrap.bind(getBindAddress());
channelFuture.syncUninterruptibly();
channel = channelFuture.channel();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.socket.nio.NioSocketChannel in project protools by SeanDragon.
the class HttpClientChannelPoolHandler method channelCreated.
@Override
public void channelCreated(Channel channel) {
NioSocketChannel nioSocketChannel = (NioSocketChannel) channel;
nioSocketChannel.config().setTcpNoDelay(true).setKeepAlive(true);
final ChannelPipeline p = nioSocketChannel.pipeline();
// HTTPS
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(channel.alloc()));
}
p.addLast(new HttpClientCodec(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE));
p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
}
use of org.apache.flink.shaded.netty4.io.netty.channel.socket.nio.NioSocketChannel in project apiRecord by tobecoder2015.
the class HttpProxyServerHandle method handleProxyData.
private void handleProxyData(final ChannelHandlerContext ctx, final Object msg) throws InterruptedException {
if (cf == null) {
Bootstrap bootstrap = new Bootstrap();
// 注册线程池
bootstrap.group(NettyHttpProxyServer.proxyGroup).channel(// 使用NioSocketChannel来作为连接用的channel类
NioSocketChannel.class).handler(new HttpProxyInitializer(ctx.channel(), isSSL));
cf = bootstrap.connect(host, port).sync();
/*cf.addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture future) throws Exception {
System.out.println("11111"+msg);
if (future.isSuccess()) {
future.channel().writeAndFlush(msg);
} else {
ctx.channel().close();
}
}
});*/
}
cf.channel().writeAndFlush(msg);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.socket.nio.NioSocketChannel in project reactor-netty by reactor.
the class DefaultPoolResourcesTest method fixedPoolTwoAcquire.
@Test
public void fixedPoolTwoAcquire() throws ExecutionException, InterruptedException, IOException {
final ScheduledExecutorService service = Executors.newScheduledThreadPool(2);
int echoServerPort = SocketUtils.findAvailableTcpPort();
TcpClientTests.EchoServer echoServer = new TcpClientTests.EchoServer(echoServerPort);
List<Channel> createdChannels = new ArrayList<>();
try {
final InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", echoServerPort);
ChannelPool pool = PoolResources.fixed("fixedPoolTwoAcquire", 2).selectOrCreate(address, () -> new Bootstrap().remoteAddress(address).channelFactory(NioSocketChannel::new).group(new NioEventLoopGroup(2)), createdChannels::add, new NioEventLoopGroup(2));
// fail a couple
assertThatExceptionOfType(Throwable.class).isThrownBy(pool.acquire()::get).withMessageContaining("Connection refused");
assertThatExceptionOfType(Throwable.class).isThrownBy(pool.acquire()::get).withMessageContaining("Connection refused");
// start the echo server
service.submit(echoServer);
Thread.sleep(100);
// acquire 2
final Channel channel1 = pool.acquire().get();
final Channel channel2 = pool.acquire().get();
// make room for 1 more
channel2.close().get();
final Channel channel3 = pool.acquire().get();
// next one will block until a previous one is released
long start = System.currentTimeMillis();
service.schedule(() -> pool.release(channel1), 500, TimeUnit.MILLISECONDS);
final Channel channel4 = pool.acquire().get();
long end = System.currentTimeMillis();
assertThat(end - start).as("channel4 acquire blocked until channel1 released").isGreaterThanOrEqualTo(500);
pool.release(channel3).get();
pool.release(channel4).get();
assertThat(pool).isInstanceOf(DefaultPoolResources.Pool.class);
DefaultPoolResources.Pool defaultPool = (DefaultPoolResources.Pool) pool;
assertThat(defaultPool.activeConnections.get()).as("activeConnections fully released").isZero();
} finally {
echoServer.close();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.socket.nio.NioSocketChannel in project grpc-java by grpc.
the class UtilsTest method channelOptionsTest_nio.
@Test
public void channelOptionsTest_nio() {
Channel channel = new NioSocketChannel();
SocketOptions socketOptions = setAndValidateGeneric(channel);
assertNull(socketOptions.soTimeoutMillis);
}
Aggregations