Search in sources :

Example 1 with ByteActivityCallback

use of io.undertow.conduits.ByteActivityCallback 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 ByteActivityCallback

use of io.undertow.conduits.ByteActivityCallback 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)

Example 3 with ByteActivityCallback

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

the class Http2ClientProvider method createHttp2Channel.

private static Http2ClientConnection createHttp2Channel(StreamConnection connection, ByteBufferPool bufferPool, OptionMap options, String defaultHost) {
    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;
    }
    Http2Channel http2Channel = new Http2Channel(connection, null, bufferPool, null, true, false, options);
    return new Http2ClientConnection(http2Channel, false, defaultHost, clientStatistics, true);
}
Also used : Http2Channel(io.undertow.protocols.http2.Http2Channel) ByteActivityCallback(io.undertow.conduits.ByteActivityCallback) BytesSentStreamSinkConduit(io.undertow.conduits.BytesSentStreamSinkConduit) BytesReceivedStreamSourceConduit(io.undertow.conduits.BytesReceivedStreamSourceConduit)

Aggregations

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