protected ChannelHandler[] createChannelHandlers(SocketChannel ch) { AbstractNetChannel<IN, OUT> netChannel = (AbstractNetChannel<IN, OUT>) select(ch); NettyNetChannelInboundHandler readHandler = new NettyNetChannelInboundHandler() .setNetChannel(netChannel); NettyNetChannelOutboundHandler writeHandler = new NettyNetChannelOutboundHandler(); return new ChannelHandler[]{readHandler, writeHandler}; }
@Override public BatchConsumer<OUT> out() { return netChannel.out(); }
@Override public ConsumerSpec on() { return new NettyConsumerSpec(); }
@Override protected <C> NetChannel<IN, OUT> createChannel(C ioChannel) { return new NettyNetChannel<IN, OUT>( getEnvironment(), getCodec(), new NettyEventLoopDispatcher(((Channel) ioChannel).eventLoop(), 256), getReactor(), (Channel) ioChannel ); }
@Override protected <C> NetChannel<IN, OUT> createChannel(C ioChannel) { SocketChannel ch = (SocketChannel) ioChannel; int backlog = getEnvironment().getProperty("reactor.tcp.connectionReactorBacklog", Integer.class, 128); return new NettyNetChannel<IN, OUT>( getEnvironment(), getCodec(), new NettyEventLoopDispatcher(ch.eventLoop(), backlog), getReactor(), ch ); }
protected ChannelHandler[] createChannelHandlers(SocketChannel ioChannel) { NettyNetChannel<IN, OUT> conn = (NettyNetChannel<IN, OUT>) createChannel(ioChannel); NettyNetChannelInboundHandler readHandler = new NettyNetChannelInboundHandler() .setNetChannel(conn); NettyNetChannelOutboundHandler writeHandler = new NettyNetChannelOutboundHandler(); return new ChannelHandler[]{readHandler, writeHandler}; }
@Override protected <C> NetChannel<IN, OUT> createChannel(C ioChannel) { return new NettyNetChannel<IN, OUT>( getEnvironment(), getCodec(), new SynchronousDispatcher(), getReactor(), (NioDatagramChannel) ioChannel ); }
@Bean public ServerSocketOptions serverSocketOptions() { return new NettyServerSocketOptions() .pipelineConfigurer( pipeline -> pipeline .addLast(new HttpServerCodec()) .addLast(new HttpObjectAggregator(16 * 1024 * 1024)) ); }
if (remainder == null) { try { passToConnection(data); } finally { if (data.isReadable()) { if (!bufferHasSufficientCapacity(remainder, data)) { ByteBuf combined = createCombinedBuffer(remainder, data, ctx); remainder.release(); remainder = combined; passToConnection(remainder); } finally { if (remainder.isReadable()) {
if (null != nettyOptions && null != nettyOptions.pipelineConfigurer()) { nettyOptions.pipelineConfigurer().accept(ch.pipeline()); inboundHandler.setNetChannel(netChannel);
@Override public void initChannel(final SocketChannel ch) throws Exception { ch.config().setConnectTimeoutMillis(options.timeout()); if (null != sslOptions) { SSLEngine ssl = new SSLEngineSupplier(sslOptions, true).get(); if (log.isDebugEnabled()) { log.debug("SSL enabled using keystore {}", (null != sslOptions.keystoreFile() ? sslOptions.keystoreFile() : "<DEFAULT>")); } ch.pipeline().addLast(new SslHandler(ssl)); } if (null != nettyOptions && null != nettyOptions.pipelineConfigurer()) { nettyOptions.pipelineConfigurer().accept(ch.pipeline()); } ch.pipeline().addLast(createChannelHandlers(ch)); } });
@SuppressWarnings("unchecked") @Override public void accept(Void v) { GenericFutureListener listener = new GenericFutureListener() { @Override public void operationComplete(Future future) throws Exception { if (future.isSuccess()) { d.accept(true); } else { d.accept(future.cause()); } } }; if (null == nettyOptions || null == nettyOptions.eventLoopGroup()) { ioGroup.shutdownGracefully().addListener(listener); } } },
@Override public Stream<IN> in() { return netChannel.in(); }
@Override public DatagramServer<IN, OUT> send(OUT data) { if (null == channel) { throw new IllegalStateException("DatagramServer not running."); } netChannel.send(data); return this; }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { super.channelRead(ctx, ((DatagramPacket) msg).content()); } };
@Override public boolean awaitAndShutdown(long timeout, TimeUnit timeUnit) { shutdown(); try { return eventLoop.awaitTermination(timeout, timeUnit); } catch(InterruptedException e) { Thread.currentThread().interrupt(); } return false; }
@Override protected void write(ByteBuffer data, Deferred<Void, Promise<Void>> onComplete, boolean flush) { ByteBuf buf = ioChannel.alloc().buffer(data.remaining()); buf.writeBytes(data); write(buf, onComplete, flush); }
@Override public void close(@Nullable final Consumer<Boolean> onClose) { if (null != nettyOptions && null != nettyOptions.eventLoopGroup()) { ioGroup.submit(new Runnable() { @Override public void run() { if (null != onClose) { onClose.accept(true); } } }); } else { ioGroup.shutdownGracefully().addListener(new FutureListener<Object>() { @Override public void operationComplete(Future<Object> future) throws Exception { if (null != onClose) { onClose.accept(future.isDone() && future.isSuccess()); } } }); } }
@SuppressWarnings({"rawtypes", "unchecked"}) @Override public void accept(Void v) { final AtomicInteger groupsToShutdown = new AtomicInteger(2); GenericFutureListener listener = new GenericFutureListener() { @Override public void operationComplete(Future future) throws Exception { if (groupsToShutdown.decrementAndGet() == 0) { notifyShutdown(); d.accept(true); } } }; selectorGroup.shutdownGracefully().addListener(listener); if (null == nettyOptions || null == nettyOptions.eventLoopGroup()) { ioGroup.shutdownGracefully().addListener(listener); } } },
if (null != nettyOptions && null != nettyOptions.eventLoopGroup()) { this.ioGroup = nettyOptions.eventLoopGroup(); } else { int ioThreadCount = env.getProperty("reactor.udp.ioThreadCount",