Search in sources :

Example 1 with IdleTimeoutConduit

use of io.undertow.conduits.IdleTimeoutConduit in project undertow by undertow-io.

the class AjpOpenListener method handleEvent.

@Override
public void handleEvent(final StreamConnection channel) {
    if (UndertowLogger.REQUEST_LOGGER.isTraceEnabled()) {
        UndertowLogger.REQUEST_LOGGER.tracef("Opened connection with %s", channel.getPeerAddress());
    }
    // set read and write timeouts
    try {
        Integer readTimeout = channel.getOption(Options.READ_TIMEOUT);
        Integer idle = undertowOptions.get(UndertowOptions.IDLE_TIMEOUT);
        if (idle != null) {
            IdleTimeoutConduit conduit = new IdleTimeoutConduit(channel);
            channel.getSourceChannel().setConduit(conduit);
            channel.getSinkChannel().setConduit(conduit);
        }
        if (readTimeout != null && readTimeout > 0) {
            channel.getSourceChannel().setConduit(new ReadTimeoutStreamSourceConduit(channel.getSourceChannel().getConduit(), channel, this));
        }
        Integer writeTimeout = channel.getOption(Options.WRITE_TIMEOUT);
        if (writeTimeout != null && writeTimeout > 0) {
            channel.getSinkChannel().setConduit(new WriteTimeoutStreamSinkConduit(channel.getSinkChannel().getConduit(), channel, this));
        }
    } catch (IOException e) {
        IoUtils.safeClose(channel);
        UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
    }
    if (statisticsEnabled) {
        channel.getSinkChannel().setConduit(new BytesSentStreamSinkConduit(channel.getSinkChannel().getConduit(), connectorStatistics.sentAccumulator()));
        channel.getSourceChannel().setConduit(new BytesReceivedStreamSourceConduit(channel.getSourceChannel().getConduit(), connectorStatistics.receivedAccumulator()));
        connectorStatistics.incrementConnectionCount();
    }
    AjpServerConnection connection = new AjpServerConnection(channel, bufferPool, rootHandler, undertowOptions, bufferSize);
    AjpReadListener readListener = new AjpReadListener(connection, scheme, parser, statisticsEnabled ? connectorStatistics : null);
    if (statisticsEnabled) {
        connection.addCloseListener(closeListener);
    }
    connection.setAjpReadListener(readListener);
    connections.add(connection);
    connection.addCloseListener(new ServerConnection.CloseListener() {

        @Override
        public void closed(ServerConnection c) {
            connections.remove(connection);
        }
    });
    readListener.startRequest();
    channel.getSourceChannel().setReadListener(readListener);
    readListener.handleEvent(channel.getSourceChannel());
}
Also used : IdleTimeoutConduit(io.undertow.conduits.IdleTimeoutConduit) WriteTimeoutStreamSinkConduit(io.undertow.conduits.WriteTimeoutStreamSinkConduit) ServerConnection(io.undertow.server.ServerConnection) ReadTimeoutStreamSourceConduit(io.undertow.conduits.ReadTimeoutStreamSourceConduit) IOException(java.io.IOException) BytesSentStreamSinkConduit(io.undertow.conduits.BytesSentStreamSinkConduit) BytesReceivedStreamSourceConduit(io.undertow.conduits.BytesReceivedStreamSourceConduit)

Example 2 with IdleTimeoutConduit

use of io.undertow.conduits.IdleTimeoutConduit in project undertow by undertow-io.

the class HttpOpenListener method handleEvent.

@Override
public void handleEvent(final StreamConnection channel, PooledByteBuffer buffer) {
    if (UndertowLogger.REQUEST_LOGGER.isTraceEnabled()) {
        UndertowLogger.REQUEST_LOGGER.tracef("Opened connection with %s", channel.getPeerAddress());
    }
    // set read and write timeouts
    try {
        Integer readTimeout = channel.getOption(Options.READ_TIMEOUT);
        Integer idle = undertowOptions.get(UndertowOptions.IDLE_TIMEOUT);
        if (idle != null) {
            IdleTimeoutConduit conduit = new IdleTimeoutConduit(channel);
            channel.getSourceChannel().setConduit(conduit);
            channel.getSinkChannel().setConduit(conduit);
        }
        if (readTimeout != null && readTimeout > 0) {
            channel.getSourceChannel().setConduit(new ReadTimeoutStreamSourceConduit(channel.getSourceChannel().getConduit(), channel, this));
        }
        Integer writeTimeout = channel.getOption(Options.WRITE_TIMEOUT);
        if (writeTimeout != null && writeTimeout > 0) {
            channel.getSinkChannel().setConduit(new WriteTimeoutStreamSinkConduit(channel.getSinkChannel().getConduit(), channel, this));
        }
    } catch (IOException e) {
        IoUtils.safeClose(channel);
        UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
    } catch (Throwable t) {
        IoUtils.safeClose(channel);
        UndertowLogger.REQUEST_IO_LOGGER.handleUnexpectedFailure(t);
    }
    if (statisticsEnabled) {
        channel.getSinkChannel().setConduit(new BytesSentStreamSinkConduit(channel.getSinkChannel().getConduit(), connectorStatistics.sentAccumulator()));
        channel.getSourceChannel().setConduit(new BytesReceivedStreamSourceConduit(channel.getSourceChannel().getConduit(), connectorStatistics.receivedAccumulator()));
    }
    HttpServerConnection connection = new HttpServerConnection(channel, bufferPool, rootHandler, undertowOptions, bufferSize, statisticsEnabled ? connectorStatistics : null);
    HttpReadListener readListener = new HttpReadListener(connection, parser, statisticsEnabled ? connectorStatistics : null);
    if (buffer != null) {
        if (buffer.getBuffer().hasRemaining()) {
            connection.setExtraBytes(buffer);
        } else {
            buffer.close();
        }
    }
    if (connectorStatistics != null && statisticsEnabled) {
        connectorStatistics.incrementConnectionCount();
    }
    connections.add(connection);
    connection.addCloseListener(new ServerConnection.CloseListener() {

        @Override
        public void closed(ServerConnection c) {
            connections.remove(connection);
        }
    });
    connection.setReadListener(readListener);
    readListener.newRequest();
    channel.getSourceChannel().setReadListener(readListener);
    readListener.handleEvent(channel.getSourceChannel());
}
Also used : WriteTimeoutStreamSinkConduit(io.undertow.conduits.WriteTimeoutStreamSinkConduit) ServerConnection(io.undertow.server.ServerConnection) ReadTimeoutStreamSourceConduit(io.undertow.conduits.ReadTimeoutStreamSourceConduit) IOException(java.io.IOException) BytesReceivedStreamSourceConduit(io.undertow.conduits.BytesReceivedStreamSourceConduit) IdleTimeoutConduit(io.undertow.conduits.IdleTimeoutConduit) BytesSentStreamSinkConduit(io.undertow.conduits.BytesSentStreamSinkConduit)

Aggregations

BytesReceivedStreamSourceConduit (io.undertow.conduits.BytesReceivedStreamSourceConduit)2 BytesSentStreamSinkConduit (io.undertow.conduits.BytesSentStreamSinkConduit)2 IdleTimeoutConduit (io.undertow.conduits.IdleTimeoutConduit)2 ReadTimeoutStreamSourceConduit (io.undertow.conduits.ReadTimeoutStreamSourceConduit)2 WriteTimeoutStreamSinkConduit (io.undertow.conduits.WriteTimeoutStreamSinkConduit)2 ServerConnection (io.undertow.server.ServerConnection)2 IOException (java.io.IOException)2