Search in sources :

Example 11 with ClientBootstrap

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());
}
Also used : NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) NioClientBossPool(org.jboss.netty.channel.socket.nio.NioClientBossPool) NioWorkerPool(org.jboss.netty.channel.socket.nio.NioWorkerPool) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) ExecutorService(java.util.concurrent.ExecutorService) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) DirectChannelBufferFactory(org.jboss.netty.buffer.DirectChannelBufferFactory)

Example 12 with ClientBootstrap

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;
}
Also used : ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap)

Example 13 with ClientBootstrap

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();
            }
        }
    });
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) CountDownLatch(java.util.concurrent.CountDownLatch) ChannelFutureListener(org.jboss.netty.channel.ChannelFutureListener) EndOfStreamException(org.apache.zookeeper.ClientCnxn.EndOfStreamException) IOException(java.io.IOException) SSLContextException(org.apache.zookeeper.common.X509Exception.SSLContextException)

Example 14 with ClientBootstrap

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());
    }
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) InetSocketAddress(java.net.InetSocketAddress)

Example 15 with ClientBootstrap

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());
                }
            });
        }
    });
}
Also used : ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

ClientBootstrap (org.jboss.netty.bootstrap.ClientBootstrap)24 InetSocketAddress (java.net.InetSocketAddress)10 ChannelFuture (org.jboss.netty.channel.ChannelFuture)10 NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)10 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)7 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)7 Channel (org.jboss.netty.channel.Channel)4 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 Map (java.util.Map)2 NioClientBossPool (org.jboss.netty.channel.socket.nio.NioClientBossPool)2 NioWorkerPool (org.jboss.netty.channel.socket.nio.NioWorkerPool)2 HttpClientCodec (org.jboss.netty.handler.codec.http.HttpClientCodec)2 HttpRequestEncoder (org.jboss.netty.handler.codec.http.HttpRequestEncoder)2 HttpResponseDecoder (org.jboss.netty.handler.codec.http.HttpResponseDecoder)2 LoggingHandler (org.jboss.netty.handler.logging.LoggingHandler)2 HashedWheelTimer (org.jboss.netty.util.HashedWheelTimer)2 Checkpoint (com.linkedin.databus.core.Checkpoint)1 FooterAwareHttpChunkAggregator (com.linkedin.databus.core.test.netty.FooterAwareHttpChunkAggregator)1 SimpleHttpResponseHandler (com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler)1