Search in sources :

Example 1 with ListenerEndpoint

use of org.apache.http.nio.reactor.ListenerEndpoint in project wso2-synapse by wso2.

the class HttpCoreNIOListener method startSpecificEndpoints.

/**
 * Start specific end points given by InetSockeAddress list
 *
 * @param endpointsClosed InetSocketAddresses of endpoints to be started
 * @throws AxisFault
 */
private void startSpecificEndpoints(List<InetSocketAddress> endpointsClosed) throws AxisFault {
    Queue<ListenerEndpoint> endpoints = new LinkedList<ListenerEndpoint>();
    // Ensure simple but stable order
    List<InetSocketAddress> addressList = endpointsClosed;
    Collections.sort(addressList, new Comparator<InetSocketAddress>() {

        public int compare(InetSocketAddress a1, InetSocketAddress a2) {
            String s1 = a1.toString();
            String s2 = a2.toString();
            return s1.compareTo(s2);
        }
    });
    for (InetSocketAddress address : addressList) {
        endpoints.add(ioReactor.listen(address));
    }
    // requests.
    while (!endpoints.isEmpty()) {
        ListenerEndpoint endpoint = endpoints.remove();
        try {
            endpoint.waitFor();
            if (log.isInfoEnabled()) {
                InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
                if (!address.isUnresolved()) {
                    log.info(name + " started on " + address.getHostName() + ":" + address.getPort());
                } else {
                    log.info(name + " started on " + address);
                }
            }
        } catch (InterruptedException e) {
            log.warn("Listener startup was interrupted");
            break;
        }
    }
}
Also used : ListenerEndpoint(org.apache.http.nio.reactor.ListenerEndpoint) InetSocketAddress(java.net.InetSocketAddress) LinkedList(java.util.LinkedList)

Example 2 with ListenerEndpoint

use of org.apache.http.nio.reactor.ListenerEndpoint 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 ListenerEndpoint

use of org.apache.http.nio.reactor.ListenerEndpoint in project wso2-synapse by wso2.

the class PassThroughListeningIOReactorManager method startDynamicPTTSSLEndpoint.

/**
 * Start SSL endpoint in IO reactor which is external to PTT Axis Listeners started at server startup
 * @param inetSocketAddress InetSocketAddress
 * @param nHttpServerEventHandler  ServerHandler responsible for handle events of port
 * @param endpointName   Endpoint Name
 * @param sslConfiguration SSL information for create secure connection
 * @return
 */
public boolean startDynamicPTTSSLEndpoint(InetSocketAddress inetSocketAddress, NHttpServerEventHandler nHttpServerEventHandler, String endpointName, SSLConfiguration sslConfiguration) {
    try {
        // get Shared IO Reactor and Start Endpoint
        ListenerEndpoint endpoint = startEndpoint(inetSocketAddress, getSharedSSLIOReactor(nHttpServerEventHandler, endpointName, inetSocketAddress.getPort(), sslConfiguration), endpointName);
        if (endpoint != null) {
            portServerHandlerMapper.put(inetSocketAddress.getPort(), nHttpServerEventHandler);
            dynamicPTTListeningEndpointMapper.put(inetSocketAddress.getPort(), endpoint);
            return true;
        } else {
            return false;
        }
    } catch (Exception e) {
        log.error("Cannot Start Endpoint for " + endpointName, e);
        return false;
    }
}
Also used : ListenerEndpoint(org.apache.http.nio.reactor.ListenerEndpoint) IOException(java.io.IOException) IOReactorException(org.apache.http.nio.reactor.IOReactorException)

Example 4 with ListenerEndpoint

use of org.apache.http.nio.reactor.ListenerEndpoint in project wso2-synapse by wso2.

the class PassThroughListeningIOReactorManager method startEndpoint.

private ListenerEndpoint startEndpoint(InetSocketAddress inetSocketAddress, ListeningIOReactor defaultListeningIOReactor, String endPointName) throws Exception {
    ListenerEndpoint endpoint = defaultListeningIOReactor.listen(inetSocketAddress);
    try {
        endpoint.waitFor();
        InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
        if (!address.isUnresolved()) {
            log.info((endPointName != null ? "Pass-through " + endPointName : " Pass-through Http ") + " Listener started on " + address.getHostName() + ":" + address.getPort());
        } else {
            log.info((endPointName != null ? "Pass-through " + endPointName : " Pass-through Http ") + " Listener started on " + address);
        }
    } catch (Exception e) {
        throw new Exception("Endpoint does not start for port " + inetSocketAddress.getPort() + "May be IO Reactor not started or endpoint binding exception ", e);
    }
    return endpoint;
}
Also used : ListenerEndpoint(org.apache.http.nio.reactor.ListenerEndpoint) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) IOReactorException(org.apache.http.nio.reactor.IOReactorException)

Example 5 with ListenerEndpoint

use of org.apache.http.nio.reactor.ListenerEndpoint in project wso2-synapse by wso2.

the class PassThroughListeningIOReactorManager method startDynamicPTTEndpoint.

/**
 * Start Endpoint in IOReactor which is external to PTT Axis2 Listeners started at server startup
 *
 * @param inetSocketAddress       Socket Address of starting endpoint
 * @param nHttpServerEventHandler ServerHandler responsible for handle events of port
 * @param endpointName            Endpoint Name
 * @return Is Endpoint started
 */
public boolean startDynamicPTTEndpoint(InetSocketAddress inetSocketAddress, NHttpServerEventHandler nHttpServerEventHandler, String endpointName) {
    try {
        // get Shared IO Reactor and Start Endpoint
        ListenerEndpoint endpoint = startEndpoint(inetSocketAddress, getSharedIOReactor(nHttpServerEventHandler, endpointName), endpointName);
        if (endpoint != null) {
            portServerHandlerMapper.put(inetSocketAddress.getPort(), nHttpServerEventHandler);
            dynamicPTTListeningEndpointMapper.put(inetSocketAddress.getPort(), endpoint);
            return true;
        } else {
            return false;
        }
    } catch (Exception e) {
        log.error("Cannot Start Endpoint for " + endpointName, e);
        return false;
    }
}
Also used : ListenerEndpoint(org.apache.http.nio.reactor.ListenerEndpoint) IOException(java.io.IOException) IOReactorException(org.apache.http.nio.reactor.IOReactorException)

Aggregations

ListenerEndpoint (org.apache.http.nio.reactor.ListenerEndpoint)10 InetSocketAddress (java.net.InetSocketAddress)6 IOException (java.io.IOException)5 IOReactorException (org.apache.http.nio.reactor.IOReactorException)5 HttpHost (org.apache.http.HttpHost)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 ServerConnFactoryBuilder (org.apache.synapse.transport.nhttp.config.ServerConnFactoryBuilder)2 HashSet (java.util.HashSet)1 ServerBootstrap (org.apache.http.impl.nio.bootstrap.ServerBootstrap)1 DefaultListeningIOReactor (org.apache.http.impl.nio.reactor.DefaultListeningIOReactor)1 BasicAsyncRequestHandler (org.apache.http.nio.protocol.BasicAsyncRequestHandler)1 ListeningIOReactor (org.apache.http.nio.reactor.ListeningIOReactor)1