Class ProtocolStreamListener
- All Implemented Interfaces:
 EventListener, Stream.Listener
- Direct Known Subclasses:
 ProtocolStreamListener.Client, ProtocolStreamListener.Server
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic class - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionprotected abstract StreamEndPointvoidonDataAvailable(Stream stream, boolean immediate) Callback method invoked when the application has expresseddemandfor data carried by STREAM frames, and there are STREAM frames available.voidInvoked when a stream failure is detected.voidonIdleTimeout(Stream stream, TimeoutException failure, Promise.Invocable<Boolean> promise) Invoked when the stream is idle for longer than the idle timeout.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Stream.Listener
onClose, onDataAvailable, onDataBlocked, onMaxData, onNewStream, onReset, onStopSending 
- 
Constructor Details
- 
ProtocolStreamListener
public ProtocolStreamListener() 
 - 
 - 
Method Details
- 
getStreamEndPoint
 - 
onDataAvailable
Description copied from interface:Stream.ListenerCallback 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
Stream.Listener.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
Stream.Listener.onDataAvailable(Stream).- Specified by:
 onDataAvailablein interfaceStream.Listener- 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:
 
 - 
onIdleTimeout
public void onIdleTimeout(Stream stream, TimeoutException failure, Promise.Invocable<Boolean> promise) Description copied from interface:Stream.ListenerInvoked when the stream is idle for longer than the idle timeout.
- Specified by:
 onIdleTimeoutin interfaceStream.Listener- Parameters:
 stream- the streamfailure- the idle timeout failurepromise- the promise to complete to notify the other peer that this stream is closing
 - 
onFailure
Description copied from interface:Stream.ListenerInvoked when a stream failure is detected.
- Specified by:
 onFailurein interfaceStream.Listener- Parameters:
 stream- the streamfailure- the stream failure
 
 -