use of io.netty.channel.ChannelHandler in project graylog2-server by Graylog2.
the class AbstractTcpTransport method getBootstrap.
protected ServerBootstrap getBootstrap(MessageInput input) {
final LinkedHashMap<String, Callable<? extends ChannelHandler>> parentHandlers = getChannelHandlers(input);
final LinkedHashMap<String, Callable<? extends ChannelHandler>> childHandlers = getChildChannelHandlers(input);
childEventLoopGroup = eventLoopGroupFactory.create(workerThreads, localRegistry, "workers");
return new ServerBootstrap().group(parentEventLoopGroup, childEventLoopGroup).channelFactory(new ServerSocketChannelFactory(nettyTransportConfiguration.getType())).option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT).option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(8192)).option(ChannelOption.SO_RCVBUF, getRecvBufferSize()).childOption(ChannelOption.SO_RCVBUF, getRecvBufferSize()).childOption(ChannelOption.SO_KEEPALIVE, tcpKeepalive).handler(getChannelInitializer(parentHandlers)).childHandler(getChannelInitializer(childHandlers));
}
use of io.netty.channel.ChannelHandler in project graylog2-server by Graylog2.
the class AbstractTcpTransport method getChildChannelHandlers.
@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getChildChannelHandlers(MessageInput input) {
final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlers = new LinkedHashMap<>();
final CodecAggregator aggregator = getAggregator();
handlers.put("channel-registration", () -> new ChannelRegistrationHandler(childChannels));
handlers.put("traffic-counter", () -> throughputCounter);
handlers.put("connection-counter", () -> connectionCounter);
if (tlsEnable) {
LOG.info("Enabled TLS for input [{}/{}]. key-file=\"{}\" cert-file=\"{}\"", input.getName(), input.getId(), tlsKeyFile, tlsCertFile);
handlers.put("tls", getSslHandlerCallable(input));
}
handlers.putAll(getCustomChildChannelHandlers(input));
if (aggregator != null) {
LOG.debug("Adding codec aggregator {} to channel pipeline", aggregator);
handlers.put("codec-aggregator", () -> new ByteBufMessageAggregationHandler(aggregator, localRegistry));
}
handlers.put("rawmessage-handler", () -> new RawMessageHandler(input));
handlers.put("exception-logger", () -> new ExceptionLoggingChannelHandler(input, LOG, this.tcpKeepalive));
return handlers;
}
use of io.netty.channel.ChannelHandler 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 io.netty.channel.ChannelHandler in project graylog2-server by Graylog2.
the class TcpTransport method getCustomChildChannelHandlers.
@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getCustomChildChannelHandlers(MessageInput input) {
final LinkedHashMap<String, Callable<? extends ChannelHandler>> childChannelHandlers = new LinkedHashMap<>();
childChannelHandlers.put("framer", () -> new LenientDelimiterBasedFrameDecoder(maxFrameLength, delimiter));
childChannelHandlers.putAll(super.getCustomChildChannelHandlers(input));
return childChannelHandlers;
}
use of io.netty.channel.ChannelHandler in project graylog2-server by Graylog2.
the class UdpTransportTest method launchTransportForBootStrapTest.
private UdpTransport launchTransportForBootStrapTest(final ChannelInboundHandler channelHandler) throws MisfireException {
final UdpTransport transport = new UdpTransport(CONFIGURATION, eventLoopGroupFactory, nettyTransportConfiguration, throughputCounter, new LocalMetricRegistry()) {
@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getChannelHandlers(MessageInput input) {
final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlers = new LinkedHashMap<>();
handlers.put("logging", () -> new LoggingHandler(LogLevel.INFO));
handlers.put("counter", () -> channelHandler);
handlers.putAll(super.getChannelHandlers(input));
return handlers;
}
};
final MessageInput messageInput = mock(MessageInput.class);
when(messageInput.getId()).thenReturn("TEST");
when(messageInput.getName()).thenReturn("TEST");
transport.launch(messageInput);
return transport;
}
Aggregations