use of org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory in project http-client by biasedbit.
the class DefaultHttpClient method init.
// HttpClient -----------------------------------------------------------------------------------------------------
@Override
public boolean init() {
if (timeoutController == null) {
// prefer lower resources consumption over precision
timeoutController = new HashedWheelTimeoutController();
timeoutController.init();
internalTimeoutManager = true;
}
if (connectionFactory == null)
connectionFactory = new DefaultConnectionFactory();
if ((sslContextFactory == null) && isHttps())
sslContextFactory = BogusSslContextFactory.getInstance();
eventConsumerLatch = new CountDownLatch(1);
eventQueue = new LinkedBlockingQueue<>();
// TODO instead of fixed size thread pool, use a cached thread pool with size limit (limited growth cached pool)
executor = Executors.newFixedThreadPool(maxHelperThreads, new NamedThreadFactory("httpHelpers"));
Executor workerPool = Executors.newFixedThreadPool(maxIoWorkerThreads, new NamedThreadFactory("httpWorkers"));
if (useNio) {
// It's only going to create 1 thread, so no harm done here.
Executor bossPool = Executors.newCachedThreadPool();
channelFactory = new NioClientSocketChannelFactory(bossPool, workerPool);
} else {
channelFactory = new OioClientSocketChannelFactory(workerPool);
}
channelGroup = new CleanupChannelGroup(toString());
// Create a pipeline without the last handler (it will be added right before connecting).
pipelineFactory = new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
if (useSsl) {
SSLEngine engine = sslContextFactory.getClientContext().createSSLEngine();
engine.setUseClientMode(true);
pipeline.addLast("ssl", new SslHandler(engine));
}
pipeline.addLast("codec", new HttpClientCodec());
if (autoDecompress)
pipeline.addLast("decompressor", new HttpContentDecompressor());
return pipeline;
}
};
executor.execute(new Runnable() {
@Override
public void run() {
eventHandlingLoop();
}
});
return true;
}
Aggregations