Search in sources :

Example 1 with BytesSentStreamSinkConduit

use of io.undertow.conduits.BytesSentStreamSinkConduit 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 (IOException e) {
                        listener.failed(e);
                    }
                }
            });
            return;
        }
        listener.completed(new Http2ClientConnection(new Http2Channel(connection, null, bufferPool, null, true, false, options), false, defaultHost, clientStatistics, false));
    } catch (IOException e) {
        listener.failed(e);
    }
}
Also used : Http2Channel(io.undertow.protocols.http2.Http2Channel) ByteActivityCallback(io.undertow.conduits.ByteActivityCallback) IOException(java.io.IOException) BytesSentStreamSinkConduit(io.undertow.conduits.BytesSentStreamSinkConduit) BytesReceivedStreamSourceConduit(io.undertow.conduits.BytesReceivedStreamSourceConduit) ByteBuffer(java.nio.ByteBuffer) ConduitStreamSinkChannel(org.xnio.conduits.ConduitStreamSinkChannel)

Example 2 with BytesSentStreamSinkConduit

use of io.undertow.conduits.BytesSentStreamSinkConduit 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());
}
Also used : WriteTimeoutStreamSinkConduit(io.undertow.conduits.WriteTimeoutStreamSinkConduit) ReadTimeoutStreamSourceConduit(io.undertow.conduits.ReadTimeoutStreamSourceConduit) IOException(java.io.IOException) BytesSentStreamSinkConduit(io.undertow.conduits.BytesSentStreamSinkConduit) BytesReceivedStreamSourceConduit(io.undertow.conduits.BytesReceivedStreamSourceConduit)

Example 3 with BytesSentStreamSinkConduit

use of io.undertow.conduits.BytesSentStreamSinkConduit 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);
    }
    http2Channel.getReceiveSetter().set(new Http2ReceiveListener(rootHandler, getUndertowOptions(), bufferSize, connectorStatistics));
    http2Channel.resumeReceives();
}
Also used : Http2Channel(io.undertow.protocols.http2.Http2Channel) BytesSentStreamSinkConduit(io.undertow.conduits.BytesSentStreamSinkConduit) BytesReceivedStreamSourceConduit(io.undertow.conduits.BytesReceivedStreamSourceConduit)

Example 4 with BytesSentStreamSinkConduit

use of io.undertow.conduits.BytesSentStreamSinkConduit 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());
}
Also used : WriteTimeoutStreamSinkConduit(io.undertow.conduits.WriteTimeoutStreamSinkConduit) ReadTimeoutStreamSourceConduit(io.undertow.conduits.ReadTimeoutStreamSourceConduit) IOException(java.io.IOException) BytesSentStreamSinkConduit(io.undertow.conduits.BytesSentStreamSinkConduit) BytesReceivedStreamSourceConduit(io.undertow.conduits.BytesReceivedStreamSourceConduit)

Example 5 with BytesSentStreamSinkConduit

use of io.undertow.conduits.BytesSentStreamSinkConduit 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));
}
Also used : AjpClientChannel(io.undertow.protocols.ajp.AjpClientChannel) ByteActivityCallback(io.undertow.conduits.ByteActivityCallback) BytesSentStreamSinkConduit(io.undertow.conduits.BytesSentStreamSinkConduit) BytesReceivedStreamSourceConduit(io.undertow.conduits.BytesReceivedStreamSourceConduit)

Aggregations

BytesReceivedStreamSourceConduit (io.undertow.conduits.BytesReceivedStreamSourceConduit)6 BytesSentStreamSinkConduit (io.undertow.conduits.BytesSentStreamSinkConduit)6 ByteActivityCallback (io.undertow.conduits.ByteActivityCallback)3 Http2Channel (io.undertow.protocols.http2.Http2Channel)3 IOException (java.io.IOException)3 ReadTimeoutStreamSourceConduit (io.undertow.conduits.ReadTimeoutStreamSourceConduit)2 WriteTimeoutStreamSinkConduit (io.undertow.conduits.WriteTimeoutStreamSinkConduit)2 AjpClientChannel (io.undertow.protocols.ajp.AjpClientChannel)1 ByteBuffer (java.nio.ByteBuffer)1 ConduitStreamSinkChannel (org.xnio.conduits.ConduitStreamSinkChannel)1