use of org.apache.flink.shaded.netty4.io.netty.bootstrap.Bootstrap 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;
}
use of org.apache.flink.shaded.netty4.io.netty.bootstrap.Bootstrap in project UnderNet by itsMatoosh.
the class Client method connect.
/**
* Connects the client to a node.
*/
public void connect(Node node) {
if (status == InterfaceStatus.STOPPING) {
logger.error("Can't connect to nodes, while the client is stopping!");
return;
}
if (status != InterfaceStatus.STARTED) {
EventManager.callEvent(new ClientStatusEvent(this, InterfaceStatus.STARTED));
}
logger.info("Connecting to node: " + node.address);
// Making sure the list of client futures exists.
if (closeFutures == null) {
closeFutures = new ArrayList<>();
}
// Starting the client.
Bootstrap clientBootstrap = new Bootstrap();
// Assigning the channel to the client event loop group.
clientBootstrap.group(workerEventLoopGroup);
// Using the non blocking io.
clientBootstrap.channel(NioSocketChannel.class);
// Making sure the connection is sending the keep alive signal.
clientBootstrap.option(ChannelOption.SO_KEEPALIVE, true);
clientBootstrap.handler(new ClientChannelInitializer(this));
// Connecting
// Connecting to the node.
ChannelFuture future = clientBootstrap.connect(node.address);
ChannelFuture closeFuture = future.channel().closeFuture();
closeFuture.addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
// Removing the future from future list.
closeFutures.remove(future);
if (closeFutures.size() == 0) {
// Stopping the worker group.
EventManager.callEvent(new ClientStatusEvent(Client.this, InterfaceStatus.STOPPED));
}
}
});
closeFutures.add(closeFuture);
}
use of org.apache.flink.shaded.netty4.io.netty.bootstrap.Bootstrap in project runelite by runelite.
the class CacheClient method connect.
public void connect() {
Bootstrap b = new Bootstrap();
b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true).handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
// p.addFirst(new HttpProxyHandler(new InetSocketAddress("runelite.net", 3128)));
p.addLast("decoder", new HandshakeResponseDecoder());
p.addLast(new CacheClientHandler(), new HandshakeResponseHandler(CacheClient.this), new ArchiveResponseHandler(CacheClient.this));
p.addLast(new UpdateHandshakeEncoder(), new EncryptionEncoder(), new ArchiveRequestEncoder());
}
});
// Start the client.
ChannelFuture f = b.connect(host, PORT).syncUninterruptibly();
channel = f.channel();
}
use of org.apache.flink.shaded.netty4.io.netty.bootstrap.Bootstrap in project scalecube by scalecube.
the class TransportImpl method connect.
private ChannelFuture connect(Address address) {
OutgoingChannelInitializer channelInitializer = new OutgoingChannelInitializer(address);
Bootstrap client = bootstrapFactory.clientBootstrap().handler(channelInitializer);
ChannelFuture connectFuture = client.connect(address.host(), address.port());
// Register logger and cleanup listener
connectFuture.addListener((ChannelFutureListener) channelFuture -> {
if (channelFuture.isSuccess()) {
LOGGER.debug("Connected from {} to {}: {}", TransportImpl.this.address, address, channelFuture.channel());
} else {
LOGGER.warn("Failed to connect from {} to {}", TransportImpl.this.address, address);
outgoingChannels.remove(address);
}
});
return connectFuture;
}
use of org.apache.flink.shaded.netty4.io.netty.bootstrap.Bootstrap in project scalecube by scalecube.
the class StreamProcessorsTest method testClientStreamProcessorsNotSameAfterSetup.
@Test
public void testClientStreamProcessorsNotSameAfterSetup() {
ClientStreamProcessors defaultOne = StreamProcessors.newClient();
// client with bootstrap
ClientStreamProcessors first = defaultOne.bootstrap(new Bootstrap());
// another client with custom bootstrap
ClientStreamProcessors second = defaultOne.bootstrap(new Bootstrap());
assertNotSame(defaultOne, first);
assertNotSame(defaultOne, second);
assertNotSame(first, second);
}
Aggregations