Search in sources :

Example 1 with ConnectionState

use of io.github.tesla.gateway.netty.transmit.ConnectionState in project tesla by linking12.

the class ProxyConnection method readHTTP.

@SuppressWarnings("unchecked")
private void readHTTP(HttpObject httpObject) {
    ConnectionState nextState = getCurrentState();
    switch(getCurrentState()) {
        case AWAITING_INITIAL:
            if (httpObject instanceof HttpMessage) {
                nextState = readHTTPInitial((I) httpObject);
            } else {
                LOG.debug("Dropping message because HTTP object was not an HttpMessage. HTTP object may be orphaned content from a short-circuited response. Message: {}", httpObject);
            }
            break;
        case AWAITING_CHUNK:
            HttpContent chunk = (HttpContent) httpObject;
            readHTTPChunk(chunk);
            nextState = ProxyUtils.isLastChunk(chunk) ? AWAITING_INITIAL : AWAITING_CHUNK;
            break;
        case AWAITING_PROXY_AUTHENTICATION:
            if (httpObject instanceof HttpRequest) {
                nextState = readHTTPInitial((I) httpObject);
            } else {
            }
            break;
        case CONNECTING:
            LOG.warn("Attempted to read from connection that's in the process of connecting.  This shouldn't happen.");
            break;
        case NEGOTIATING_CONNECT:
            LOG.debug("Attempted to read from connection that's in the process of negotiating an HTTP CONNECT.  This is probably the LastHttpContent of a chunked CONNECT.");
            break;
        case AWAITING_CONNECT_OK:
            LOG.warn("AWAITING_CONNECT_OK should have been handled by ProxyToServerConnection.read()");
            break;
        case HANDSHAKING:
            LOG.warn("Attempted to read from connection that's in the process of handshaking.  This shouldn't happen.", channel);
            break;
        case DISCONNECT_REQUESTED:
        case DISCONNECTED:
            LOG.info("Ignoring message since the connection is closed or about to close");
            break;
    }
    become(nextState);
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) ConnectionState(io.github.tesla.gateway.netty.transmit.ConnectionState) HttpMessage(io.netty.handler.codec.http.HttpMessage) HttpContent(io.netty.handler.codec.http.HttpContent)

Example 2 with ConnectionState

use of io.github.tesla.gateway.netty.transmit.ConnectionState in project tesla by linking12.

the class ConnectionFlow method fail.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void fail(final Throwable cause) {
    final ConnectionState lastStateBeforeFailure = serverConnection.getCurrentState();
    serverConnection.disconnect().addListener(new GenericFutureListener() {

        @Override
        public void operationComplete(Future future) throws Exception {
            synchronized (connectLock) {
                if (!clientConnection.serverConnectionFailed(serverConnection, lastStateBeforeFailure, cause)) {
                    serverConnection.become(ConnectionState.DISCONNECTED);
                    notifyThreadsWaitingForConnection();
                }
            }
        }
    });
}
Also used : Future(io.netty.util.concurrent.Future) ConnectionState(io.github.tesla.gateway.netty.transmit.ConnectionState) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener)

Aggregations

ConnectionState (io.github.tesla.gateway.netty.transmit.ConnectionState)2 HttpContent (io.netty.handler.codec.http.HttpContent)1 HttpMessage (io.netty.handler.codec.http.HttpMessage)1 HttpRequest (io.netty.handler.codec.http.HttpRequest)1 Future (io.netty.util.concurrent.Future)1 GenericFutureListener (io.netty.util.concurrent.GenericFutureListener)1