List of usage examples for org.apache.http.nio.reactor ListenerEndpoint waitFor
void waitFor() throws InterruptedException;
From source file:org.wso2.carbon.inbound.endpoint.protocol.hl7.core.InboundHL7IOReactor.java
public static boolean bind(int port, HL7Processor processor) { checkReactor();// w w w . j a v a2 s. c o m if (!isPortAvailable(port)) { log.error("A service is already listening on port " + port + ". Please select a different port for this endpoint."); return false; } ListenerEndpoint ep = reactor.listen(getSocketAddress(port)); try { ep.waitFor(); endpointMap.put(port, ep); processorMap.put(port, processor); return true; } catch (InterruptedException e) { log.error("Error while starting a new MLLP Listener on port " + port + ". ", e); return false; } }
From source file:org.apache.synapse.transport.passthru.core.PassThroughListeningIOReactorManager.java
private ListenerEndpoint startEndpoint(InetSocketAddress inetSocketAddress, ListeningIOReactor defaultListeningIOReactor, String endPointName) throws Exception { ListenerEndpoint endpoint = defaultListeningIOReactor.listen(inetSocketAddress); try {/*from w w w .ja v a 2 s . co m*/ 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; }
From source file:com.eislab.af.translator.spokes.HttpServer_spoke.java
public HttpServer_spoke(String ipaddress, String path) throws IOException, InterruptedException { address = ipaddress;// w w w . j a va 2 s . c o m // HTTP parameters for the server HttpParams params = new SyncBasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, SOCKET_TIMEOUT) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, SOCKET_BUFFER_SIZE) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, SERVER_NAME); // Create HTTP protocol processing chain // Use standard server-side protocol interceptors HttpRequestInterceptor[] requestInterceptors = new HttpRequestInterceptor[] { new RequestAcceptEncoding() }; HttpResponseInterceptor[] responseInterceptors = new HttpResponseInterceptor[] { new ResponseAllowCORS(), new ResponseContentEncoding(), new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl() }; HttpProcessor httpProcessor = new ImmutableHttpProcessor(requestInterceptors, responseInterceptors); // Create request handler registry HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry(); // register the handler that will reply to the proxy requests registry.register(path, new RequestHandler("", true)); // Create server-side HTTP protocol handler HttpAsyncService protocolHandler = new HttpAsyncService(httpProcessor, new DefaultConnectionReuseStrategy(), registry, params); // Create HTTP connection factory NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory = new DefaultNHttpServerConnectionFactory( params); // Create server-side I/O event dispatch final IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch(protocolHandler, connFactory); try { // Create server-side I/O reactor ioReactor = new DefaultListeningIOReactor(); // Listen of the given port InetSocketAddress socketAddress = new InetSocketAddress(ipaddress, 0); ListenerEndpoint endpoint1 = ioReactor.listen(socketAddress); // create the listener thread Thread listener = new Thread("Http listener") { @Override public void run() { try { ioReactor.execute(ioEventDispatch); } catch (IOException e) { // LOGGER.severe("I/O Exception: " + e.getMessage()); } } }; listener.setDaemon(false); listener.start(); endpoint1.waitFor(); if (address.contains(":")) { if (!address.startsWith("[")) { address = "[" + address + "]"; } } address = address + ":" + Integer.toString(((InetSocketAddress) endpoint1.getAddress()).getPort()) + "/"; System.out.println(address); } catch (IOException e) { // LOGGER.severe("I/O error: " + e.getMessage()); } }
From source file:org.apache.synapse.transport.nhttp.HttpCoreNIOListener.java
/** * Start specific end points given by InetSockeAddress list * * @param endpointsClosed InetSocketAddresses of endpoints to be started * @throws AxisFault//from w w w . jav a 2s. co m */ 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)); } // Wait for the endpoint to become ready, i.e. for the listener to start accepting // 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; } } }
From source file:org.apache.synapse.transport.nhttp.HttpCoreNIOListener.java
private void startEndpoints() throws AxisFault { Queue<ListenerEndpoint> endpoints = new LinkedList<ListenerEndpoint>(); Set<InetSocketAddress> addressSet = new HashSet<InetSocketAddress>(); addressSet.addAll(connFactory.getBindAddresses()); if (NHttpConfiguration.getInstance().getMaxActiveConnections() != -1) { addMaxConnectionCountController(NHttpConfiguration.getInstance().getMaxActiveConnections()); }/*from w w w .j a v a2s . c o m*/ if (listenerContext.getBindAddress() != null) { addressSet.add(new InetSocketAddress(listenerContext.getBindAddress(), listenerContext.getPort())); } if (addressSet.isEmpty()) { addressSet.add(new InetSocketAddress(listenerContext.getPort())); } // Ensure simple but stable order List<InetSocketAddress> addressList = new ArrayList<InetSocketAddress>(addressSet); 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)); } // Wait for the endpoint to become ready, i.e. for the listener to start accepting // 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; } } }
From source file:org.apache.http.localserver.AbstractAsyncTest.java
public HttpHost startServer() throws Exception { this.server = this.serverBootstrap.create(); this.server.start(); final ListenerEndpoint endpoint = this.server.getEndpoint(); endpoint.waitFor(); final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress(); return new HttpHost("localhost", address.getPort(), this.scheme.name()); }