Example usage for org.apache.http.nio.reactor IOReactorStatus ACTIVE

List of usage examples for org.apache.http.nio.reactor IOReactorStatus ACTIVE

Introduction

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

Prototype

IOReactorStatus ACTIVE

To view the source code for org.apache.http.nio.reactor IOReactorStatus ACTIVE.

Click Source Link

Document

The reactor is active / processing I/O events.

Usage

From source file:org.wso2.carbon.inbound.endpoint.protocol.hl7.core.InboundHL7IOReactor.java

public static void start() throws IOException {

    if (reactor != null && reactor.getStatus().equals(IOReactorStatus.ACTIVE)) {
        return;/*  w  w  w .j a v  a  2 s. c om*/
    }

    IOReactorConfig config = getDefaultReactorConfig();

    reactor = new DefaultListeningIOReactor(config);

    Thread reactorThread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                isStarted = true;
                multiIOHandler = new MultiIOHandler(processorMap);
                log.info("MLLP Transport IO Reactor Started");
                reactor.execute(multiIOHandler);
            } catch (IOException e) {
                isStarted = false;
                log.error("Error while starting the MLLP Transport IO Reactor.", e);
            }
        }
    });

    reactorThread.start();
}

From source file:org.hydracache.server.httpd.AsyncHttpLightServer.java

@Override
public boolean isRunning() {
    return IOReactorStatus.ACTIVE == ioReactor.getStatus();
}

From source file:net.kungfoo.grizzly.proxy.impl.ProxyAdapter.java

/**
 * {@inheritDoc}/*from  ww  w  .  j  ava 2s.c  om*/
 */
public void service(Request request, Response response) throws Exception {
    String uri = request.unparsedURI().toString();

    final MessageBytes method = request.method();
    logURIAndMethod(uri, method);

    if (maxForwards(request, response, method))
        return;

    String targetHost = request.serverName().toString();
    int targetPort = request.getServerPort();

    ProxyProcessingInfo proxyTask = new ProxyProcessingInfo();

    // TODO: think of it.
    synchronized (proxyTask) {

        // from connected

        // Initialize connection state
        proxyTask.setTarget(new HttpHost(targetHost, targetPort));
        proxyTask.setRequest(convert(method.getString(), uri, request));
        proxyTask.setOriginalRequest(request);
        Runnable completion = (Runnable) request.getAttribute(CALLBACK_KEY);
        proxyTask.setCompletion(completion);
        proxyTask.setResponse(response);

        InetSocketAddress address = new InetSocketAddress(targetHost, targetPort);

        if (!IOReactorStatus.ACTIVE.equals(connectingIOReactor.getStatus())) {
            System.err.println("Connecting reactor not running.");
            response.setStatus(500);
            response.setMessage("Internal Booo");
            // complete request.
            ExecutorService executorService = Executors.newFixedThreadPool(1, new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    return new Thread(r, "EmergencyService"); //To change body of implemented methods use File | Settings | File Templates.
                }
            });
            executorService.submit(completion);
            return;
        } else {
            connectingIOReactor.connect(address, null, proxyTask, null);
        }

        // from requestReceived
        try {
            System.out.println(request + " [client->proxy] >> " + request.unparsedURI().toString());

            // Update connection state
            proxyTask.setClientState(ConnState.REQUEST_RECEIVED);

            if (request.getContentLength() != 0) {
                proxyTask.setClientState(ConnState.REQUEST_BODY_DONE);
            }
            // See if the client expects a 100-Continue
            if (isExpectContinue(request)) {
                response.setStatus(HttpStatus.SC_CONTINUE);
                response.sendHeaders();
            }
        } catch (IOException ignore) {
            System.out.println("err " + ignore.getMessage());
        }
    }

    // handle "Via", TODO: should go after we have headers from target server.
    response.setHeader(Via.name(), request.protocol() + " antares");// TODO hostname, and Via from response

}

From source file:org.hydracache.server.httpd.AsyncHttpLightServerTest.java

private void addReturnActiveStatusExpectation(final ListeningIOReactor ioReactor) {
    context.checking(new Expectations() {
        {//from ww  w.ja v a2 s.  co  m
            one(ioReactor).getStatus();
            will(returnValue(IOReactorStatus.ACTIVE));
        }
    });
}

From source file:com.aptana.webserver.internal.core.builtin.LocalWebServer.java

private void startServer(final InetAddress host, final int port) {
    updateState(State.STARTING);/*from   w w  w.  ja  v  a 2  s.  com*/
    thread = new Thread() {
        @Override
        public void run() {
            runServer(new InetSocketAddress(host, port),
                    new BasicAsyncRequestHandler(new LocalWebServerHttpRequestHandler(LocalWebServer.this)));
        }
    };
    thread.setDaemon(true);
    thread.start();
    Thread.yield();
    long startTime = System.currentTimeMillis();
    while (thread.isAlive() && (System.currentTimeMillis() - startTime) < STARTUP_TIMEOUT) {
        if (reactor != null && reactor.getStatus() == IOReactorStatus.ACTIVE) {
            updateState(State.STARTED);
            break;
        }
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            updateState(State.UNKNOWN);
            break;
        }
    }
}