Search in sources :

Example 1 with BytesReceivedStreamSourceConduit

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());
}
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 BytesReceivedStreamSourceConduit

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);
    }
}
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 3 with BytesReceivedStreamSourceConduit

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();
}
Also used : Http2Channel(io.undertow.protocols.http2.Http2Channel) BytesSentStreamSinkConduit(io.undertow.conduits.BytesSentStreamSinkConduit) BytesReceivedStreamSourceConduit(io.undertow.conduits.BytesReceivedStreamSourceConduit)

Example 4 with BytesReceivedStreamSourceConduit

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());
}
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)

Example 5 with BytesReceivedStreamSourceConduit

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));
}
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 IdleTimeoutConduit (io.undertow.conduits.IdleTimeoutConduit)2 ReadTimeoutStreamSourceConduit (io.undertow.conduits.ReadTimeoutStreamSourceConduit)2 WriteTimeoutStreamSinkConduit (io.undertow.conduits.WriteTimeoutStreamSinkConduit)2 ServerConnection (io.undertow.server.ServerConnection)2 AjpClientChannel (io.undertow.protocols.ajp.AjpClientChannel)1 ByteBuffer (java.nio.ByteBuffer)1 ConduitStreamSinkChannel (org.xnio.conduits.ConduitStreamSinkChannel)1