/** * Create a stream channel that compresses to the destination according to the configuration in the given inflater. * * @param delegate the channel to compress to * @param deflater the deflater to use * @return a compressed channel * @throws IOException if the channel could not be constructed */ protected StreamSinkChannel getDeflatingChannel(final StreamSinkChannel delegate, final Deflater deflater) throws IOException { return new ConduitStreamSinkChannel(Configurable.EMPTY, new DeflatingStreamSinkConduit(new StreamSinkChannelWrappingConduit(delegate), deflater)); }
/** * Create a stream channel that decompresses the source data according to the configuration in the given inflater. * * @param delegate the compressed channel * @param inflater the inflater to use * @return a decompressed channel * @throws IOException if the channel could not be constructed */ protected StreamSourceChannel getInflatingChannel(final StreamSourceChannel delegate, final Inflater inflater) throws IOException { return new ConduitStreamSourceChannel(Configurable.EMPTY, new InflatingStreamSourceConduit(new StreamSourceChannelWrappingConduit(delegate), inflater)); }
private long write(final ByteBuffer[] srcs, final int offs, final int len, final boolean writeFinal) throws IOException { if (resumed) return doWrite(srcs, offs, len, writeFinal); long res; while ((res = next.write(srcs, offs, len)) == 0L) { next.awaitWritable(); } return res; }
public Http2ServerConnection(Http2Channel channel, Http2StreamSourceChannel requestChannel, OptionMap undertowOptions, int bufferSize, HttpHandler rootHandler) { this.channel = channel; this.requestChannel = requestChannel; this.undertowOptions = undertowOptions; this.bufferSize = bufferSize; this.rootHandler = rootHandler; responseChannel = requestChannel.getResponseChannel(); originalSinkConduit = new StreamSinkChannelWrappingConduit(responseChannel); originalSourceConduit = new StreamSourceChannelWrappingConduit(requestChannel); this.conduitStreamSinkChannel = new ConduitStreamSinkChannel(responseChannel, originalSinkConduit); this.conduitStreamSourceChannel = new ConduitStreamSourceChannel(channel, originalSourceConduit); }
public IdleTimeoutConduit(StreamConnection connection) { this.sink = connection.getSinkChannel().getConduit(); this.source = connection.getSourceChannel().getConduit(); setWriteReadyHandler(new WriteReadyHandler.ChannelListenerHandler<>(connection.getSinkChannel())); setReadReadyHandler(new ReadReadyHandler.ChannelListenerHandler<>(connection.getSourceChannel())); }
void terminated() { final ReadReadyHandler read = readReadyHandler; if (read != null) read.terminated(); final WriteReadyHandler write = writeReadyHandler; if (write != null) write.terminated(); }
void forceTermination() { final ReadReadyHandler read = readReadyHandler; if (read != null) read.forceTermination(); final WriteReadyHandler write = writeReadyHandler; if (write != null) write.forceTermination(); }
/** * Construct a new instance. * * @param configurable the configurable to delegate configuration requests to * @param conduit the initial conduit to use for data transport */ public ConduitStreamSourceChannel(final Configurable configurable, final StreamSourceConduit conduit) { this.configurable = configurable; this.conduit = conduit; conduit.setReadReadyHandler(new ReadReadyHandler.ChannelListenerHandler<ConduitStreamSourceChannel>(this)); }
/** * Construct a new instance. * * @param configurable the configurable to delegate configuration requests to * @param conduit the initial conduit to use for data transport */ public ConduitStreamSinkChannel(final Configurable configurable, final StreamSinkConduit conduit) { this.configurable = configurable; this.conduit = conduit; conduit.setWriteReadyHandler(new WriteReadyHandler.ChannelListenerHandler<ConduitStreamSinkChannel>(this)); }
@Override public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException { //todo: non-naive implementations of this return Conduits.writeFinalBasic(this, srcs, offset, length); }
private int write(final ByteBuffer src, final boolean writeFinal) throws IOException { if (resumed) { return doWrite(src, writeFinal); } int res; while ((res = doWrite(src, writeFinal)) == 0L) { next.awaitWritable(); } return res; }
/** * Construct a new instance. * * @param configurable the configurable to delegate configuration requests to * @param conduit the initial conduit to use for data transport */ public ConduitWritableMessageChannel(final Configurable configurable, final MessageSinkConduit conduit) { this.configurable = configurable; this.conduit = conduit; conduit.setWriteReadyHandler(new WriteReadyHandler.ChannelListenerHandler<ConduitWritableMessageChannel>(this)); }
/** * Construct a new instance. * * @param configurable the configurable to delegate configuration requests to * @param conduit the initial conduit to use for data transport */ public ConduitReadableMessageChannel(final Configurable configurable, final MessageSourceConduit conduit) { this.configurable = configurable; this.conduit = conduit; conduit.setReadReadyHandler(new ReadReadyHandler.ChannelListenerHandler<ConduitReadableMessageChannel>(this)); }
public long transferFrom(final FileChannel src, final long position, final long count) throws IOException { return flushLocal() ? super.transferFrom(src, position, count) : 0L; }
public boolean flush() throws IOException { return writeBuffer() && next.flush(); }
public boolean flush() throws IOException { return flushLocal() && super.flush(); }
@Override public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException { return next.writeFinal(srcs, offset, length); } }
public void run() { final ReadReadyHandler handler = readReadyHandler; if (handler != null) { handler.readReady(); } } });
public void suspendWrites() { synchronized (lock) { next.suspendWrites(); } }
public void wakeupReads() { synchronized (lock) { next.wakeupReads(); } }