use of io.undertow.conduits.BytesReceivedStreamSourceConduit 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());
}
use of io.undertow.conduits.BytesReceivedStreamSourceConduit in project undertow by undertow-io.
the class Http2PriorKnowledgeClientProvider method handleConnected.
private void handleConnected(final StreamConnection connection, final ClientCallback<ClientConnection> listener, final ByteBufferPool bufferPool, final OptionMap options, final String defaultHost) {
try {
final ClientStatisticsImpl clientStatistics;
// first we set up statistics, if required
if (options.get(UndertowOptions.ENABLE_STATISTICS, false)) {
clientStatistics = new ClientStatisticsImpl();
connection.getSinkChannel().setConduit(new BytesSentStreamSinkConduit(connection.getSinkChannel().getConduit(), new ByteActivityCallback() {
@Override
public void activity(long bytes) {
clientStatistics.written += bytes;
}
}));
connection.getSourceChannel().setConduit(new BytesReceivedStreamSourceConduit(connection.getSourceChannel().getConduit(), new ByteActivityCallback() {
@Override
public void activity(long bytes) {
clientStatistics.read += bytes;
}
}));
} else {
clientStatistics = null;
}
final ByteBuffer pri = ByteBuffer.wrap(PRI_REQUEST);
pri.flip();
ConduitStreamSinkChannel sink = connection.getSinkChannel();
sink.write(pri);
if (pri.hasRemaining()) {
sink.setWriteListener(new ChannelListener<ConduitStreamSinkChannel>() {
@Override
public void handleEvent(ConduitStreamSinkChannel channel) {
try {
channel.write(pri);
if (pri.hasRemaining()) {
return;
}
listener.completed(new Http2ClientConnection(new Http2Channel(connection, null, bufferPool, null, true, false, options), false, defaultHost, clientStatistics, false));
} catch (Throwable t) {
IOException e = t instanceof IOException ? (IOException) t : new IOException(t);
listener.failed(e);
}
}
});
return;
}
listener.completed(new Http2ClientConnection(new Http2Channel(connection, null, bufferPool, null, true, false, options), false, defaultHost, clientStatistics, false));
} catch (Throwable t) {
IOException e = t instanceof IOException ? (IOException) t : new IOException(t);
listener.failed(e);
}
}
use of io.undertow.conduits.BytesReceivedStreamSourceConduit in project undertow by undertow-io.
the class Http2OpenListener method handleEvent.
public void handleEvent(final StreamConnection channel, PooledByteBuffer buffer) {
if (UndertowLogger.REQUEST_LOGGER.isTraceEnabled()) {
UndertowLogger.REQUEST_LOGGER.tracef("Opened HTTP/2 connection with %s", channel.getPeerAddress());
}
// cool, we have a Http2 connection.
Http2Channel http2Channel = new Http2Channel(channel, protocol, bufferPool, buffer, false, false, undertowOptions);
Integer idleTimeout = undertowOptions.get(UndertowOptions.IDLE_TIMEOUT);
if (idleTimeout != null && idleTimeout > 0) {
http2Channel.setIdleTimeout(idleTimeout);
}
if (statisticsEnabled) {
channel.getSinkChannel().setConduit(new BytesSentStreamSinkConduit(channel.getSinkChannel().getConduit(), connectorStatistics.sentAccumulator()));
channel.getSourceChannel().setConduit(new BytesReceivedStreamSourceConduit(channel.getSourceChannel().getConduit(), connectorStatistics.receivedAccumulator()));
connectorStatistics.incrementConnectionCount();
http2Channel.addCloseTask(closeTask);
}
connections.add(http2Channel);
http2Channel.addCloseTask(new ChannelListener<Http2Channel>() {
@Override
public void handleEvent(Http2Channel channel) {
connections.remove(channel);
}
});
http2Channel.getReceiveSetter().set(new Http2ReceiveListener(rootHandler, getUndertowOptions(), bufferSize, connectorStatistics));
http2Channel.resumeReceives();
}
use of io.undertow.conduits.BytesReceivedStreamSourceConduit 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());
}
use of io.undertow.conduits.BytesReceivedStreamSourceConduit in project undertow by undertow-io.
the class AjpClientProvider method handleConnected.
private void handleConnected(StreamConnection connection, ClientCallback<ClientConnection> listener, URI uri, XnioSsl ssl, ByteBufferPool bufferPool, OptionMap options) {
final ClientStatisticsImpl clientStatistics;
// first we set up statistics, if required
if (options.get(UndertowOptions.ENABLE_STATISTICS, false)) {
clientStatistics = new ClientStatisticsImpl();
connection.getSinkChannel().setConduit(new BytesSentStreamSinkConduit(connection.getSinkChannel().getConduit(), new ByteActivityCallback() {
@Override
public void activity(long bytes) {
clientStatistics.written += bytes;
}
}));
connection.getSourceChannel().setConduit(new BytesReceivedStreamSourceConduit(connection.getSourceChannel().getConduit(), new ByteActivityCallback() {
@Override
public void activity(long bytes) {
clientStatistics.read += bytes;
}
}));
} else {
clientStatistics = null;
}
listener.completed(new AjpClientConnection(new AjpClientChannel(connection, bufferPool, options), options, bufferPool, clientStatistics));
}
Aggregations