use of org.apache.http.nio.reactor.IOReactorException in project uavstack by uavorg.
the class HttpAsyncClient method initCloseableHttpAsyncClient.
private CloseableHttpAsyncClient initCloseableHttpAsyncClient(int maxConnectionPerRoute, int maxTotalConnection, int sockTimeout, int connectTimeout, int requestTimeout) {
ConnectingIOReactor ioReactor = null;
try {
ioReactor = new DefaultConnectingIOReactor();
} catch (IOReactorException e) {
// ignore
}
/**
* 增加请求连接的相关超时
*/
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(sockTimeout).setConnectTimeout(connectTimeout).setConnectionRequestTimeout(requestTimeout).build();
if (maxConnectionPerRoute > 0) {
this.maxConnectionPerRoute = maxConnectionPerRoute;
}
if (maxTotalConnection > 0) {
this.maxTotalConnection = maxTotalConnection;
}
PoolingNHttpClientConnectionManager cm = new PoolingNHttpClientConnectionManager(ioReactor);
cm.setDefaultMaxPerRoute(this.maxConnectionPerRoute);
cm.setMaxTotal(this.maxTotalConnection);
return HttpAsyncClients.custom().setDefaultRequestConfig(requestConfig).setConnectionManager(cm).build();
}
use of org.apache.http.nio.reactor.IOReactorException in project wso2-synapse by wso2.
the class PassThroughHttpSender method init.
public void init(ConfigurationContext configurationContext, TransportOutDescription transportOutDescription) throws AxisFault {
log.info("Initializing Pass-through HTTP/S Sender...");
namePrefix = transportOutDescription.getName().toUpperCase(Locale.US);
scheme = getScheme();
WorkerPool workerPool = null;
Object obj = configurationContext.getProperty(PassThroughConstants.PASS_THROUGH_TRANSPORT_WORKER_POOL);
if (obj != null) {
workerPool = (WorkerPool) obj;
}
PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(false, scheme.getName());
TransportView view = new TransportView(null, this, metrics, null);
MBeanRegistrar.getInstance().registerMBean(view, "Transport", "passthru-" + namePrefix.toLowerCase() + "-sender");
proxyConfig = new ProxyConfigBuilder().build(transportOutDescription);
log.info(proxyConfig.logProxyConfig());
targetConfiguration = new TargetConfiguration(configurationContext, transportOutDescription, workerPool, metrics, proxyConfig.createProxyAuthenticator());
targetConfiguration.build();
PassThroughSenderManager.registerPassThroughHttpSender(this);
configurationContext.setProperty(PassThroughConstants.PASS_THROUGH_TRANSPORT_WORKER_POOL, targetConfiguration.getWorkerPool());
ClientConnFactoryBuilder connFactoryBuilder = initConnFactoryBuilder(transportOutDescription);
connFactory = connFactoryBuilder.createConnFactory(targetConfiguration.getHttpParams());
try {
String prefix = namePrefix + "-Sender I/O dispatcher";
ioReactor = new DefaultConnectingIOReactor(targetConfiguration.getIOReactorConfig(), new NativeThreadFactory(new ThreadGroup(prefix + " Thread Group"), prefix));
ioReactor.setExceptionHandler(new IOReactorExceptionHandler() {
public boolean handle(IOException ioException) {
log.warn("System may be unstable: " + namePrefix + " ConnectingIOReactor encountered a checked exception : " + ioException.getMessage(), ioException);
return true;
}
public boolean handle(RuntimeException runtimeException) {
log.warn("System may be unstable: " + namePrefix + " ConnectingIOReactor encountered a runtime exception : " + runtimeException.getMessage(), runtimeException);
return true;
}
});
} catch (IOReactorException e) {
handleException("Error starting " + namePrefix + " ConnectingIOReactor", e);
}
ConnectCallback connectCallback = new ConnectCallback();
targetConnections = new TargetConnections(ioReactor, targetConfiguration, connectCallback);
targetConfiguration.setConnections(targetConnections);
// create the delivery agent to hand over messages
deliveryAgent = new DeliveryAgent(targetConfiguration, targetConnections, proxyConfig);
// we need to set the delivery agent
connectCallback.setDeliveryAgent(deliveryAgent);
handler = new TargetHandler(deliveryAgent, connFactory, targetConfiguration);
ioEventDispatch = new ClientIODispatch(handler, connFactory);
// start the sender in a separate thread
Thread t = new Thread(new Runnable() {
public void run() {
try {
ioReactor.execute(ioEventDispatch);
} catch (Exception ex) {
log.fatal("Exception encountered in the " + namePrefix + " Sender. " + "No more connections will be initiated by this transport", ex);
}
log.info(namePrefix + " Sender shutdown");
}
}, "PassThrough" + namePrefix + "Sender");
t.start();
state = BaseConstants.STARTED;
log.info("Pass-through " + namePrefix + " Sender started...");
}
use of org.apache.http.nio.reactor.IOReactorException in project wso2-synapse by wso2.
the class PassThroughListeningIOReactorManager method initIOReactor.
/**
* Create IOReactor with given configuration
*
* @param port Port of the Endpoint for axis2 Listener
* @param nHttpServerEventHandler Server Handler responsible for handle events of port
* @param passThroughSharedListenerConfiguration configuration related to create and start IOReactor
* @return IOReactor
*/
public ListeningIOReactor initIOReactor(int port, NHttpServerEventHandler nHttpServerEventHandler, PassThroughSharedListenerConfiguration passThroughSharedListenerConfiguration) throws IOReactorException {
ListeningIOReactor defaultListeningIOReactor;
try {
ServerIODispatch serverIODispatch;
// PassThroughListenerConfiguration to be used by Shared IO Reactor
synchronized (this) {
if (this.passThroughListenerConfiguration == null && !passThroughSharedListenerConfiguration.getSourceConfiguration().getScheme().isSSL()) {
this.passThroughListenerConfiguration = passThroughSharedListenerConfiguration;
}
if (this.sslPassThroughListenerConfiguration == null && passThroughSharedListenerConfiguration.getSourceConfiguration().getScheme().isSSL()) {
this.sslPassThroughListenerConfiguration = passThroughSharedListenerConfiguration;
}
}
// If IOReactor is in shared mode and if it is not initialized, initialize it for HTTP Protocol
if (ioReactorSharingMode == IOReactorSharingMode.SHARED && !isSharedIOReactorInitiated.get() && !passThroughSharedListenerConfiguration.getSourceConfiguration().getScheme().isSSL()) {
synchronized (this) {
portServerHandlerMapper.put(port, nHttpServerEventHandler);
serverIODispatch = new MultiListenerServerIODispatch(portServerHandlerMapper, nHttpServerEventHandler, passThroughSharedListenerConfiguration.getServerConnFactory());
// Create IOReactor for Listener make it shareable with Inbounds
defaultListeningIOReactor = createListeningIOReactor(passThroughSharedListenerConfiguration);
log.info("IO Reactor for port " + port + " initiated on shared mode which will be used by non axis2 " + "Transport Listeners ");
sharedListeningIOReactor = defaultListeningIOReactor;
isSharedIOReactorInitiated.compareAndSet(false, true);
}
} else if (ioReactorSharingMode == IOReactorSharingMode.SHARED && !isSharedSSLIOReactorInitiated.get() && passThroughSharedListenerConfiguration.getSourceConfiguration().getScheme().isSSL()) {
synchronized (this) {
serverConnectionFactoryMapper.put(port, passThroughSharedListenerConfiguration.getServerConnFactory());
portServerHandlerMapper.put(port, nHttpServerEventHandler);
serverIODispatch = new MultiListenerSSLServerIODispatch(portServerHandlerMapper, nHttpServerEventHandler, serverConnectionFactoryMapper);
// Create IOReactor for Listener make it shareable with Inbounds
defaultListeningIOReactor = createListeningIOReactor(passThroughSharedListenerConfiguration);
log.info("IO Reactor for port " + port + " initiated on shared mode which will be used by non axis2 " + "Transport SSL Listeners ");
sharedSSLListeningIOReactor = defaultListeningIOReactor;
isSharedSSLIOReactorInitiated.compareAndSet(false, true);
}
} else {
// Create un shareable IOReactors for axis2 Listeners and assign IOReactor Config for later
// create IOReactor for Inbounds
serverIODispatch = new ServerIODispatch(nHttpServerEventHandler, passThroughSharedListenerConfiguration.getServerConnFactory());
defaultListeningIOReactor = createListeningIOReactor(passThroughSharedListenerConfiguration);
}
passThroughListenerServerIODispatchMapper.put(port, serverIODispatch);
passThroughListenerIOReactorMapper.put(port, defaultListeningIOReactor);
} catch (IOReactorException e) {
throw new IOReactorException("Error occurred when trying to init IO Reactor", e);
}
return defaultListeningIOReactor;
}
use of org.apache.http.nio.reactor.IOReactorException in project wso2-synapse by wso2.
the class PassThroughListeningIOReactorManager method getSharedSSLIOReactor.
private ListeningIOReactor getSharedSSLIOReactor(NHttpServerEventHandler nHttpServerEventHandler, String endpointName, int port, SSLConfiguration sslConfiguration) throws Exception {
if (!isSharedSSLIOReactorInitiated.get()) {
if (sslPassThroughListenerConfiguration != null) {
try {
synchronized (this) {
sharedSSLListeningIOReactor = createListeningIOReactor(sslPassThroughListenerConfiguration);
ServerIODispatch serverIODispatch = new MultiListenerSSLServerIODispatch(portServerHandlerMapper, nHttpServerEventHandler, serverConnectionFactoryMapper);
startIOReactor(sharedSSLListeningIOReactor, serverIODispatch, "HTTPS");
isSharedSSLIOReactorInitiated.compareAndSet(false, true);
}
} catch (IOReactorException e) {
throw new IOReactorException("Error occurred when creating shared IO Reactor for non axis2 Listener " + endpointName, e);
}
} else {
throw new Exception("Cannot start Endpoint for" + endpointName + "Axis2 SSL Transport Listeners for PassThrough transport" + " not started correctly or not created the " + "IOReactor Configuration");
}
}
ServerConnFactory serverConnFactory = SSLConnectionUtils.getServerConnectionFactory(endpointName, sslPassThroughListenerConfiguration, sslConfiguration);
if (serverConnectionFactoryMapper.get(port) != null) {
throw new Exception("Cannot create ServerConnectionFactory for " + endpointName + "in port " + port + "already registered a server connection factory ");
} else {
serverConnectionFactoryMapper.put(port, serverConnFactory);
}
return sharedSSLListeningIOReactor;
}
use of org.apache.http.nio.reactor.IOReactorException in project wso2-synapse by wso2.
the class PassThroughListeningIOReactorManager method getSharedIOReactor.
private ListeningIOReactor getSharedIOReactor(NHttpServerEventHandler nHttpServerEventHandler, String endpointName) throws Exception {
if (!isSharedIOReactorInitiated.get()) {
if (passThroughListenerConfiguration != null) {
try {
synchronized (this) {
sharedListeningIOReactor = createListeningIOReactor(passThroughListenerConfiguration);
ServerIODispatch serverIODispatch = new MultiListenerServerIODispatch(portServerHandlerMapper, nHttpServerEventHandler, passThroughListenerConfiguration.getServerConnFactory());
startIOReactor(sharedListeningIOReactor, serverIODispatch, "HTTP");
isSharedIOReactorInitiated.compareAndSet(false, true);
}
} catch (IOReactorException e) {
throw new IOReactorException("Error occurred when creating shared IO Reactor for non axis2 Listener " + endpointName, e);
}
} else {
throw new Exception("Cannot start Endpoint for" + endpointName + "Axis2 Transport Listeners for PassThrough transport" + " not started correctly or not created the " + "IOReactor Configuration");
}
}
return sharedListeningIOReactor;
}
Aggregations