Search in sources :

Example 6 with ExecutableCommand

use of org.apache.hc.core5.http.nio.command.ExecutableCommand in project httpcomponents-core by apache.

the class AbstractH2StreamMultiplexer method onException.

public final void onException(final Exception cause) {
    try {
        for (; ; ) {
            final AsyncPingHandler pingHandler = pingHandlers.poll();
            if (pingHandler != null) {
                pingHandler.failed(cause);
            } else {
                break;
            }
        }
        for (; ; ) {
            final Command command = ioSession.poll();
            if (command != null) {
                if (command instanceof ExecutableCommand) {
                    ((ExecutableCommand) command).failed(new ConnectionClosedException());
                } else {
                    command.cancel();
                }
            } else {
                break;
            }
        }
        for (final Iterator<Map.Entry<Integer, H2Stream>> it = streamMap.entrySet().iterator(); it.hasNext(); ) {
            final Map.Entry<Integer, H2Stream> entry = it.next();
            final H2Stream stream = entry.getValue();
            stream.reset(cause);
        }
        streamMap.clear();
        if (!(cause instanceof ConnectionClosedException)) {
            if (connState.compareTo(ConnectionHandshake.GRACEFUL_SHUTDOWN) <= 0) {
                final H2Error errorCode;
                if (cause instanceof H2ConnectionException) {
                    errorCode = H2Error.getByCode(((H2ConnectionException) cause).getCode());
                } else if (cause instanceof ProtocolException) {
                    errorCode = H2Error.PROTOCOL_ERROR;
                } else {
                    errorCode = H2Error.INTERNAL_ERROR;
                }
                final RawFrame goAway = frameFactory.createGoAway(processedRemoteStreamId, errorCode, cause.getMessage());
                commitFrame(goAway);
            }
        }
    } catch (final IOException ignore) {
    } finally {
        connState = ConnectionHandshake.SHUTDOWN;
        final CloseMode closeMode;
        if (cause instanceof ConnectionClosedException) {
            closeMode = CloseMode.GRACEFUL;
        } else if (cause instanceof IOException) {
            closeMode = CloseMode.IMMEDIATE;
        } else {
            closeMode = CloseMode.GRACEFUL;
        }
        ioSession.close(closeMode);
    }
}
Also used : ProtocolException(org.apache.hc.core5.http.ProtocolException) H2ConnectionException(org.apache.hc.core5.http2.H2ConnectionException) ConnectionClosedException(org.apache.hc.core5.http.ConnectionClosedException) H2Error(org.apache.hc.core5.http2.H2Error) IOException(java.io.IOException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PingCommand(org.apache.hc.core5.http2.nio.command.PingCommand) ExecutableCommand(org.apache.hc.core5.http.nio.command.ExecutableCommand) Command(org.apache.hc.core5.reactor.Command) ShutdownCommand(org.apache.hc.core5.http.nio.command.ShutdownCommand) AsyncPingHandler(org.apache.hc.core5.http2.nio.AsyncPingHandler) CloseMode(org.apache.hc.core5.io.CloseMode) RawFrame(org.apache.hc.core5.http2.frame.RawFrame) ExecutableCommand(org.apache.hc.core5.http.nio.command.ExecutableCommand) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

Command (org.apache.hc.core5.reactor.Command)5 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ExecutableCommand (org.apache.hc.core5.http.nio.command.ExecutableCommand)3 ShutdownCommand (org.apache.hc.core5.http.nio.command.ShutdownCommand)3 AsyncPingHandler (org.apache.hc.core5.http2.nio.AsyncPingHandler)3 PingCommand (org.apache.hc.core5.http2.nio.command.PingCommand)3 ConnectionClosedException (org.apache.hc.core5.http.ConnectionClosedException)2 H2ConnectionException (org.apache.hc.core5.http2.H2ConnectionException)2 RawFrame (org.apache.hc.core5.http2.frame.RawFrame)2 IOException (java.io.IOException)1 CancellableDependency (org.apache.hc.core5.concurrent.CancellableDependency)1 ProtocolException (org.apache.hc.core5.http.ProtocolException)1 RequestNotExecutedException (org.apache.hc.core5.http.RequestNotExecutedException)1 AsyncClientExchangeHandler (org.apache.hc.core5.http.nio.AsyncClientExchangeHandler)1 AsyncPushConsumer (org.apache.hc.core5.http.nio.AsyncPushConsumer)1 RequestExecutionCommand (org.apache.hc.core5.http.nio.command.RequestExecutionCommand)1 HttpCoreContext (org.apache.hc.core5.http.protocol.HttpCoreContext)1 H2Error (org.apache.hc.core5.http2.H2Error)1