Java Code Examples for org.xnio.StreamConnection#getSourceChannel()

The following examples show how to use org.xnio.StreamConnection#getSourceChannel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReadTimeoutStreamSourceConduit.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public ReadTimeoutStreamSourceConduit(final StreamSourceConduit delegate, StreamConnection connection, OpenListener openListener) {
    super(delegate);
    this.connection = connection;
    this.openListener = openListener;
    final ReadReadyHandler handler = new ReadReadyHandler.ChannelListenerHandler<>(connection.getSourceChannel());
    delegate.setReadReadyHandler(new ReadReadyHandler() {
        @Override
        public void readReady() {
            handler.readReady();
        }

        @Override
        public void forceTermination() {
            cleanup();
            handler.forceTermination();
        }

        @Override
        public void terminated() {
            cleanup();
            handler.terminated();
        }
    });
}
 
Example 2
Source File: HttpReadListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void handleHttp2PriorKnowledge(final StreamConnection connection, final HttpServerConnection serverConnection, PooledByteBuffer readData) throws IOException {

        final ConduitStreamSourceChannel request = connection.getSourceChannel();

        byte[] data = new byte[PRI_EXPECTED.length];
        final ByteBuffer buffer = ByteBuffer.wrap(data);
        if(readData.getBuffer().hasRemaining()) {
            while (readData.getBuffer().hasRemaining() && buffer.hasRemaining()) {
                buffer.put(readData.getBuffer().get());
            }
        }
        final PooledByteBuffer extraData;
        if(readData.getBuffer().hasRemaining()) {
            extraData = readData;
        } else {
            readData.close();
            extraData = null;
        }
        if(!doHttp2PriRead(connection, buffer, serverConnection, extraData)) {
            request.getReadSetter().set(new ChannelListener<StreamSourceChannel>() {
                @Override
                public void handleEvent(StreamSourceChannel channel) {
                    try {
                        doHttp2PriRead(connection, buffer, serverConnection, extraData);
                    } catch (IOException e) {
                        UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
                        IoUtils.safeClose(connection);
                    } catch (Throwable t) {
                        UndertowLogger.REQUEST_IO_LOGGER.handleUnexpectedFailure(t);
                        IoUtils.safeClose(connection);
                    }
                }
            });
            request.resumeReads();
        }
    }
 
Example 3
Source File: AbstractXnioSocketChannel.java    From netty-xnio-transport with Apache License 2.0 5 votes vote down vote up
@Override
protected void doBeginRead() throws Exception {
    StreamConnection conn = connection();
    if (conn == null) {
        return;
    }
    ConduitStreamSourceChannel source = conn.getSourceChannel();
    if (!source.isReadResumed()) {
        source.resumeReads();
    }
}