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)
is invoked.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
Invoked when the stream has beenclosed
.default void
onDataAvailable
(Stream stream) Callback method invoked when the application has expresseddemand
for data carried by STREAM frames, and there are STREAM frames available.default void
onDataBlocked
(Stream stream, StreamDataBlockedFrame frame) Invoked when a STREAM_DATA_BLOCKED frame has been received.default void
Invoked when a stream failure is detected.default void
onIdleTimeout
(Stream stream, TimeoutException failure, Promise.Invocable<Boolean> promise) Invoked when the stream is idle for longer than the idle timeout.default void
onMaxData
(Stream stream, StreamMaxDataFrame frame) Invoked when a MAX_STREAM_DATA frame has been received.default void
onNewStream
(Stream stream, Frame.WithStreamId frame) Callback method invoked when receiving a frame that causes the creation of a new stream.default void
onReset
(Stream stream, ResetFrame frame) Invoked when a RESET_STREAM frame has been received.default void
onStopSending
(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
Callback method invoked when the application has expressed
demand
for 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 aStream
viaSession.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) { 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; } } } }
- Parameters:
stream
- the stream- 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
-