use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project netty by netty.
the class NioSocketChannelTest method testChannelReRegisterRead.
private static void testChannelReRegisterRead(final boolean sameEventLoop) throws Exception {
final EventLoopGroup group = new NioEventLoopGroup(2);
final CountDownLatch latch = new CountDownLatch(1);
// Just some random bytes
byte[] bytes = new byte[1024];
PlatformDependent.threadLocalRandom().nextBytes(bytes);
Channel sc = null;
Channel cc = null;
ServerBootstrap b = new ServerBootstrap();
try {
b.group(group).channel(NioServerSocketChannel.class).childOption(ChannelOption.SO_KEEPALIVE, true).childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new SimpleChannelInboundHandler<ByteBuf>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf byteBuf) {
// We was able to read something from the Channel after reregister.
latch.countDown();
}
@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
final EventLoop loop = group.next();
if (sameEventLoop) {
deregister(ctx, loop);
} else {
loop.execute(new Runnable() {
@Override
public void run() {
deregister(ctx, loop);
}
});
}
}
private void deregister(ChannelHandlerContext ctx, final EventLoop loop) {
// As soon as the channel becomes active re-register it to another
// EventLoop. After this is done we should still receive the data that
// was written to the channel.
ctx.deregister().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture cf) {
Channel channel = cf.channel();
assertNotSame(loop, channel.eventLoop());
group.next().register(channel);
}
});
}
});
}
});
sc = b.bind(0).syncUninterruptibly().channel();
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group).channel(NioSocketChannel.class);
bootstrap.handler(new ChannelInboundHandlerAdapter());
cc = bootstrap.connect(sc.localAddress()).syncUninterruptibly().channel();
cc.writeAndFlush(Unpooled.wrappedBuffer(bytes)).syncUninterruptibly();
latch.await();
} finally {
if (cc != null) {
cc.close();
}
if (sc != null) {
sc.close();
}
group.shutdownGracefully();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project netty by netty.
the class SocketSslGreetingTest method testSslGreeting.
public void testSslGreeting(ServerBootstrap sb, Bootstrap cb) throws Throwable {
final ServerHandler sh = new ServerHandler();
final ClientHandler ch = new ClientHandler();
sb.childHandler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(Channel sch) throws Exception {
ChannelPipeline p = sch.pipeline();
p.addLast(serverCtx.newHandler(sch.alloc()));
p.addLast(new LoggingHandler(LOG_LEVEL));
p.addLast(sh);
}
});
cb.handler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(Channel sch) throws Exception {
ChannelPipeline p = sch.pipeline();
p.addLast(clientCtx.newHandler(sch.alloc()));
p.addLast(new LoggingHandler(LOG_LEVEL));
p.addLast(ch);
}
});
Channel sc = sb.bind().sync().channel();
Channel cc = cb.connect().sync().channel();
ch.latch.await();
sh.channel.close().awaitUninterruptibly();
cc.close().awaitUninterruptibly();
sc.close().awaitUninterruptibly();
if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) {
throw sh.exception.get();
}
if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) {
throw ch.exception.get();
}
if (sh.exception.get() != null) {
throw sh.exception.get();
}
if (ch.exception.get() != null) {
throw ch.exception.get();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project alluxio by Alluxio.
the class PipelineHandler method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("frameDecoder", RPCMessage.createFrameDecoder());
pipeline.addLast("RPCMessageDecoder", new RPCMessageDecoder());
pipeline.addLast("RPCMessageEncoder", new RPCMessageEncoder());
pipeline.addLast("dataServerHandler", mDataServerHandler);
pipeline.addLast("dataServerBlockReadHandler", new DataServerBlockReadHandler(NettyExecutors.BLOCK_READER_EXECUTOR, mWorker.getBlockWorker(), mFileTransferType));
pipeline.addLast("dataServerUfsBlockReadHandler", new DataServerUfsBlockReadHandler(NettyExecutors.UFS_BLOCK_READER_EXECUTOR, mWorker.getBlockWorker()));
pipeline.addLast("dataServerBlockWriteHandler", new DataServerBlockWriteHandler(NettyExecutors.BLOCK_WRITER_EXECUTOR, mWorker.getBlockWorker()));
// DataServerFileReadHandler is deprecated. It is here for backward compatibility.
pipeline.addLast("dataServerFileReadHandler", new DataServerUFSFileReadHandler(NettyExecutors.UFS_BLOCK_READER_EXECUTOR, mWorker.getFileSystemWorker()));
pipeline.addLast("dataServerFileWriteHandler", new DataServerUFSFileWriteHandler(NettyExecutors.FILE_WRITER_EXECUTOR, mWorker.getFileSystemWorker()));
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project jersey by jersey.
the class JerseyServerInitializer method initChannel.
@Override
public void initChannel(SocketChannel ch) {
if (http2) {
if (sslCtx != null) {
configureSsl(ch);
} else {
configureClearText(ch);
}
} else {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc()));
}
p.addLast(new HttpServerCodec());
p.addLast(new ChunkedWriteHandler());
p.addLast(new JerseyServerHandler(baseUri, container));
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project carbondata by apache.
the class DictionaryClient method startClient.
/**
* start dictionary client
*
* @param address
* @param port
*/
public void startClient(String address, int port) {
LOGGER.audit("Starting client on " + address + " " + port);
long start = System.currentTimeMillis();
// Create an Event with 1 thread.
workerGroup = new NioEventLoopGroup(1);
Bootstrap clientBootstrap = new Bootstrap();
clientBootstrap.group(workerGroup).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// Based on length provided at header, it collects all packets
pipeline.addLast("LengthDecoder", new LengthFieldBasedFrameDecoder(1048576, 0, 2, 0, 2));
pipeline.addLast("DictionaryClientHandler", dictionaryClientHandler);
}
});
clientBootstrap.connect(new InetSocketAddress(address, port));
LOGGER.info("Dictionary client Started, Total time spent : " + (System.currentTimeMillis() - start));
}
Aggregations