Search in sources :

Example 1 with IOEventHandler

use of org.apache.hc.core5.reactor.IOEventHandler in project httpcomponents-core by apache.

the class LoggingIOSession method upgrade.

@Override
public void upgrade(final IOEventHandler handler) {
    Args.notNull(handler, "Protocol handler");
    if (this.log.isDebugEnabled()) {
        this.log.debug("{} protocol upgrade: {}", this.session, handler.getClass());
    }
    this.session.upgrade(new IOEventHandler() {

        @Override
        public void connected(final IOSession protocolSession) throws IOException {
            handler.connected(protocolSession);
        }

        @Override
        public void inputReady(final IOSession protocolSession, final ByteBuffer src) throws IOException {
            if (src != null && wireLog.isDebugEnabled()) {
                final ByteBuffer b = src.duplicate();
                logData(b, "<< ");
            }
            handler.inputReady(protocolSession, src);
        }

        @Override
        public void outputReady(final IOSession protocolSession) throws IOException {
            handler.outputReady(protocolSession);
        }

        @Override
        public void timeout(final IOSession protocolSession, final Timeout timeout) throws IOException {
            handler.timeout(protocolSession, timeout);
        }

        @Override
        public void exception(final IOSession protocolSession, final Exception cause) {
            handler.exception(protocolSession, cause);
        }

        @Override
        public void disconnected(final IOSession protocolSession) {
            handler.disconnected(protocolSession);
        }
    });
}
Also used : IOEventHandler(org.apache.hc.core5.reactor.IOEventHandler) Timeout(org.apache.hc.core5.util.Timeout) ProtocolIOSession(org.apache.hc.core5.reactor.ProtocolIOSession) IOSession(org.apache.hc.core5.reactor.IOSession) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException)

Example 2 with IOEventHandler

use of org.apache.hc.core5.reactor.IOEventHandler in project httpcomponents-core by apache.

the class InternalDataChannel method onIOEvent.

@Override
void onIOEvent(final int readyOps) throws IOException {
    if ((readyOps & SelectionKey.OP_CONNECT) != 0) {
        final IOSession currentSession = currentSessionRef.get();
        currentSession.clearEvent(SelectionKey.OP_CONNECT);
        if (tlsSessionRef.get() == null) {
            if (sessionListener != null) {
                sessionListener.connected(currentSession);
            }
            final IOEventHandler handler = ensureHandler(currentSession);
            handler.connected(currentSession);
        }
    }
    if ((readyOps & SelectionKey.OP_READ) != 0) {
        final IOSession currentSession = currentSessionRef.get();
        currentSession.updateReadTime();
        if (sessionListener != null) {
            sessionListener.inputReady(currentSession);
        }
        final IOEventHandler handler = ensureHandler(currentSession);
        handler.inputReady(currentSession, null);
    }
    if ((readyOps & SelectionKey.OP_WRITE) != 0 || (ioSession.getEventMask() & SelectionKey.OP_WRITE) != 0) {
        final IOSession currentSession = currentSessionRef.get();
        currentSession.updateWriteTime();
        if (sessionListener != null) {
            sessionListener.outputReady(currentSession);
        }
        final IOEventHandler handler = ensureHandler(currentSession);
        handler.outputReady(currentSession);
    }
}
Also used : SSLIOSession(org.apache.hc.core5.reactor.ssl.SSLIOSession)

Example 3 with IOEventHandler

use of org.apache.hc.core5.reactor.IOEventHandler in project httpcomponents-core by apache.

the class InternalDataChannel method upgrade.

@Override
public void upgrade(final IOEventHandler handler) {
    final IOSession currentSession = currentSessionRef.get();
    currentSession.upgrade(handler);
    eventHandlerRef.set(handler);
}
Also used : SSLIOSession(org.apache.hc.core5.reactor.ssl.SSLIOSession)

Example 4 with IOEventHandler

use of org.apache.hc.core5.reactor.IOEventHandler in project httpcomponents-core by apache.

the class InternalDataChannel method disconnected.

void disconnected() {
    final IOSession currentSession = currentSessionRef.get();
    if (sessionListener != null) {
        sessionListener.disconnected(currentSession);
    }
    final IOEventHandler handler = currentSession.getHandler();
    if (handler != null) {
        handler.disconnected(currentSession);
    }
}
Also used : SSLIOSession(org.apache.hc.core5.reactor.ssl.SSLIOSession)

Example 5 with IOEventHandler

use of org.apache.hc.core5.reactor.IOEventHandler in project httpcomponents-core by apache.

the class InternalDataChannel method onTimeout.

@Override
void onTimeout(final Timeout timeout) throws IOException {
    final IOSession currentSession = currentSessionRef.get();
    if (sessionListener != null) {
        sessionListener.timeout(currentSession);
    }
    final IOEventHandler handler = ensureHandler(currentSession);
    handler.timeout(currentSession, timeout);
}
Also used : SSLIOSession(org.apache.hc.core5.reactor.ssl.SSLIOSession)

Aggregations

SSLIOSession (org.apache.hc.core5.reactor.ssl.SSLIOSession)4 IOEventHandler (org.apache.hc.core5.reactor.IOEventHandler)3 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 HttpProtocolNegotiator (org.apache.hc.core5.http2.impl.nio.HttpProtocolNegotiator)2 File (java.io.File)1 SocketAddress (java.net.SocketAddress)1 ByteChannel (java.nio.channels.ByteChannel)1 Lock (java.util.concurrent.locks.Lock)1 SSLContext (javax.net.ssl.SSLContext)1 Header (org.apache.hc.core5.http.Header)1 HttpConnection (org.apache.hc.core5.http.HttpConnection)1 HttpRequest (org.apache.hc.core5.http.HttpRequest)1 HttpResponse (org.apache.hc.core5.http.HttpResponse)1 Http1StreamListener (org.apache.hc.core5.http.impl.Http1StreamListener)1 HttpAsyncRequester (org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester)1 ClientHttp1IOEventHandler (org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler)1 ClientHttp1StreamDuplexerFactory (org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory)1 ServerHttp1IOEventHandler (org.apache.hc.core5.http.impl.nio.ServerHttp1IOEventHandler)1 ServerHttp1StreamDuplexerFactory (org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexerFactory)1