use of org.jboss.netty.bootstrap.ClientBootstrap in project hadoop by apache.
the class SimpleTcpClient method run.
public void run() {
// Configure the client.
ChannelFactory factory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool(), 1, 1);
ClientBootstrap bootstrap = new ClientBootstrap(factory);
// Set up the pipeline factory.
bootstrap.setPipelineFactory(setPipelineFactory());
bootstrap.setOption("tcpNoDelay", true);
bootstrap.setOption("keepAlive", true);
// Start the connection attempt.
ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));
if (oneShot) {
// Wait until the connection is closed or the connection attempt fails.
future.getChannel().getCloseFuture().awaitUninterruptibly();
// Shut down thread pools to exit.
bootstrap.releaseExternalResources();
}
}
use of org.jboss.netty.bootstrap.ClientBootstrap in project weave by continuuity.
the class SimpleKafkaClient method startUp.
@Override
protected void startUp() throws Exception {
brokerCache.startAndWait();
ThreadFactory threadFactory = Threads.createDaemonThreadFactory("kafka-client-netty-%d");
NioClientBossPool bossPool = new NioClientBossPool(Executors.newSingleThreadExecutor(threadFactory), 1, new HashedWheelTimer(threadFactory), null);
NioWorkerPool workerPool = new NioWorkerPool(Executors.newFixedThreadPool(4, threadFactory), 4);
bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(bossPool, workerPool));
bootstrap.setPipelineFactory(new KafkaChannelPipelineFactory());
connectionPool = new ConnectionPool(bootstrap);
}
use of org.jboss.netty.bootstrap.ClientBootstrap in project dubbo by alibaba.
the class NettyClient method doOpen.
@Override
protected void doOpen() throws Throwable {
NettyHelper.setNettyLoggerFactory();
bootstrap = new ClientBootstrap(channelFactory);
// config
// @see org.jboss.netty.channel.socket.SocketChannelConfig
bootstrap.setOption("keepAlive", true);
bootstrap.setOption("tcpNoDelay", true);
bootstrap.setOption("connectTimeoutMillis", getTimeout());
final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() {
NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyClient.this);
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("decoder", adapter.getDecoder());
pipeline.addLast("encoder", adapter.getEncoder());
pipeline.addLast("handler", nettyHandler);
return pipeline;
}
});
}
use of org.jboss.netty.bootstrap.ClientBootstrap in project databus by linkedin.
the class DummyHttpRequestHandler method setupClient.
private void setupClient() {
_clientBootstrap = new ClientBootstrap(new DefaultLocalClientChannelFactory());
_clientBootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline clientPipeline = pipeline();
clientPipeline.addLast("client logger 1", new LoggingHandler("client logger 1", InternalLogLevel.DEBUG, true));
clientPipeline.addLast("codec", new HttpClientCodec());
clientPipeline.addLast("aggregator", new FooterAwareHttpChunkAggregator(1000000));
_responseHandler = new SimpleHttpResponseHandler();
clientPipeline.addLast("handler", _responseHandler);
clientPipeline.addLast("client logger 5", new LoggingHandler("client logger 5", InternalLogLevel.DEBUG, true));
return clientPipeline;
}
});
}
use of org.jboss.netty.bootstrap.ClientBootstrap in project pinpoint by naver.
the class DefaultPinpointClientFactory method reconnect.
public ChannelFuture reconnect(final SocketAddress remoteAddress) {
if (remoteAddress == null) {
throw new NullPointerException("remoteAddress");
}
ChannelPipeline pipeline;
final ClientBootstrap bootstrap = this.bootstrap;
try {
pipeline = bootstrap.getPipelineFactory().getPipeline();
} catch (Exception e) {
throw new ChannelPipelineException("Failed to initialize a pipeline.", e);
}
PinpointClientHandler pinpointClientHandler = (DefaultPinpointClientHandler) pipeline.getLast();
pinpointClientHandler.initReconnect();
// Set the options.
Channel ch = bootstrap.getFactory().newChannel(pipeline);
boolean success = false;
try {
ch.getConfig().setOptions(bootstrap.getOptions());
success = true;
} finally {
if (!success) {
ch.close();
}
}
// Connect.
return ch.connect(remoteAddress);
}
Aggregations