@Override @SuppressWarnings("unchecked") public SocketChannel delegate() { return (SocketChannel) tcpStream.delegate(); }
@Override protected void doDecoded(IN in) { tcpStream.doDecoded(in); }
public NettyHttpWSClientHandler( ReactorChannelHandler<IN, OUT, ChannelStream<IN, OUT>> handler, NettyChannelStream<IN, OUT> tcpStream, WebSocketClientHandshaker handshaker) { super(handler, tcpStream); this.handshaker = handshaker; this.plainText = tcpStream.getEncoder() instanceof StringCodec.StringEncoder; }
protected void bindChannel(ReactorChannelHandler<IN, OUT, ChannelStream<IN, OUT>> handler, SocketChannel nativeChannel) { NettyChannelStream<IN, OUT> netChannel = new NettyChannelStream<IN, OUT>( getDefaultEnvironment(), getDefaultCodec(), getDefaultPrefetchSize(), getDefaultDispatcher(), nativeChannel ); ChannelPipeline pipeline = nativeChannel.pipeline(); if (log.isDebugEnabled()) { pipeline.addLast(new LoggingHandler(NettyTcpClient.class)); } pipeline.addLast( new NettyChannelHandlerBridge<IN, OUT>(handler, netChannel) ); }
protected void bindChannel(ReactorChannelHandler<IN, OUT, ChannelStream<IN, OUT>> handler, SocketChannel nativeChannel) { NettyChannelStream<IN ,OUT> netChannel = new NettyChannelStream<IN, OUT>( getDefaultEnvironment(), getDefaultCodec(), getDefaultPrefetchSize(), getDefaultDispatcher(), nativeChannel ); ChannelPipeline pipeline = nativeChannel.pipeline(); if(log.isDebugEnabled()){ pipeline.addLast(new LoggingHandler(NettyTcpServer.class)); } pipeline.addLast( new NettyChannelHandlerBridge<IN, OUT>(handler, netChannel) ); }
StompTcpClientSpecFactory(String host, int port, EventLoopGroup group, Environment environment) { this.host = host; this.port = port; this.socketOptions = new NettyClientSocketOptions().eventLoopGroup(group); this.environment = environment; this.codec = new Reactor2StompCodec(new StompEncoder(), new StompDecoder()); }
@Override public void initChannel(final DatagramChannel ch) throws Exception { if (null != nettyOptions && null != nettyOptions.pipelineConfigurer()) { nettyOptions.pipelineConfigurer().accept(ch.pipeline()); } bindChannel(channelHandler, ch); } }).bind();
@Override public void write(final ChannelHandlerContext ctx, Object msg, final ChannelPromise promise) throws Exception { if (msg instanceof Publisher) { CHANNEL_REF.incrementAndGet(this); @SuppressWarnings("unchecked") Publisher<?> data = (Publisher<?>) msg; final long capacity = msg instanceof NonBlocking ? ((NonBlocking) data).getCapacity() : Long.MAX_VALUE; if (capacity == Long.MAX_VALUE) { data.subscribe(new FlushOnTerminateSubscriber(ctx, promise)); } else { data.subscribe(new FlushOnCapacitySubscriber(ctx, promise, capacity)); } } else { super.write(ctx, msg, promise); } }
@Override public ConsumerSpec on() { return tcpStream.on(); }
@Override public ConsumerSpec on() { return new NettyConsumerSpec(); }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { doRead(ctx, msg); }
@Override protected void doSubscribeWriter(Publisher<? extends OUT> writer, Subscriber<? super Void> postWriter) { tcpStream.doSubscribeWriter(writer, postWriter); }
@Override public InetSocketAddress remoteAddress() { return tcpStream.remoteAddress(); }
private ClientSocketOptions createClientSocketOptions() { return (ClientSocketOptions) ReflectionUtils.invokeMethod(eventLoopGroupMethod, new NettyClientSocketOptions(), nioEventLoopGroup); } };
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { subscriber.onError(future.cause()); } else { tcpStream.subscribe(subscriber); } } });
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg != null && DatagramPacket.class.isAssignableFrom(msg.getClass())) { super.channelRead(ctx, ((DatagramPacket) msg).content()); } else { super.channelRead(ctx, msg); } } },
@Override public void subscribe(Subscriber<? super IN> subscriber) { ioChannel.pipeline() .fireUserEventTriggered(new NettyChannelHandlerBridge.ChannelInputSubscriberEvent<>(subscriber)); }
@Override @SuppressWarnings("unchecked") public void doDecoded(IN in) { NettyChannelHandlerBridge ch = ioChannel.pipeline().get(NettyChannelHandlerBridge.class); PushSubscription<IN> subscription = ch == null ? null : ch.subscription(); if (subscription != null) { try { subscription.onNext(in); } catch (CancelException ce){ } } }
protected ChannelFuture doOnWrite(Object data, ChannelHandlerContext ctx) { if (data.getClass().equals(Buffer.class)) { return ctx.channel().write(convertBufferToByteBuff(ctx, (Buffer) data)); } else if (Unpooled.EMPTY_BUFFER != data) { return ctx.channel().write(data); } return null; }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { d.onError(future.cause()); return; } if (null == nettyOptions || null == nettyOptions.eventLoopGroup()) { ioGroup.shutdownGracefully().addListener(listener); } } });