use of org.apache.flink.shaded.netty4.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());
}
}
};
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInitializer in project chuidiang-ejemplos by chuidiang.
the class Client method run.
public void run() throws Exception {
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
// (2)
Bootstrap b = new Bootstrap();
b.group(workerGroup).channel(// (3)
NioSocketChannel.class).handler(new // (4)
ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new KryoDecoderHandler());
ch.pipeline().addLast(new KryoEncoderHandler());
ch.pipeline().addLast(handler);
}
}).option(ChannelOption.SO_KEEPALIVE, // (6)
true);
// Bind and start to accept incoming connections.
// (7)
ChannelFuture f = b.connect("localhost", port).sync();
// Wait until the server socket is closed.
// In this example, this does not happen, but you can do that to gracefully
// shut down your server.
f.channel().closeFuture().sync();
} finally {
workerGroup.shutdownGracefully();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInitializer in project chuidiang-ejemplos by chuidiang.
the class Client method run.
public void run() throws Exception {
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
// (2)
Bootstrap b = new Bootstrap();
b.group(workerGroup).channel(// (3)
NioSocketChannel.class).handler(new // (4)
ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new FrameExtractor());
ch.pipeline().addLast(new FrameMaker());
ch.pipeline().addLast(new StringDecoder());
ch.pipeline().addLast(new StringEncoder());
ch.pipeline().addLast(clientHandler);
}
}).option(ChannelOption.SO_KEEPALIVE, // (6)
true);
// Bind and start to accept incoming connections.
// (7)
ChannelFuture f = b.connect("localhost", port).sync();
// Wait until the server socket is closed.
// In this example, this does not happen, but you can do that to gracefully
// shut down your server.
f.channel().closeFuture().sync();
} finally {
workerGroup.shutdownGracefully();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInitializer in project ambry by linkedin.
the class NettyServerTest method getNettyServer.
// helpers
// general
/**
* Gets an instance of {@link NettyServer}.
* @param properties the in-memory {@link Properties} to use.
* @return an instance of {@link NettyServer}.
* @throws InstantiationException
* @throws IOException
*/
private NettyServer getNettyServer(Properties properties) throws InstantiationException, IOException {
if (properties == null) {
// dud properties. should pick up defaults
properties = new Properties();
}
VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
final NettyConfig nettyConfig = new NettyConfig(verifiableProperties);
final PerformanceConfig performanceConfig = new PerformanceConfig(verifiableProperties);
Map<Integer, ChannelInitializer<SocketChannel>> channelInitializers = new HashMap<>();
channelInitializers.put(nettyConfig.nettyServerPort, new FrontendNettyChannelInitializer(nettyConfig, performanceConfig, NETTY_METRICS, CONNECTION_STATS_HANDLER, REQUEST_HANDLER, PUBLIC_ACCESS_LOGGER, REST_SERVER_STATE, null, null));
channelInitializers.put(nettyConfig.nettyServerSSLPort, new FrontendNettyChannelInitializer(nettyConfig, performanceConfig, NETTY_METRICS, CONNECTION_STATS_HANDLER, REQUEST_HANDLER, PUBLIC_ACCESS_LOGGER, REST_SERVER_STATE, SSL_FACTORY, null));
return new NettyServer(nettyConfig, NETTY_METRICS, channelInitializers);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInitializer in project weicoder by wdcode.
the class WebSocketServer method handler.
@Override
protected ChannelHandler handler() {
return new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(final SocketChannel ch) throws Exception {
ch.pipeline().addLast(new HttpServerCodec());
ch.pipeline().addLast(new HttpObjectAggregator(1024 * 1024));
ch.pipeline().addLast(new WebSocketHandler("websocket"));
ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);
}
};
}
Aggregations