use of org.jboss.netty.bootstrap.ClientBootstrap in project cdap by caskdata.
the class NettyRouter method bootstrapClient.
private void bootstrapClient(final ChannelUpstreamHandler connectionTracker) {
ExecutorService clientBossExecutor = createExecutorService(clientBossThreadPoolSize, "router-client-boss-thread-%d");
ExecutorService clientWorkerExecutor = createExecutorService(clientWorkerThreadPoolSize, "router-client-worker-thread-%d");
clientBootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(new NioClientBossPool(clientBossExecutor, clientBossThreadPoolSize), new NioWorkerPool(clientWorkerExecutor, clientWorkerThreadPoolSize)));
ChannelPipelineFactory pipelineFactory = new ClientChannelPipelineFactory(connectionTracker, connectionTimeout, timer);
clientBootstrap.setPipelineFactory(pipelineFactory);
clientBootstrap.setOption("bufferFactory", new DirectChannelBufferFactory());
}
use of org.jboss.netty.bootstrap.ClientBootstrap in project storm by apache.
the class Client method createClientBootstrap.
private ClientBootstrap createClientBootstrap(ChannelFactory factory, int bufferSize, Map stormConf) {
ClientBootstrap bootstrap = new ClientBootstrap(factory);
bootstrap.setOption("tcpNoDelay", true);
bootstrap.setOption("sendBufferSize", bufferSize);
bootstrap.setOption("keepAlive", true);
bootstrap.setPipelineFactory(new StormClientPipelineFactory(this, stormConf));
return bootstrap;
}
use of org.jboss.netty.bootstrap.ClientBootstrap in project zookeeper by apache.
the class ClientCnxnSocketNetty method connect.
@Override
void connect(InetSocketAddress addr) throws IOException {
firstConnect = new CountDownLatch(1);
ClientBootstrap bootstrap = new ClientBootstrap(channelFactory);
bootstrap.setPipelineFactory(new ZKClientPipelineFactory());
bootstrap.setOption("soLinger", -1);
bootstrap.setOption("tcpNoDelay", true);
connectFuture = bootstrap.connect(addr);
connectFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
// this lock guarantees that channel won't be assgined after cleanup().
connectLock.lock();
try {
if (!channelFuture.isSuccess() || connectFuture == null) {
LOG.info("future isn't success, cause: {}", channelFuture.getCause());
return;
}
// setup channel, variables, connection, etc.
channel = channelFuture.getChannel();
disconnected.set(false);
initialized = false;
lenBuffer.clear();
incomingBuffer = lenBuffer;
sendThread.primeConnection();
updateNow();
updateLastSendAndHeard();
if (sendThread.tunnelAuthInProgress()) {
waitSasl.drainPermits();
needSasl.set(true);
sendPrimePacket();
} else {
needSasl.set(false);
}
// we need to wake up on first connect to avoid timeout.
wakeupCnxn();
firstConnect.countDown();
LOG.info("channel is connected: {}", channelFuture.getChannel());
} finally {
connectLock.unlock();
}
}
});
}
use of org.jboss.netty.bootstrap.ClientBootstrap in project bigbluebutton by bigbluebutton.
the class Client method connect.
/**
* Attempt to establish an authenticated connection to the nominated FreeSWITCH ESL server socket.
* This call will block, waiting for an authentication handshake to occur, or timeout after the
* supplied number of seconds.
*
* @param host can be either ip address or hostname
* @param port tcp port that server socket is listening on (set in event_socket_conf.xml)
* @param password server event socket is expecting (set in event_socket_conf.xml)
* @param timeoutSeconds number of seconds to wait for the server socket before aborting
*/
public void connect(String host, int port, String password, int timeoutSeconds) throws InboundConnectionFailure {
// If already connected, disconnect first
if (canSend()) {
close();
}
// Configure this client
ClientBootstrap bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
// Add ESL handler and factory
InboundClientHandler handler = new InboundClientHandler(password, protocolListener);
bootstrap.setPipelineFactory(new InboundPipelineFactory(handler));
// Attempt connection
ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));
// Wait till attempt succeeds, fails or timeouts
if (!future.awaitUninterruptibly(timeoutSeconds, TimeUnit.SECONDS)) {
throw new InboundConnectionFailure("Timeout connecting to " + host + ":" + port);
}
// Did not timeout
channel = future.getChannel();
// But may have failed anyway
if (!future.isSuccess()) {
log.warn("Failed to connect to [{}:{}]", host, port);
log.warn(" * reason: {}", future.getCause());
channel = null;
bootstrap.releaseExternalResources();
throw new InboundConnectionFailure("Could not connect to " + host + ":" + port, future.getCause());
}
// Wait for the authentication handshake to call back
while (!authenticatorResponded.get()) {
try {
Thread.sleep(250);
} catch (InterruptedException e) {
// ignore
}
}
if (!authenticated) {
throw new InboundConnectionFailure("Authentication failed: " + authenticationResponse.getReplyText());
}
}
use of org.jboss.netty.bootstrap.ClientBootstrap in project http-client by biasedbit.
the class DefaultHttpClient method openConnection.
private void openConnection(final HostController controller) {
// No need to recheck whether a connection can be opened or not, that was done already inside the HttpContext.
// Try to create a pipeline before signalling a new connection is being open.
// This should never throw exceptions but who knows...
final ChannelPipeline pipeline = createChannelPipeline();
// Signal that a new connection is opening.
controller.connectionOpening();
// server:port-X
String id = new StringBuilder().append(hostId(controller)).append("-").append(connectionCounter++).toString();
// If not using NIO, then delegate the blocking write() call to the executor.
Executor writeDelegator = useNio ? null : executor;
final Connection connection = connectionFactory.createConnection(id, controller.getHost(), controller.getPort(), this, timeoutController, writeDelegator);
pipeline.addLast("handler", connection);
// Delegate actual connection to other thread, since calling connect is a blocking call.
executor.execute(new Runnable() {
@Override
public void run() {
ClientBootstrap bootstrap = new ClientBootstrap(channelFactory);
bootstrap.setOption("reuseAddress", true);
bootstrap.setOption("connectTimeoutMillis", connectionTimeout);
bootstrap.setPipeline(pipeline);
InetSocketAddress address = new InetSocketAddress(controller.getHost(), controller.getPort());
ChannelFuture future = bootstrap.connect(address);
future.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess())
channelGroup.add(future.getChannel());
}
});
}
});
}
Aggregations