use of io.undertow.conduits.WriteTimeoutStreamSinkConduit 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 idleTimeout = undertowOptions.get(UndertowOptions.IDLE_TIMEOUT);
if ((readTimeout == null || readTimeout <= 0) && idleTimeout != null) {
readTimeout = idleTimeout;
} else if (readTimeout != null && idleTimeout != null && idleTimeout > 0) {
readTimeout = Math.min(readTimeout, idleTimeout);
}
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) && idleTimeout != null) {
writeTimeout = idleTimeout;
} else if (writeTimeout != null && idleTimeout != null && idleTimeout > 0) {
writeTimeout = Math.min(writeTimeout, idleTimeout);
}
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()));
}
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();
}
connection.setReadListener(readListener);
readListener.newRequest();
channel.getSourceChannel().setReadListener(readListener);
readListener.handleEvent(channel.getSourceChannel());
}
use of io.undertow.conduits.WriteTimeoutStreamSinkConduit 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 idleTimeout = undertowOptions.get(UndertowOptions.IDLE_TIMEOUT);
if ((readTimeout == null || readTimeout <= 0) && idleTimeout != null) {
readTimeout = idleTimeout;
} else if (readTimeout != null && idleTimeout != null && idleTimeout > 0) {
readTimeout = Math.min(readTimeout, idleTimeout);
}
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) && idleTimeout != null) {
writeTimeout = idleTimeout;
} else if (writeTimeout != null && idleTimeout != null && idleTimeout > 0) {
writeTimeout = Math.min(writeTimeout, idleTimeout);
}
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);
readListener.startRequest();
channel.getSourceChannel().setReadListener(readListener);
readListener.handleEvent(channel.getSourceChannel());
}
Aggregations