use of org.apache.http.impl.nio.reactor.IOReactorConfig in project jmeter by apache.
the class HttpMetricsSender method setup.
/**
* The HTTP API is the primary means of writing data into InfluxDB, by
* sending POST requests to the /write endpoint. Initiate the HttpClient
* client with a HttpPost request from influxdb url
*
* @param influxdbUrl example : http://localhost:8086/write?db=myd&rp=one_week
* @param influxDBToken example: my-token
* @see InfluxdbMetricsSender#setup(String, String)
*/
@Override
public void setup(String influxdbUrl, String influxDBToken) throws Exception {
// Create I/O reactor configuration
IOReactorConfig ioReactorConfig = IOReactorConfig.custom().setIoThreadCount(1).setConnectTimeout(JMeterUtils.getPropDefault("backend_influxdb.connection_timeout", 1000)).setSoTimeout(JMeterUtils.getPropDefault("backend_influxdb.socket_timeout", 3000)).build();
// Create a custom I/O reactor
ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(ioReactorConfig);
// Create a connection manager with custom configuration.
PoolingNHttpClientConnectionManager connManager = new PoolingNHttpClientConnectionManager(ioReactor);
httpClient = HttpAsyncClientBuilder.create().setConnectionManager(connManager).setMaxConnPerRoute(2).setMaxConnTotal(2).setUserAgent("ApacheJMeter" + JMeterUtils.getJMeterVersion()).disableCookieManagement().disableConnectionState().build();
url = new URL(influxdbUrl);
token = influxDBToken;
httpRequest = createRequest(url, token);
httpClient.start();
}
use of org.apache.http.impl.nio.reactor.IOReactorConfig in project cxf by apache.
the class AsyncHTTPConduitFactory method setupNIOClient.
public synchronized void setupNIOClient(HTTPClientPolicy clientPolicy) throws IOReactorException {
if (client != null) {
return;
}
IOReactorConfig config = IOReactorConfig.custom().setIoThreadCount(ioThreadCount).setSelectInterval(selectInterval).setInterestOpQueued(interestOpQueued).setSoLinger(soLinger).setSoTimeout(soTimeout).setSoKeepAlive(soKeepalive).setTcpNoDelay(tcpNoDelay).build();
Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry = RegistryBuilder.<SchemeIOSessionStrategy>create().register("http", NoopIOSessionStrategy.INSTANCE).register("https", SSLIOSessionStrategy.getSystemDefaultStrategy()).build();
ManagedNHttpClientConnectionFactory connectionFactory = new ManagedNHttpClientConnectionFactory();
DefaultConnectingIOReactor ioreactor = new DefaultConnectingIOReactor(config);
connectionManager = new PoolingNHttpClientConnectionManager(ioreactor, connectionFactory, ioSessionFactoryRegistry, DefaultSchemePortResolver.INSTANCE, SystemDefaultDnsResolver.INSTANCE, connectionTTL, TimeUnit.MILLISECONDS);
connectionManager.setDefaultMaxPerRoute(maxPerRoute);
connectionManager.setMaxTotal(maxConnections);
ConnectionConfig connectionConfig = ConnectionConfig.custom().setBufferSize(clientPolicy.getChunkLength() > 0 ? clientPolicy.getChunkLength() : 16332).build();
connectionManager.setDefaultConnectionConfig(connectionConfig);
RedirectStrategy redirectStrategy = new RedirectStrategy() {
public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
return false;
}
public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
return null;
}
};
HttpAsyncClientBuilder httpAsyncClientBuilder = HttpAsyncClients.custom().setConnectionManager(connectionManager).setRedirectStrategy(redirectStrategy).setDefaultCookieStore(new BasicCookieStore() {
private static final long serialVersionUID = 1L;
public void addCookie(Cookie cookie) {
}
});
adaptClientBuilder(httpAsyncClientBuilder);
client = httpAsyncClientBuilder.build();
// Start the client thread
client.start();
// Always start the idle checker thread to validate pending requests and
// use the ConnectionMaxIdle to close the idle connection
new CloseIdleConnectionThread(connectionManager, client).start();
}
use of org.apache.http.impl.nio.reactor.IOReactorConfig in project wso2-synapse by wso2.
the class BaseConfigurationTest method testBuildIOReactorConfig.
@Test
public void testBuildIOReactorConfig() throws Exception {
IOReactorConfig config = baseConfiguration.buildIOReactorConfig();
int expectedIOThreadCount = Runtime.getRuntime().availableProcessors();
Assert.assertNotNull("I/O Reactor hasn't been initialized.", config);
Assert.assertEquals("I/O reactor thread count isn't correct.", expectedIOThreadCount, config.getIoThreadCount());
}
use of org.apache.http.impl.nio.reactor.IOReactorConfig in project wso2-synapse by wso2.
the class SourceConfigurationTest method testGetIOReactorConfig.
@Test
public void testGetIOReactorConfig() throws Exception {
IOReactorConfig config = sourceConfiguration.getIOReactorConfig();
int expectedIOThreadCount = Runtime.getRuntime().availableProcessors();
Assert.assertNotNull("I/O Reactor hasn't been initialized.", config);
Assert.assertEquals("I/O reactor thread count isn't correct.", expectedIOThreadCount, config.getIoThreadCount());
}
use of org.apache.http.impl.nio.reactor.IOReactorConfig in project wso2-synapse by wso2.
the class HttpCoreNIOSender method init.
/**
* Initialize the transport sender, and execute reactor in new separate thread
* @param cfgCtx the Axis2 configuration context
* @param transportOut the description of the http/s transport from Axis2 configuration
* @throws AxisFault thrown on an error
*/
public void init(ConfigurationContext cfgCtx, TransportOutDescription transportOut) throws AxisFault {
this.configurationContext = cfgCtx;
cfg = NHttpConfiguration.getInstance();
params = new BasicHttpParams();
params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, cfg.getProperty(NhttpConstants.SO_TIMEOUT_SENDER, 60000)).setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, cfg.getProperty(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000)).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, cfg.getProperty(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)).setParameter(CoreProtocolPNames.USER_AGENT, "Synapse-HttpComponents-NIO");
// .setParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET,
// cfg.getStringValue(CoreProtocolPNames.HTTP_ELEMENT_CHARSET,HTTP.DEFAULT_PROTOCOL_CHARSET)); //TODO:This does not works with HTTPCore 4.3
name = transportOut.getName().toUpperCase(Locale.US) + " Sender";
ClientConnFactoryBuilder contextBuilder = initConnFactoryBuilder(transportOut, cfgCtx);
connFactory = contextBuilder.createConnFactory(params);
connpool = new ConnectionPool();
proxyConfig = new ProxyConfigBuilder().build(transportOut);
if (log.isDebugEnabled()) {
log.debug(proxyConfig.logProxyConfig());
}
Parameter param = transportOut.getParameter("warnOnHTTP500");
if (param != null) {
String[] warnOnHttp500 = ((String) param.getValue()).split("\\|");
cfgCtx.setNonReplicableProperty("warnOnHTTP500", warnOnHttp500);
}
IOReactorConfig ioReactorConfig = new IOReactorConfig();
ioReactorConfig.setIoThreadCount(NHttpConfiguration.getInstance().getClientIOWorkers());
ioReactorConfig.setSoTimeout(cfg.getProperty(NhttpConstants.SO_TIMEOUT_RECEIVER, 60000));
ioReactorConfig.setConnectTimeout(cfg.getProperty(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000));
ioReactorConfig.setTcpNoDelay(cfg.getProperty(CoreConnectionPNames.TCP_NODELAY, 1) == 1);
if (cfg.getBooleanValue("http.nio.interest-ops-queueing", false)) {
ioReactorConfig.setInterestOpQueued(true);
}
try {
String prefix = name + " I/O dispatcher";
ioReactor = new DefaultConnectingIOReactor(ioReactorConfig, new NativeThreadFactory(new ThreadGroup(prefix + " thread group"), prefix));
ioReactor.setExceptionHandler(new IOReactorExceptionHandler() {
public boolean handle(IOException ioException) {
log.warn("System may be unstable: IOReactor encountered a checked exception : " + ioException.getMessage(), ioException);
return true;
}
public boolean handle(RuntimeException runtimeException) {
log.warn("System may be unstable: IOReactor encountered a runtime exception : " + runtimeException.getMessage(), runtimeException);
return true;
}
});
} catch (IOException e) {
log.error("Error starting the IOReactor", e);
throw new AxisFault(e.getMessage(), e);
}
metrics = new NhttpMetricsCollector(false, transportOut.getName());
handler = new ClientHandler(connpool, connFactory, proxyConfig, cfgCtx, params, metrics);
iodispatch = new ClientIODispatch(handler, connFactory);
final IOEventDispatch ioEventDispatch = iodispatch;
// start the Sender in a new seperate thread
Thread t = new Thread(new Runnable() {
public void run() {
try {
ioReactor.execute(ioEventDispatch);
} catch (InterruptedIOException ex) {
log.fatal("Reactor Interrupted");
} catch (IOException e) {
log.fatal("Encountered an I/O error: " + e.getMessage(), e);
}
log.info(name + " Shutdown");
}
}, "HttpCoreNIOSender");
t.start();
log.info(name + " starting");
// register with JMX
mbeanSupport = new TransportMBeanSupport(this, "nio-" + transportOut.getName());
mbeanSupport.register();
state = BaseConstants.STARTED;
}
Aggregations