use of io.netty.channel.ChannelInitializer in project moco by dreamhead.
the class MocoHttpServer method channelInitializer.
@Override
public final ChannelInitializer<SocketChannel> channelInitializer() {
return new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(final SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
if (serverSetting.isSecure()) {
pipeline.addFirst("ssl", serverSetting.sslHandler().get());
}
ServerConfig serverConfig = serverSetting.getServerConfig();
pipeline.addLast("codec", new HttpServerCodec(MAX_INITIAL_LINE_LENGTH, serverConfig.getHeaderSize(), MAX_CHUNK_SIZE, false));
pipeline.addLast("aggregator", new HttpObjectAggregator(serverConfig.getContentLength()));
pipeline.addLast("handler", new MocoHandler(serverSetting));
}
};
}
use of io.netty.channel.ChannelInitializer in project vert.x by eclipse.
the class Http2ServerTest method testPriorKnowledge.
@Test
public void testPriorKnowledge() throws Exception {
server.close();
server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST));
server.requestHandler(req -> {
req.response().end("Hello World");
});
startServer();
TestClient client = new TestClient() {
@Override
protected ChannelInitializer channelInitializer(int port, String host, Consumer<Connection> handler) {
return new ChannelInitializer() {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
Http2Connection connection = new DefaultHttp2Connection(false);
TestClientHandlerBuilder clientHandlerBuilder = new TestClientHandlerBuilder(handler);
TestClientHandler clientHandler = clientHandlerBuilder.build(connection);
p.addLast(clientHandler);
}
};
}
};
ChannelFuture fut = client.connect(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, request -> {
request.decoder.frameListener(new Http2EventAdapter() {
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
vertx.runOnContext(v -> {
testComplete();
});
}
});
int id = request.nextStreamId();
request.encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.netty.channel.ChannelInitializer in project vert.x by eclipse.
the class HostnameResolutionTest method testAsyncResolveConnectIsNotifiedOnChannelEventLoop.
@Test
public void testAsyncResolveConnectIsNotifiedOnChannelEventLoop() throws Exception {
CountDownLatch listenLatch = new CountDownLatch(1);
NetServer server = vertx.createNetServer().connectHandler(so -> {
});
try {
server.listen(1234, "localhost", onSuccess(v -> listenLatch.countDown()));
awaitLatch(listenLatch);
AtomicReference<Thread> channelThread = new AtomicReference<>();
CountDownLatch connectLatch = new CountDownLatch(1);
Bootstrap bootstrap = new Bootstrap();
bootstrap.channelFactory(((VertxInternal) vertx).transport().channelFactory(false));
bootstrap.group(vertx.nettyEventLoopGroup());
bootstrap.resolver(((VertxInternal) vertx).nettyAddressResolverGroup());
bootstrap.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
channelThread.set(Thread.currentThread());
connectLatch.countDown();
}
});
ChannelFuture channelFut = bootstrap.connect("localhost", 1234);
awaitLatch(connectLatch);
channelFut.addListener(v -> {
assertTrue(v.isSuccess());
assertEquals(channelThread.get(), Thread.currentThread());
testComplete();
});
await();
} finally {
server.close();
}
}
use of io.netty.channel.ChannelInitializer in project hive by apache.
the class ShuffleHandler method initPipeline.
private void initPipeline(ServerBootstrap bootstrap, Configuration conf) throws Exception {
SHUFFLE = getShuffle(conf);
// TODO Setup SSL Shuffle
// if (conf.getBoolean(MRConfig.SHUFFLE_SSL_ENABLED_KEY,
// MRConfig.SHUFFLE_SSL_ENABLED_DEFAULT)) {
// LOG.info("Encrypted shuffle is enabled.");
// sslFactory = new SSLFactory(SSLFactory.Mode.SERVER, conf);
// sslFactory.init();
// }
ChannelInitializer<NioSocketChannel> channelInitializer = new ChannelInitializer<NioSocketChannel>() {
@Override
public void initChannel(NioSocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
if (sslFactory != null) {
pipeline.addLast("ssl", new SslHandler(sslFactory.createSSLEngine()));
}
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("aggregator", new HttpObjectAggregator(1 << 16));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("chunking", new ChunkedWriteHandler());
pipeline.addLast("shuffle", SHUFFLE);
pipeline.addLast("idle", new IdleStateHandler(0, connectionKeepAliveTimeOut, 0));
pipeline.addLast(TIMEOUT_HANDLER, new TimeoutHandler());
}
};
bootstrap.childHandler(channelInitializer);
}
use of io.netty.channel.ChannelInitializer in project graylog2-server by Graylog2.
the class NettyTransport method getChannelInitializer.
protected ChannelInitializer<? extends Channel> getChannelInitializer(final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlerList) {
return new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
final ChannelPipeline p = ch.pipeline();
Map.Entry<String, Callable<? extends ChannelHandler>> postentry = null;
for (final Map.Entry<String, Callable<? extends ChannelHandler>> entry : handlerList.entrySet()) {
// Handle exceptions at the top of the (bottom-up evaluated) pipeline
if (entry.getKey().equals("exception-logger")) {
postentry = entry;
} else {
p.addLast(entry.getKey(), entry.getValue().call());
}
}
if (postentry != null) {
p.addLast(postentry.getKey(), postentry.getValue().call());
}
}
};
}
Aggregations