use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInitializer 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.ChannelInitializer in project jackrabbit-oak by apache.
the class ForwardHandler method channelActive.
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
group = new NioEventLoopGroup(0, r -> {
return new Thread(r, String.format("forward-handler-%d", threadNumber.getAndIncrement()));
});
Bootstrap b = new Bootstrap().group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
if (flipPosition >= 0) {
ch.pipeline().addLast(new FlipHandler(flipPosition));
}
if (skipBytes > 0) {
ch.pipeline().addLast(new SkipHandler(skipPosition, skipBytes));
}
ch.pipeline().addLast(new BackwardHandler(ctx.channel()));
}
});
remote = b.connect(targetHost, targetPort).sync().channel();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInitializer in project jocean-http by isdom.
the class Nettys4Test method createLocalConnection4Http.
public static Pair<Channel, Channel> createLocalConnection4Http(final String addr) throws Exception {
final BlockingQueue<Channel> serverChannels = new ArrayBlockingQueue<Channel>(1);
final Bootstrap clientbootstrap = new Bootstrap().group(Nettys4Test.EVENTLOOP4CLIENT).channel(LocalChannel.class).handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(final Channel ch) throws Exception {
Nettys.applyHandler(ch.pipeline(), HttpHandlers.LOGGING);
Nettys.applyHandler(ch.pipeline(), HttpHandlers.HTTPCLIENT);
}
}).remoteAddress(new LocalAddress(addr));
final Channel acceptorChannel = new ServerBootstrap().group(EVENTLOOP4BOSS, EVENTLOOP4SERVER).channel(LocalServerChannel.class).childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(final Channel ch) throws Exception {
Nettys.applyHandler(ch.pipeline(), HttpHandlers.LOGGING);
Nettys.applyHandler(ch.pipeline(), HttpHandlers.HTTPSERVER);
serverChannels.offer(ch);
}
}).localAddress(new LocalAddress(addr)).bind().sync().channel();
try {
final Channel client = clientbootstrap.connect().sync().channel();
final Channel server = serverChannels.take();
return Pair.of(client, server);
} finally {
acceptorChannel.close().sync();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInitializer in project LogHub by fbacchella.
the class ClientFactory method addHandlers.
@Override
public void addHandlers(ChannelConsumer<Bootstrap, Channel, SA> source) {
ChannelHandler handler = new ChannelInitializer<CC>() {
@Override
public void initChannel(CC ch) throws Exception {
try {
source.addHandlers(ch.pipeline());
} catch (Exception e) {
logger.error("Netty handler failed: {}", e.getMessage());
logger.throwing(Level.DEBUG, e);
}
}
};
bootstrap.handler(handler);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInitializer in project bgpcep by opendaylight.
the class PCCDispatcherImpl method createClient.
@Override
@SuppressWarnings("unchecked")
public Future<PCEPSession> createClient(final InetSocketAddress remoteAddress, final long reconnectTime, final PCEPSessionListenerFactory listenerFactory, final PCEPSessionNegotiatorFactory negotiatorFactory, final KeyMapping keys, final InetSocketAddress localAddress, final BigInteger dbVersion) {
final Bootstrap b = new Bootstrap();
b.group(this.workerGroup);
b.localAddress(localAddress);
setChannelFactory(b, keys);
b.option(ChannelOption.SO_KEEPALIVE, true);
b.option(ChannelOption.SO_REUSEADDR, true);
b.option(ChannelOption.RCVBUF_ALLOCATOR, new io.netty.channel.FixedRecvByteBufAllocator(1));
final long retryTimer = reconnectTime == -1 ? 0 : reconnectTime;
final PCCReconnectPromise promise = new PCCReconnectPromise(remoteAddress, (int) retryTimer, CONNECT_TIMEOUT, b);
final ChannelInitializer<SocketChannel> channelInitializer = new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(final SocketChannel ch) {
ch.pipeline().addLast(PCCDispatcherImpl.this.factory.getDecoders());
ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(new PCEPSessionNegotiatorFactoryDependencies() {
@Override
public PCEPSessionListenerFactory getListenerFactory() {
return listenerFactory;
}
@Override
public PCEPPeerProposal getPeerProposal() {
return new PCCPeerProposal(dbVersion);
}
}, ch, promise));
ch.pipeline().addLast(PCCDispatcherImpl.this.factory.getEncoders());
ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
@Override
public void channelInactive(final ChannelHandlerContext ctx) {
if (promise.isCancelled()) {
return;
}
if (!promise.isInitialConnectFinished()) {
LOG.debug("Connection to {} was dropped during negotiation, reattempting", remoteAddress);
return;
}
LOG.debug("Reconnecting after connection to {} was dropped", remoteAddress);
PCCDispatcherImpl.this.createClient(remoteAddress, reconnectTime, listenerFactory, negotiatorFactory, keys, localAddress, dbVersion);
}
});
}
};
b.handler(channelInitializer);
promise.connect();
return promise;
}
Aggregations