1 module hunt.http.codec.http.stream.SessionSPI; 2 3 import hunt.http.codec.http.stream.CloseState; 4 import hunt.http.codec.http.stream.Session; 5 import hunt.http.codec.http.stream.Stream; 6 import hunt.http.codec.http.stream.StreamSPI; 7 8 import hunt.http.codec.http.frame.DataFrame; 9 import hunt.http.codec.http.frame.Frame; 10 import hunt.http.codec.http.frame.PushPromiseFrame; 11 import hunt.http.codec.http.frame.WindowUpdateFrame; 12 13 import hunt.util.Common; 14 import hunt.concurrency.Promise; 15 16 /** 17 * <p>The SPI interface for implementing a HTTP/2 session.</p> 18 * <p>This class :{@link Session} by adding the methods required to 19 * implement the HTTP/2 session functionalities.</p> 20 */ 21 interface SessionSPI : Session { 22 override 23 StreamSPI getStream(int streamId); 24 25 /** 26 * <p>Removes the given {@code stream}.</p> 27 * 28 * @param stream the stream to remove 29 */ 30 void removeStream(StreamSPI stream); 31 32 /** 33 * <p>Enqueues the given frames to be written to the connection.</p> 34 * 35 * @param stream the stream the frames belong to 36 * @param callback the callback that gets notified when the frames have been sent 37 * @param frame the first frame to enqueue 38 * @param frames additional frames to enqueue 39 */ 40 void frames(StreamSPI stream, Callback callback, Frame frame, Frame[] frames... ); 41 42 /** 43 * <p>Enqueues the given PUSH_PROMISE frame to be written to the connection.</p> 44 * <p>Differently from {@link #frames(StreamSPI, Callback, Frame, Frame...)}, this method 45 * generates atomically the stream id for the pushed stream.</p> 46 * 47 * @param stream the stream associated to the pushed stream 48 * @param promise the promise that gets notified of the pushed stream creation 49 * @param frame the PUSH_PROMISE frame to enqueue 50 * @param listener the listener that gets notified of pushed stream events 51 */ 52 void push(StreamSPI stream, Promise!Stream promise, PushPromiseFrame frame, Stream.Listener listener); 53 54 /** 55 * <p>Enqueues the given DATA frame to be written to the connection.</p> 56 * 57 * @param stream the stream the data frame belongs to 58 * @param callback the callback that gets notified when the frame has been sent 59 * @param frame the DATA frame to send 60 */ 61 void data(StreamSPI stream, Callback callback, DataFrame frame); 62 63 /** 64 * <p>Updates the session send window by the given {@code delta}.</p> 65 * 66 * @param delta the delta value (positive or negative) to add to the session send window 67 * @return the previous value of the session send window 68 */ 69 int updateSendWindow(int delta); 70 71 /** 72 * <p>Updates the session receive window by the given {@code delta}.</p> 73 * 74 * @param delta the delta value (positive or negative) to add to the session receive window 75 * @return the previous value of the session receive window 76 */ 77 int updateRecvWindow(int delta); 78 79 /** 80 * <p>Callback method invoked when a WINDOW_UPDATE frame has been received.</p> 81 * 82 * @param stream the stream the window update belongs to, or null if the window update belongs to the session 83 * @param frame the WINDOW_UPDATE frame received 84 */ 85 void onWindowUpdate(StreamSPI stream, WindowUpdateFrame frame); 86 87 /** 88 * @return whether the push functionality is enabled 89 */ 90 bool isPushEnabled(); 91 92 /** 93 * <p>Callback invoked when the connection reads -1.</p> 94 * 95 * @see #onIdleTimeout() 96 * @see #close(int, string, Callback) 97 */ 98 void onShutdown(); 99 100 /** 101 * <p>Callback invoked when the idle timeout expires.</p> 102 * 103 * @see #onShutdown() 104 * @see #close(int, string, Callback) 105 */ 106 bool onIdleTimeout(); 107 108 /** 109 * <p>Callback method invoked during an HTTP/1.1 to HTTP/2 upgrade requests 110 * to process the given synthetic frame.</p> 111 * 112 * @param frame the synthetic frame to process 113 */ 114 void onFrame(Frame frame); 115 116 /** 117 * @return the number of bytes written by this session 118 */ 119 long getBytesWritten(); 120 }