use of org.apache.http.nio.reactor.ListeningIOReactor 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.ListeningIOReactor in project wso2-synapse by wso2.
the class PassThroughListeningIOReactorManager method closeAllPTTListenerEndpoints.
/**
* Close all endpoints started by PTT Listeners.
*
* @param port Port of the Endpoint for PTT axis2 Listener
* @return is all Endpoints closed
*/
public boolean closeAllPTTListenerEndpoints(int port) {
try {
ListeningIOReactor listeningIOReactor = passThroughListenerIOReactorMapper.get(port);
if (listeningIOReactor != null) {
Set<ListenerEndpoint> endpoints = listeningIOReactor.getEndpoints();
// If it is shared IO Reactor then only close endpoints related to PTT Listener
if (passThroughListenerServerIODispatchMapper.get(port) instanceof MultiListenerServerIODispatch) {
for (ListenerEndpoint listenerEndpoint : endpoints) {
if (listenerEndpoint.getAddress() instanceof InetSocketAddress) {
int endPointPort = ((InetSocketAddress) listenerEndpoint.getAddress()).getPort();
if (dynamicPTTListeningEndpointMapper.containsKey(endPointPort)) {
continue;
}
log.info("Closing Endpoint Listener for port " + port);
listenerEndpoint.close();
log.info("Successfully closed Endpoint Listener for port " + port);
}
}
} else {
for (ListenerEndpoint listenerEndpoint : endpoints) {
log.info("Closing Endpoint Listener for port " + port);
listenerEndpoint.close();
log.info("Successfully closed Endpoint Listener for port " + port);
}
}
}
return true;
} catch (Exception e) {
log.error("Error occurred when closing Endpoint in PassThrough Transport Related to port " + port, e);
return false;
}
}
use of org.apache.http.nio.reactor.ListeningIOReactor in project wso2-synapse by wso2.
the class PassThroughListeningIOReactorManager method shutdownReactor.
private ListeningIOReactor shutdownReactor(int port) {
ListeningIOReactor listeningIOReactor = passThroughListenerIOReactorMapper.get(port);
ServerIODispatch serverIODispatch = passThroughListenerServerIODispatchMapper.get(port);
if (listeningIOReactor != null) {
if (serverIODispatch instanceof MultiListenerServerIODispatch || serverIODispatch instanceof MultiListenerSSLServerIODispatch) {
log.info("Shutting down shared IO Reactor bind for port " + port + " will be caused for shutdown non " + "axis2 Listeners ");
} else {
log.info("Shutting down IO Reactor bind for port " + port);
}
} else {
log.error("Cannot find Pass Through Listener for port " + port);
}
return listeningIOReactor;
}
use of org.apache.http.nio.reactor.ListeningIOReactor in project wso2-synapse by wso2.
the class PassThroughListeningIOReactorManager method shutdownIOReactor.
/**
* ShutdownIOReactor which is registered by HTTPListener running on given port
*
* @param port Port of axis2 PTT Listener
* @throws IOException Exception throwing when Shutdown
*/
public void shutdownIOReactor(int port) throws IOException {
ListeningIOReactor ioReactor = shutdownReactor(port);
if (ioReactor != null) {
try {
ioReactor.shutdown();
} catch (IOException e) {
throw new IOException("IOException occurred when shutting down IOReactor for Listener started on port " + port, e);
}
passThroughListenerIOReactorMapper.remove(port);
passThroughListenerServerIODispatchMapper.remove(port);
}
}
use of org.apache.http.nio.reactor.ListeningIOReactor in project wso2-synapse by wso2.
the class PassThroughListeningIOReactorManager method shutdownIOReactor.
/**
* ShutdownIOReactor which is registered by HTTPListener running on given port
*
* @param port Port of axis2 PTT Listener
* @param miliSeconds Waiting Time before close IO Reactor
* @throws IOException Exception throwing when Shutdown
*/
public void shutdownIOReactor(int port, long miliSeconds) throws IOException {
ListeningIOReactor ioReactor = shutdownReactor(port);
if (ioReactor != null) {
try {
ioReactor.shutdown(miliSeconds);
} catch (IOException e) {
throw new IOException("IOException occurred when shutting down IOReactor for Listener started on port " + port, e);
}
passThroughListenerIOReactorMapper.remove(port);
passThroughListenerServerIODispatchMapper.remove(port);
}
}
Aggregations