use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project java by wavefrontHQ.
the class PushAgent method startOpenTsdbListener.
protected void startOpenTsdbListener(final String strPort) {
if (prefix != null && !prefix.isEmpty()) {
preprocessors.forPort(strPort).forReportPoint().addTransformer(new ReportPointAddPrefixTransformer(prefix));
}
preprocessors.forPort(strPort).forReportPoint().addFilter(new ReportPointTimestampInRangeFilter(dataBackfillCutoffHours, dataPrefillCutoffHours));
final int port = Integer.parseInt(strPort);
final PostPushDataTimedTask[] flushTasks = getFlushTasks(strPort);
ChannelInitializer initializer = new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
final ChannelHandler handler = new OpenTSDBPortUnificationHandler(new OpenTSDBDecoder("unknown", customSourceTags), new PointHandlerImpl(strPort, pushValidationLevel, pushBlockedSamples, flushTasks), preprocessors.forPort(strPort));
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new PlainTextOrHttpFrameDecoder(handler));
}
};
startAsManagedThread(new TcpIngester(initializer, port).withChildChannelOptions(childChannelOptions), "listener-plaintext-opentsdb-" + port);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project java by wavefrontHQ.
the class PushAgent method startCustomListener.
/**
* Registers a custom point handler on a particular port.
*
* @param strPort The port to listen on.
* @param decoder The decoder to use.
* @param pointHandler The handler to handle parsed ReportPoints.
* @param preprocessor Pre-processor (predicates and transform functions) for every point
*/
protected void startCustomListener(String strPort, Decoder<String> decoder, PointHandler pointHandler, @Nullable PointPreprocessor preprocessor) {
int port = Integer.parseInt(strPort);
ChannelHandler channelHandler = new ChannelStringHandler(decoder, pointHandler, preprocessor);
startAsManagedThread(new StringLineIngester(channelHandler, port).withChildChannelOptions(childChannelOptions), null);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project bgpcep by opendaylight.
the class BGPDispatcherImpl method createServerBootstrap.
private synchronized ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer) {
final ServerBootstrap serverBootstrap = new ServerBootstrap();
if (Epoll.isAvailable()) {
serverBootstrap.channel(EpollServerSocketChannel.class);
serverBootstrap.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
} else {
serverBootstrap.channel(NioServerSocketChannel.class);
}
final ChannelHandler serverChannelHandler = BGPChannel.createServerChannelHandler(initializer);
serverBootstrap.childHandler(serverChannelHandler);
serverBootstrap.option(ChannelOption.SO_BACKLOG, SOCKET_BACKLOG_SIZE);
serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, WATER_MARK);
// Make sure we are doing round-robin processing
serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(FIX_BUFFER_SIZE));
if (serverBootstrap.config().group() == null) {
serverBootstrap.group(this.bossGroup, this.workerGroup);
}
return serverBootstrap;
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project incubator-pulsar by apache.
the class ClientCnx method verifyTlsHostName.
/**
* verifies host name provided in x509 Certificate in tls session
*
* it matches hostname with below scenarios
*
* <pre>
* 1. Supports IPV4 and IPV6 host matching
* 2. Supports wild card matching for DNS-name
* eg:
* HostName CN Result
* 1. localhost localhost PASS
* 2. localhost local* PASS
* 3. pulsar1-broker.com pulsar*.com PASS
* </pre>
*
* @param ctx
* @return true if hostname is verified else return false
*/
private boolean verifyTlsHostName(String hostname, ChannelHandlerContext ctx) {
ChannelHandler sslHandler = ctx.channel().pipeline().get("tls");
SSLSession sslSession = null;
if (sslHandler != null) {
sslSession = ((SslHandler) sslHandler).engine().getSession();
if (log.isDebugEnabled()) {
log.debug("Verifying HostName for {}, Cipher {}, Protocols {}", hostname, sslSession.getCipherSuite(), sslSession.getProtocol());
}
return hostnameVerifier.verify(hostname, sslSession);
}
return false;
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project java-driver by datastax.
the class NettyOptionsTest method should_invoke_netty_options_hooks.
private void should_invoke_netty_options_hooks(int hosts, int coreConnections) throws Exception {
NettyOptions nettyOptions = mock(NettyOptions.class, CALLS_REAL_METHODS.get());
EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
Timer timer = new HashedWheelTimer();
doReturn(eventLoopGroup).when(nettyOptions).eventLoopGroup(any(ThreadFactory.class));
doReturn(timer).when(nettyOptions).timer(any(ThreadFactory.class));
final ChannelHandler handler = mock(ChannelHandler.class);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
SocketChannel channel = (SocketChannel) invocation.getArguments()[0];
channel.pipeline().addLast("test-handler", handler);
return null;
}
}).when(nettyOptions).afterChannelInitialized(any(SocketChannel.class));
Cluster cluster = register(Cluster.builder().addContactPoints(getContactPoints().get(0)).withPort(ccm().getBinaryPort()).withPoolingOptions(new PoolingOptions().setConnectionsPerHost(HostDistance.LOCAL, coreConnections, coreConnections)).withNettyOptions(nettyOptions).build());
// when
// force session creation to populate pools
cluster.connect();
int expectedNumberOfCalls = TestUtils.numberOfLocalCoreConnections(cluster) * hosts + 1;
// If the driver supports a more recent protocol version than C*, the negotiation at startup
// will open an additional connection for each protocol version tried.
ProtocolVersion version = ProtocolVersion.NEWEST_SUPPORTED;
ProtocolVersion usedVersion = ccm().getProtocolVersion();
while (version != usedVersion && version != null) {
version = version.getLowerSupported();
expectedNumberOfCalls++;
}
cluster.close();
// then
verify(nettyOptions, times(1)).eventLoopGroup(any(ThreadFactory.class));
verify(nettyOptions, times(1)).channelClass();
verify(nettyOptions, times(1)).timer(any(ThreadFactory.class));
// per-connection hooks will be called coreConnections * hosts + 1 times:
// the extra call is for the control connection
verify(nettyOptions, times(expectedNumberOfCalls)).afterBootstrapInitialized(any(Bootstrap.class));
verify(nettyOptions, times(expectedNumberOfCalls)).afterChannelInitialized(any(SocketChannel.class));
verify(handler, times(expectedNumberOfCalls)).handlerAdded(any(ChannelHandlerContext.class));
verify(handler, times(expectedNumberOfCalls)).handlerRemoved(any(ChannelHandlerContext.class));
verify(nettyOptions, times(1)).onClusterClose(eventLoopGroup);
verify(nettyOptions, times(1)).onClusterClose(timer);
verifyNoMoreInteractions(nettyOptions);
}
Aggregations