use of org.apache.synapse.transport.passthru.ServerIODispatch 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.synapse.transport.passthru.ServerIODispatch 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.synapse.transport.passthru.ServerIODispatch 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;
}
use of org.apache.synapse.transport.passthru.ServerIODispatch 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.synapse.transport.passthru.ServerIODispatch in project wso2-synapse by wso2.
the class PassThroughListeningIOReactorManager method pauseIOReactor.
/**
* Pause IO Reactor which is registered by HTTPListener running on given port
*
* @param port Port of axis2 PTT Listener
* @throws IOException Exception throwing when pausing
*/
public void pauseIOReactor(int port) throws IOException {
ListeningIOReactor listeningIOReactor = passThroughListenerIOReactorMapper.get(port);
ServerIODispatch serverIODispatch = passThroughListenerServerIODispatchMapper.get(port);
if (listeningIOReactor != null) {
if (serverIODispatch instanceof MultiListenerServerIODispatch || serverIODispatch instanceof MultiListenerSSLServerIODispatch) {
log.info("Pausing shared IO Reactor bind for port " + port + " will be caused for pausing non " + "axis2 Listeners ");
} else {
log.info("Pausing IO Reactor bind for port " + port);
}
listeningIOReactor.pause();
} else {
log.error("Cannot find Pass Through Listener for port " + port);
}
}
Aggregations