View Javadoc
1   /*
2    * Copyright 2014 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License, version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * copy of the License at:
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software distributed under the License
11   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  package io.netty.handler.codec.http2;
16  
17  import io.netty.buffer.ByteBuf;
18  import io.netty.channel.ChannelFuture;
19  import io.netty.channel.ChannelHandlerContext;
20  import io.netty.channel.ChannelPromise;
21  
22  /**
23   * Manager for the life cycle of the HTTP/2 connection. Handles graceful shutdown of the channel,
24   * closing only after all of the streams have closed.
25   */
26  public interface Http2LifecycleManager {
27  
28      /**
29       * Closes the local side of the given stream. If this causes the stream to be closed, adds a
30       * hook to deactivate the stream and close the channel after the given future completes.
31       *
32       * @param stream the stream to be half closed.
33       * @param future If closing, the future after which to close the channel.
34       */
35      void closeLocalSide(Http2Stream stream, ChannelFuture future);
36  
37      /**
38       * Closes the remote side of the given stream. If this causes the stream to be closed, adds a
39       * hook to deactivate the stream and close the channel after the given future completes.
40       *
41       * @param stream the stream to be half closed.
42       * @param future If closing, the future after which to close the channel.
43       */
44      void closeRemoteSide(Http2Stream stream, ChannelFuture future);
45  
46      /**
47       * Closes the given stream and adds a hook to deactivate the stream and close the channel after
48       * the given future completes.
49       *
50       * @param stream the stream to be closed.
51       * @param future the future after which to close the channel.
52       */
53      void closeStream(Http2Stream stream, ChannelFuture future);
54  
55      /**
56       * Writes a {@code RST_STREAM} frame to the remote endpoint and updates the connection state
57       * appropriately.
58       */
59      ChannelFuture writeRstStream(ChannelHandlerContext ctx, int streamId, long errorCode,
60              ChannelPromise promise);
61  
62      /**
63       * Sends a {@code GO_AWAY} frame to the remote endpoint and updates the connection state
64       * appropriately.
65       */
66      ChannelFuture writeGoAway(ChannelHandlerContext ctx, int lastStreamId, long errorCode,
67              ByteBuf debugData, ChannelPromise promise);
68  
69      /**
70       * Processes the given exception.
71       */
72      void onException(ChannelHandlerContext ctx, Throwable cause);
73  }