Interface Stream.Server.Listener
- Enclosing interface:
Stream.Server
A Stream.Server.Listener is the passive counterpart of a Stream.Server
and receives server-side events happening on an HTTP/3 stream.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidonDataAvailable(Stream.Server stream) A simplified version ofonDataAvailable(Stream.Server, boolean).default voidonDataAvailable(Stream.Server stream, boolean immediate) Callback method invoked if the application has expresseddemandfor content, and if there may be content available.default voidonFailure(Stream.Server stream, long error, Throwable failure) Callback method invoked when a stream failure occurred.default voidonIdleTimeout(Stream.Server stream, TimeoutException failure, Promise<Boolean> promise) Callback method invoked when the stream idle timeout elapses.default voidonTrailer(Stream.Server stream, HeadersFrame frame) Callback method invoked when a trailer is received.
-
Method Details
-
onDataAvailable
A simplified version of
onDataAvailable(Stream.Server, boolean).The default implementation of this method reads and discards data.
- Parameters:
stream- the stream- See Also:
-
onDataAvailable
Callback method invoked if the application has expressed
demandfor content, and if there may be content available.A server application that wishes to handle request content should typically call
Stream.demand()fromSession.Server.Listener.onRequest(Server, HeadersFrame).A client application that wishes to handle response content should typically call
Stream.demand()fromStream.Client.Listener.onResponse(Client, HeadersFrame).Just prior calling this method, the outstanding demand is cancelled; applications that implement this method should read content calling
Stream.readData(), and callStream.demand()to signal to the implementation to call again this method when there may be more content 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.Server.Listener { @Override public void onDataAvailable(Stream.Server stream, boolean immediate) { // Read a chunk of the content. Stream.Data data = stream.readData(); if (data == null) { // No data available now, demand to be called back. stream.demand(); } else { // Process the content. process(data.getByteBuffer()); // Notify that the content has been consumed. data.release(); if (!data.isLast()) { // Demand to be called back. stream.demand(); } } } }The default implementation of this method calls
onDataAvailable(Stream.Server).- 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:
-
onTrailer
Callback method invoked when a trailer is received.
- Parameters:
stream- the streamframe- the HEADERS frame containing the trailer headers
-
onIdleTimeout
default void onIdleTimeout(Stream.Server stream, TimeoutException failure, Promise<Boolean> promise) Callback method invoked when the stream idle timeout elapses.
- Parameters:
stream- the streamfailure- the timeout failurepromise- the promise to complete with true to reset the stream, false to ignore the idle timeout
-
onFailure
Callback method invoked when a stream failure occurred.
Typical stream failures, among others, are failures to decode a HEADERS frame, or failures to read bytes because the stream has been reset.
- Parameters:
stream- the streamerror- the failure errorfailure- the cause of the failure
-