@Override public void run() { bossGroup = new NioEventLoopGroup(1); workerGroup = new NioEventLoopGroup(); new ServerBootstrap().group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100) .handler(new LoggingHandler(EchoServer.class)) .childHandler(new EchoServerInitializer(mockServerLogger, secure, error)) .childAttr(LOG_FILTER, logFilter) .childAttr(NEXT_RESPONSE, nextResponse) .childAttr(ONLY_RESPONSE, onlyResponse) .bind(0) .addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { boundPort.set(((InetSocketAddress) future.channel().localAddress()).getPort()); } else { boundPort.setException(future.cause()); eventLoopGroup.shutdownGracefully(0, 1, TimeUnit.MILLISECONDS); } } }); } }, "MockServer EchoServer Thread").start();
private void createServerBootstrap(final ProxyConfiguration proxyConfiguration, final Integer... localPorts) { List<Integer> portBindings = singletonList(0); if (localPorts != null && localPorts.length > 0) { portBindings = Arrays.asList(localPorts); } serverServerBootstrap = new ServerBootstrap() .group(bossGroup, workerGroup) .option(ChannelOption.SO_BACKLOG, 1024) .channel(NioServerSocketChannel.class) .childOption(ChannelOption.AUTO_READ, true) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(8 * 1024, 32 * 1024)) .childHandler(new MockServerUnificationInitializer(MockServer.this, httpStateHandler, proxyConfiguration)) .childAttr(REMOTE_SOCKET, remoteSocket) .childAttr(PROXYING, remoteSocket != null); bindServerPorts(portBindings); startedServer(getLocalPorts()); }
.channel( PipelineUtils.getServerChannel() ) .option( ChannelOption.SO_REUSEADDR, true ) // TODO: Move this elsewhere! .childAttr( PipelineUtils.LISTENER, info ) .childHandler( PipelineUtils.SERVER_CHILD ) .group( eventLoops )
/** * Attribute default attribute to the future {@link Channel} connection. They will * be available via {@link reactor.ipc.netty.NettyInbound#attr(AttributeKey)}. * * @param key the attribute key * @param value the attribute value * @param <T> the attribute type * @return {@code this} * @see ServerBootstrap#childAttr(AttributeKey, Object) */ @Override public final <T> BUILDER attr(AttributeKey<T> key, T value) { this.bootstrapTemplate.childAttr(key, value); return get(); }
/** * Inject default attribute to the future child {@link Channel} connections. They * will be available via {@link Channel#attr(AttributeKey)}. * If the {@code value} is {@code null}, the attribute of the specified {@code key} * is removed. * * @param key the attribute key * @param value the attribute value * @param <T> the attribute type * * @return a new {@link TcpServer} * * @see ServerBootstrap#childAttr(AttributeKey, Object) */ public final <T> TcpServer attr(AttributeKey<T> key, @Nullable T value) { Objects.requireNonNull(key, "key"); return bootstrap(b -> b.childAttr(key, value)); }
/** * Inject default attribute to the future child {@link Channel} connections. They * will be available via {@link Channel#attr(AttributeKey)}. * If the {@code value} is {@code null}, the attribute of the specified {@code key} * is removed. * * @param key the attribute key * @param value the attribute value * @param <T> the attribute type * * @return a new {@link TcpServer} * * @see ServerBootstrap#childAttr(AttributeKey, Object) */ public final <T> TcpServer attr(AttributeKey<T> key, @Nullable T value) { Objects.requireNonNull(key, "key"); return bootstrap(b -> b.childAttr(key, value)); }
@Override public void run() { bossGroup = new NioEventLoopGroup(1); workerGroup = new NioEventLoopGroup(); new ServerBootstrap().group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100) .handler(new LoggingHandler(EchoServer.class)) .childHandler(new EchoServerInitializer(mockServerLogger, secure, error)) .childAttr(LOG_FILTER, logFilter) .childAttr(NEXT_RESPONSE, nextResponse) .childAttr(ONLY_RESPONSE, onlyResponse) .bind(0) .addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { boundPort.set(((InetSocketAddress) future.channel().localAddress()).getPort()); } else { boundPort.setException(future.cause()); eventLoopGroup.shutdownGracefully(0, 1, TimeUnit.MILLISECONDS); } } }); } }, "MockServer EchoServer Thread").start();
private void createServerBootstrap(final ProxyConfiguration proxyConfiguration, final Integer... localPorts) { List<Integer> portBindings = singletonList(0); if (localPorts != null && localPorts.length > 0) { portBindings = Arrays.asList(localPorts); } serverServerBootstrap = new ServerBootstrap() .group(bossGroup, workerGroup) .option(ChannelOption.SO_BACKLOG, 1024) .channel(NioServerSocketChannel.class) .childOption(ChannelOption.AUTO_READ, true) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(8 * 1024, 32 * 1024)) .childHandler(new MockServerUnificationInitializer(MockServer.this, httpStateHandler, proxyConfiguration)) .childAttr(REMOTE_SOCKET, remoteSocket) .childAttr(PROXYING, remoteSocket != null); bindServerPorts(portBindings); startedServer(getLocalPorts()); }
NioServerSocketChannel.class).handler( new LoggingHandler(LogLevel.INFO)).childHandler( new NettyServerInitializer()).childAttr(AttributeKey.newInstance("abc"),"aaaa");
.childOption( ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 1024 * 1024 * 10 ) .childOption( ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 1024 * 1024 * 1 ) .childAttr( PipelineUtils.LISTENER, info ) .childHandler( PipelineUtils.SERVER_CHILD ) .group( bossEventLoopGroup, workerEventLoopGroup )