use of com.wavefront.agent.channel.IdleStateEventHandler in project java by wavefrontHQ.
the class ProxyUtil method createInitializer.
/**
* Create a {@link ChannelInitializer} with multiple dynamically created
* {@link ChannelHandler} objects.
*
* @param channelHandlerSuppliers Suppliers of ChannelHandlers.
* @param port port number.
* @param idleTimeout idle timeout in seconds.
* @param sslContext SSL context.
* @return channel initializer
*/
static ChannelInitializer<SocketChannel> createInitializer(Iterable<Supplier<ChannelHandler>> channelHandlerSuppliers, int port, int idleTimeout, @Nullable SslContext sslContext) {
String strPort = String.valueOf(port);
ChannelHandler idleStateEventHandler = new IdleStateEventHandler(Metrics.newCounter(new TaggedMetricName("listeners", "connections.idle.closed", "port", strPort)));
ChannelHandler connectionTracker = new ConnectionTrackingHandler(Metrics.newCounter(new TaggedMetricName("listeners", "connections.accepted", "port", strPort)), Metrics.newCounter(new TaggedMetricName("listeners", "connections.active", "port", strPort)));
if (sslContext != null) {
logger.info("TLS enabled on port: " + port);
}
return new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
if (sslContext != null) {
pipeline.addLast(sslContext.newHandler(ch.alloc()));
}
pipeline.addFirst("idlehandler", new IdleStateHandler(idleTimeout, 0, 0));
pipeline.addLast("idlestateeventhandler", idleStateEventHandler);
pipeline.addLast("connectiontracker", connectionTracker);
channelHandlerSuppliers.forEach(x -> pipeline.addLast(x.get()));
}
};
}
Aggregations