Java Code Examples for org.apache.http.impl.nio.reactor.IOReactorConfig#Builder

The following examples show how to use org.apache.http.impl.nio.reactor.IOReactorConfig#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InboundHL7IOReactor.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private static IOReactorConfig getDefaultReactorConfig() {
    IOReactorConfig.Builder builder = IOReactorConfig.custom();

    return builder.setSelectInterval(
            HL7Configuration.getInstance().getIntProperty(MLLPConstants.TCPConstants.SELECT_INTERVAL, 1000))
            .setShutdownGracePeriod(HL7Configuration.getInstance()
                                            .getIntProperty(MLLPConstants.TCPConstants.SHUTDOWN_GRACE_PERIOD, 500))
            .setIoThreadCount(HL7Configuration.getInstance()
                                      .getIntProperty(MLLPConstants.TCPConstants.IO_THREAD_COUNT,
                                                      Runtime.getRuntime().availableProcessors()))
            .setSoTimeout(HL7Configuration.getInstance().getIntProperty(MLLPConstants.TCPConstants.SO_TIMEOUT, 0))
            .setSoKeepAlive(HL7Configuration.getInstance()
                                    .getBooleanProperty(MLLPConstants.TCPConstants.SO_KEEP_ALIVE, true))
            .setTcpNoDelay(HL7Configuration.getInstance()
                                   .getBooleanProperty(MLLPConstants.TCPConstants.TCP_NO_DELAY, true))
            .setConnectTimeout(
                    HL7Configuration.getInstance().getIntProperty(MLLPConstants.TCPConstants.CONNECT_TIMEOUT, 0))
            .setRcvBufSize(HL7Configuration.getInstance().getIntProperty(MLLPConstants.TCPConstants.SO_RCVBUF, 0))
            .setSndBufSize(HL7Configuration.getInstance().getIntProperty(MLLPConstants.TCPConstants.SO_SNDBUF, 0))
            .setInterestOpQueued(false).setSoReuseAddress(true).setSoLinger(-1).build();
}
 
Example 2
Source File: RestClient.java    From light with Apache License 2.0 5 votes vote down vote up
private ConnectingIOReactor ioReactor() throws Exception {
    // Create I/O reactor configuration
    Map<String, Object> asyncRestTemplateMap = (Map)configMap.get(ASYNC_REST_TEMPLATE);
    Map<String, Object> reactorMap = (Map)asyncRestTemplateMap.get(REACTOR);
    Integer ioThreadCount = (Integer)reactorMap.get(REACTOR_IO_THREAD_COUNT);
    IOReactorConfig.Builder builder = IOReactorConfig.custom();
    builder.setIoThreadCount(ioThreadCount == null? Runtime.getRuntime().availableProcessors(): ioThreadCount);
    Integer connectTimeout = (Integer)reactorMap.get(REACTOR_CONNECT_TIMEOUT);
    builder.setConnectTimeout(connectTimeout == null? DEFAULT_REACTOR_CONNECT_TIMEOUT: connectTimeout);
    Integer soTimeout = (Integer)reactorMap.get(REACTOR_SO_TIMEOUT);
    builder.setSoTimeout(soTimeout == null? DEFAULT_REACTOR_SO_TIMEOUT: soTimeout);
    IOReactorConfig ioReactorConfig = builder.build();
    return new DefaultConnectingIOReactor(ioReactorConfig);
}
 
Example 3
Source File: JsonRpcHttpAsyncClient.java    From jsonrpc4j with MIT License 5 votes vote down vote up
private void initialize() {
	if (initialized.getAndSet(true)) {
		return;
	}
	IOReactorConfig.Builder config = createConfig();
	// params.setParameter(CoreProtocolPNames.USER_AGENT, "jsonrpc4j/1.0");
	final ConnectingIOReactor ioReactor = createIoReactor(config);
	createSslContext();
	int socketBufferSize = Integer.getInteger("com.googlecode.jsonrpc4j.async.socket.buffer", 8 * 1024);
	final ConnectionConfig connectionConfig = ConnectionConfig.custom().setBufferSize(socketBufferSize).build();
	BasicNIOConnFactory nioConnFactory = new BasicNIOConnFactory(sslContext, null, connectionConfig);
	pool = new BasicNIOConnPool(ioReactor, nioConnFactory, Integer.getInteger("com.googlecode.jsonrpc4j.async.connect.timeout", 30000));
	pool.setDefaultMaxPerRoute(Integer.getInteger("com.googlecode.jsonrpc4j.async.max.inflight.route", 500));
	pool.setMaxTotal(Integer.getInteger("com.googlecode.jsonrpc4j.async.max.inflight.total", 500));
	
	Thread t = new Thread(new Runnable() {
		@Override
		public void run() {
			try {
				HttpAsyncRequestExecutor protocolHandler = new HttpAsyncRequestExecutor();
				IOEventDispatch ioEventDispatch = new DefaultHttpClientIODispatch(protocolHandler, sslContext, connectionConfig);
				ioReactor.execute(ioEventDispatch);
			} catch (InterruptedIOException ex) {
				System.err.println("Interrupted");
			} catch (IOException e) {
				System.err.println("I/O error: " + e.getMessage());
			}
		}
	}, "jsonrpc4j HTTP IOReactor");
	
	t.setDaemon(true);
	t.start();
	
	HttpProcessor httpProcessor = new ImmutableHttpProcessor(new RequestContent(), new RequestTargetHost(), new RequestConnControl(), new RequestUserAgent(), new RequestExpectContinue(false));
	requester = new HttpAsyncRequester(httpProcessor, new DefaultConnectionReuseStrategy());
}
 
Example 4
Source File: JsonRpcHttpAsyncClient.java    From jsonrpc4j with MIT License 5 votes vote down vote up
private IOReactorConfig.Builder createConfig() {
	IOReactorConfig.Builder config = IOReactorConfig.custom();
	config = config.setSoTimeout(Integer.getInteger("com.googlecode.jsonrpc4j.async.socket.timeout", 30000));
	config = config.setConnectTimeout(Integer.getInteger("com.googlecode.jsonrpc4j.async.connect.timeout", 30000));
	config = config.setTcpNoDelay(Boolean.valueOf(System.getProperty("com.googlecode.jsonrpc4j.async.tcp.nodelay", "true")));
	config = config.setIoThreadCount(Integer.getInteger("com.googlecode.jsonrpc4j.async.reactor.threads", 1));
	return config;
}