Search in sources :

Example 1 with ListeningIOReactor

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;
}
Also used : IOReactorException(org.apache.http.nio.reactor.IOReactorException) ServerIODispatch(org.apache.synapse.transport.passthru.ServerIODispatch) MultiListenerSSLServerIODispatch(org.apache.synapse.transport.passthru.core.ssl.MultiListenerSSLServerIODispatch) ListeningIOReactor(org.apache.http.nio.reactor.ListeningIOReactor) DefaultListeningIOReactor(org.apache.http.impl.nio.reactor.DefaultListeningIOReactor) MultiListenerSSLServerIODispatch(org.apache.synapse.transport.passthru.core.ssl.MultiListenerSSLServerIODispatch)

Example 2 with ListeningIOReactor

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;
    }
}
Also used : ListenerEndpoint(org.apache.http.nio.reactor.ListenerEndpoint) InetSocketAddress(java.net.InetSocketAddress) ListeningIOReactor(org.apache.http.nio.reactor.ListeningIOReactor) DefaultListeningIOReactor(org.apache.http.impl.nio.reactor.DefaultListeningIOReactor) ListenerEndpoint(org.apache.http.nio.reactor.ListenerEndpoint) IOException(java.io.IOException) IOReactorException(org.apache.http.nio.reactor.IOReactorException)

Example 3 with ListeningIOReactor

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;
}
Also used : ServerIODispatch(org.apache.synapse.transport.passthru.ServerIODispatch) MultiListenerSSLServerIODispatch(org.apache.synapse.transport.passthru.core.ssl.MultiListenerSSLServerIODispatch) ListeningIOReactor(org.apache.http.nio.reactor.ListeningIOReactor) DefaultListeningIOReactor(org.apache.http.impl.nio.reactor.DefaultListeningIOReactor) MultiListenerSSLServerIODispatch(org.apache.synapse.transport.passthru.core.ssl.MultiListenerSSLServerIODispatch)

Example 4 with 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);
    }
}
Also used : ListeningIOReactor(org.apache.http.nio.reactor.ListeningIOReactor) DefaultListeningIOReactor(org.apache.http.impl.nio.reactor.DefaultListeningIOReactor) IOException(java.io.IOException)

Example 5 with 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
 * @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);
    }
}
Also used : ListeningIOReactor(org.apache.http.nio.reactor.ListeningIOReactor) DefaultListeningIOReactor(org.apache.http.impl.nio.reactor.DefaultListeningIOReactor) IOException(java.io.IOException)

Aggregations

DefaultListeningIOReactor (org.apache.http.impl.nio.reactor.DefaultListeningIOReactor)6 ListeningIOReactor (org.apache.http.nio.reactor.ListeningIOReactor)6 IOException (java.io.IOException)3 ServerIODispatch (org.apache.synapse.transport.passthru.ServerIODispatch)3 MultiListenerSSLServerIODispatch (org.apache.synapse.transport.passthru.core.ssl.MultiListenerSSLServerIODispatch)3 IOReactorException (org.apache.http.nio.reactor.IOReactorException)2 InetSocketAddress (java.net.InetSocketAddress)1 ListenerEndpoint (org.apache.http.nio.reactor.ListenerEndpoint)1