Interface Stream.Listener
- All Superinterfaces:
 EventListener
- All Known Implementing Classes:
 ProtocolStreamListener, ProtocolStreamListener.Client, ProtocolStreamListener.Server
- Enclosing interface:
 Stream
A Stream.Listener is the passive counterpart of a Stream
and receives events, triggered by the remote peer, happening on stream.
Stream data is requested using Stream.demand() and when data
is available onDataAvailable(Stream, boolean) is invoked.
- See Also:
 
- 
Method Summary
Modifier and TypeMethodDescriptiondefault voidInvoked when the stream has beenclosed.default voidonDataAvailable(Stream stream) A simplified version ofonDataAvailable(Stream, boolean).default voidonDataAvailable(Stream stream, boolean immediate) Callback method invoked when the application has expresseddemandfor data carried by STREAM frames, and there are STREAM frames available.default voidonDataBlocked(Stream stream, StreamDataBlockedFrame frame) Invoked when a STREAM_DATA_BLOCKED frame has been received.default voidInvoked when a stream failure is detected.default voidonIdleTimeout(Stream stream, TimeoutException failure, Promise.Invocable<Boolean> promise) Invoked when the stream is idle for longer than the idle timeout.default voidonMaxData(Stream stream, StreamMaxDataFrame frame) Invoked when a MAX_STREAM_DATA frame has been received.default voidonNewStream(Stream stream, Frame.WithStreamId frame) Callback method invoked when receiving a frame that causes the creation of a new stream.default voidonReset(Stream stream, ResetFrame frame) Invoked when a RESET_STREAM frame has been received.default voidonStopSending(Stream stream, StopSendingFrame frame) Invoked when a STOP_SENDING frame has been received. 
- 
Method Details
- 
onNewStream
Callback method invoked when receiving a frame that causes the creation of a new stream.
- Parameters:
 stream- the newly created streamframe- the frame that caused the creation of the stream
 - 
onDataAvailable
A simplified version of
onDataAvailable(Stream, boolean).The default implementation of this method reads and discards data.
- Parameters:
 stream- the stream- See Also:
 
 - 
onDataAvailable
Callback method invoked when the application has expressed
demandfor data carried by STREAM frames, and there are STREAM frames available.Server applications should typically demand from
onNewStream(Stream, Frame.WithStreamId)(upon receiving the first stream frame), while client applications should typically demand after obtaining aStreamviaSession.newStream(long, Listener).Just prior calling this method, the outstanding demand is cancelled; applications that implement this method should read content calling
Stream.read(), and callStream.demand()to signal to the implementation to call again this method when there may be more data available.Only one thread at a time invokes this method, although it may not be the same thread across different invocations.
It is always guaranteed that invoking
Stream.demand()from within this method will not cause aStackOverflowError.Typical usage:
class MyStreamListener implements Stream.Listener { @Override public void onDataAvailable(Stream stream, boolean immediate) { while (true) { // Read a chunk of the content. Content.Chunk chunk = stream.read(); if (chunk == null) { // No data available now, demand to be called back. stream.demand(); return; } // Process the content chunk. process(chunk); // Notify that the content has been consumed. chunk.release(); if (chunk.isLast()) { // All data has been processed. return; } } } }The default implementation of this method calls
onDataAvailable(Stream).- Parameters:
 stream- the streamimmediate-truewhen data is immediately available at the timeStream.demand()is invoked (this method is directly invoked fromStream.demand();falsewhen data was not immediately available at the timeStream.demand()was called, but is now available (this method is invoked from the network layer, not directly fromStream.demand()- See Also:
 
 - 
onDataBlocked
Invoked when a STREAM_DATA_BLOCKED frame has been received.
This event is only emitted for informational purposes.
- Parameters:
 stream- the streamframe- the frame
 - 
onMaxData
Invoked when a MAX_STREAM_DATA frame has been received.
This event is only emitted for informational purposes.
- Parameters:
 stream- the streamframe- the frame
 - 
onStopSending
Invoked when a STOP_SENDING frame has been received.
This event is only emitted for informational purposes.
- Parameters:
 stream- the streamframe- the frame
 - 
onReset
Invoked when a RESET_STREAM frame has been received.
This event is only emitted for informational purposes.
- Parameters:
 stream- the streamframe- the frame
 - 
onClose
Invoked when the stream has been
closed.A stream is closed when either:
- The receiving side read the last frame in the stream, and the sending side sent the last frame in the stream
 - The stream is 
disconnected, for example due to failures. 
- Parameters:
 stream- the stream
 - 
onIdleTimeout
default void onIdleTimeout(Stream stream, TimeoutException failure, Promise.Invocable<Boolean> promise) Invoked when the stream is idle for longer than the idle timeout.
- Parameters:
 stream- the streamfailure- the idle timeout failurepromise- the promise to complete to notify the other peer that this stream is closing
 - 
onFailure
 
 -