Example usage for org.apache.http.nio.reactor IOReactorException IOReactorException

List of usage examples for org.apache.http.nio.reactor IOReactorException IOReactorException

Introduction

In this page you can find the example usage for org.apache.http.nio.reactor IOReactorException IOReactorException.

Prototype

public IOReactorException(final String message, final Exception cause) 

Source Link

Usage

From source file:org.apache.synapse.transport.passthru.core.PassThroughListeningIOReactorManager.java

/**
 * 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/*from  w w  w  .  j  a  va2 s. c om*/
 */
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;
}

From source file:org.apache.synapse.transport.passthru.core.PassThroughListeningIOReactorManager.java

private ListeningIOReactor getSharedIOReactor(NHttpServerEventHandler nHttpServerEventHandler,
        String endpointName) throws Exception {

    if (!isSharedIOReactorInitiated.get()) {

        if (passThroughListenerConfiguration != null) {
            //create separate IO Reactor for external non axis2 transports and share among them

            try {
                synchronized (this) {
                    sharedListeningIOReactor = createListeningIOReactor(passThroughListenerConfiguration);
                    ServerIODispatch serverIODispatch = new MultiListenerServerIODispatch(
                            portServerHandlerMapper, nHttpServerEventHandler,
                            passThroughListenerConfiguration.getServerConnFactory());
                    startIOReactor(sharedListeningIOReactor, serverIODispatch, "HTTP");
                    isSharedIOReactorInitiated.compareAndSet(false, true);
                }/*from   ww w .ja  va2  s . c o m*/

            } 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;
}

From source file:org.apache.synapse.transport.passthru.core.PassThroughListeningIOReactorManager.java

private ListeningIOReactor getSharedSSLIOReactor(NHttpServerEventHandler nHttpServerEventHandler,
        String endpointName, int port, SSLConfiguration sslConfiguration) throws Exception {

    if (!isSharedSSLIOReactorInitiated.get()) {

        if (sslPassThroughListenerConfiguration != null) {
            //create separate IO Reactor for external non axis2 transports and share among them

            try {
                synchronized (this) {
                    sharedSSLListeningIOReactor = createListeningIOReactor(sslPassThroughListenerConfiguration);
                    ServerIODispatch serverIODispatch = new MultiListenerSSLServerIODispatch(
                            portServerHandlerMapper, nHttpServerEventHandler, serverConnectionFactoryMapper);
                    startIOReactor(sharedSSLListeningIOReactor, serverIODispatch, "HTTPS");
                    isSharedSSLIOReactorInitiated.compareAndSet(false, true);
                }/* ww  w.j a va 2 s  .co m*/

            } 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;
}

From source file:org.apache.synapse.transport.passthru.core.PassThroughListeningIOReactorManager.java

private ListeningIOReactor createListeningIOReactor(
        PassThroughSharedListenerConfiguration passThroughSharedListenerConfiguration)
        throws IOReactorException {
    try {/*from   ww w  .j  a v  a 2  s .  co  m*/
        return new DefaultListeningIOReactor(
                passThroughSharedListenerConfiguration.getSourceConfiguration().getIOReactorConfig(),
                passThroughSharedListenerConfiguration.getThreadFactory());
    } catch (IOReactorException e) {
        throw new IOReactorException(
                "Error creating DefaultListingIOReactor, ioReactorConfig or thread factory may have problems",
                e);
    }
}