Examples of StreamSinkChannel


Examples of org.xnio.channels.StreamSinkChannel

    @Override
    public void sendText(CharSequence payload, final SendCallback callback) {
        try {
            final ByteBuffer buffer = WebSocketUtils.fromUtf8String(payload);
            StreamSinkChannel sink = StreamSinkChannelUtils.applyAsyncSendTimeout(session, createSink(buffer.remaining()));
            StreamSinkChannelUtils.send(sink, buffer, callback);
        } catch (IOException e) {
            StreamSinkChannelUtils.safeNotify(callback, e);
        }
    }
View Full Code Here

Examples of org.xnio.channels.StreamSinkChannel

    @Override
    public void sendText(CharSequence payload) throws IOException {
        checkBlockingAllowed();

        final ByteBuffer buffer = WebSocketUtils.fromUtf8String(payload);
        StreamSinkChannel sink = createSink(buffer.remaining());
        StreamSinkChannelUtils.send(sink, buffer);

    }
View Full Code Here

Examples of org.xnio.channels.StreamSinkChannel

                    return;
                }
                if (res == -1) {
                    try {
                        channel.shutdownReads();
                        final StreamSinkChannel responseChannel = connection.getChannel().getSinkChannel();
                        responseChannel.shutdownWrites();
                        // will return false if there's a response queued ahead of this one, so we'll set up a listener then
                        if (!responseChannel.flush()) {
                            responseChannel.getWriteSetter().set(ChannelListeners.flushingChannelListener(null, null));
                            responseChannel.resumeWrites();
                        }
                    } catch (IOException e) {
                        UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
                        // fuck it, it's all ruined
                        IoUtils.safeClose(channel);
View Full Code Here

Examples of org.xnio.channels.StreamSinkChannel

                        return;
                    } else if (res == -1) {
                        try {
                            channel.suspendReads();
                            channel.shutdownReads();
                            final StreamSinkChannel requestChannel = underlyingChannel;
                            requestChannel.shutdownWrites();
                            // will return false if there's a response queued ahead of this one, so we'll set up a listener then
                            if (!requestChannel.flush()) {
                                requestChannel.getWriteSetter().set(ChannelListeners.flushingChannelListener(null, null));
                                requestChannel.resumeWrites();
                            }
                            // Cancel the current active request
                            builder.setFailed(new IOException(MESSAGES.connectionClosed()));
                        } catch (IOException e) {
                            if (UndertowLogger.CLIENT_LOGGER.isDebugEnabled()) {
View Full Code Here

Examples of org.xnio.channels.StreamSinkChannel

    }

    @Override
    public void sendBinary(final ByteBuffer payload, final SendCallback callback) {
        try {
            StreamSinkChannel sink = StreamSinkChannelUtils.applyAsyncSendTimeout(session, createSink(payload.remaining()));

            StreamSinkChannelUtils.send(sink, payload, callback);
        } catch (IOException e) {
            StreamSinkChannelUtils.safeNotify(callback, e);
        }
View Full Code Here

Examples of org.xnio.channels.StreamSinkChannel

    @Override
    public void sendBinary(final ByteBuffer[] payload, final SendCallback callback) {
        try {
            final long length = StreamSinkChannelUtils.payloadLength(payload);
            StreamSinkChannel sink = StreamSinkChannelUtils.applyAsyncSendTimeout(session, createSink(length));
            StreamSinkChannelUtils.send(sink, payload, callback);
        } catch (IOException e) {
            StreamSinkChannelUtils.safeNotify(callback, e);
        }
    }
View Full Code Here

Examples of org.xnio.channels.StreamSinkChannel

    public void sendBinary(final FileChannel payloadChannel, final int offset, final long length, final SendCallback callback) {
        try{
            if (length > payloadChannel.size() - offset) {
                throw WebSocketMessages.MESSAGES.lengthBiggerThenFileChannel();
            }
            StreamSinkChannel sink = StreamSinkChannelUtils.applyAsyncSendTimeout(session, createSink(length));
            long written = 0;
            while (written < length) {
                long w = sink.transferFrom(payloadChannel, offset + written, length - written);
                if (w == 0) {
                    final long writtenBytes = written;
                    sink.getWriteSetter().set(new ChannelListener<StreamSinkChannel>() {
                        long written = writtenBytes;
                        @Override
                        public void handleEvent(StreamSinkChannel sink) {
                            try {
                                while (written < length) {
                                    long w = sink.transferFrom(payloadChannel, offset + written, length - written);
                                    if (w == 0) {
                                        sink.resumeWrites();
                                        return;
                                    }
                                    if (w > 0) {
                                        written += w;
                                    }
                                }
                                StreamSinkChannelUtils.shutdownAndFlush(sink, callback);

                            } catch (IOException e) {
                                StreamSinkChannelUtils.safeNotify(callback, e);
                            }
                        }
                    });
                    sink.resumeWrites();
                    return;
                }
                if (w > 0) {
                    written += w;
                }
View Full Code Here

Examples of org.xnio.channels.StreamSinkChannel

    @Override
    public void sendBinary(ByteBuffer payload) throws IOException {
        checkBlockingAllowed();

        StreamSinkChannel sink = createSink(payload.remaining());
        StreamSinkChannelUtils.send(sink, payload);

    }
View Full Code Here

Examples of org.xnio.channels.StreamSinkChannel

    @Override
    public void sendBinary(ByteBuffer[] payload) throws IOException {
        checkBlockingAllowed();

        long length = StreamSinkChannelUtils.payloadLength(payload);
        StreamSinkChannel sink = createSink(length);
        StreamSinkChannelUtils.send(sink, payload);
    }
View Full Code Here

Examples of org.xnio.channels.StreamSinkChannel

    }

    @Override
    public void sendText(final ByteBuffer payload, final SendCallback callback) {
        try {
            StreamSinkChannel sink = StreamSinkChannelUtils.applyAsyncSendTimeout(session, createSink(payload.remaining()));
            StreamSinkChannelUtils.send(sink, payload, callback);
        } catch (IOException e) {
            StreamSinkChannelUtils.safeNotify(callback, e);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.