View Javadoc
1   /*
2    * Copyright 2015 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    * https://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 static io.netty.util.internal.ObjectUtil.checkNotNull;
18  
19  /**
20   * A decorator around another {@link Http2ConnectionEncoder} instance.
21   */
22  public class DecoratingHttp2ConnectionEncoder extends DecoratingHttp2FrameWriter implements Http2ConnectionEncoder,
23          Http2SettingsReceivedConsumer {
24      private final Http2ConnectionEncoder delegate;
25  
26      public DecoratingHttp2ConnectionEncoder(Http2ConnectionEncoder delegate) {
27          super(delegate);
28          this.delegate = checkNotNull(delegate, "delegate");
29      }
30  
31      @Override
32      public void lifecycleManager(Http2LifecycleManager lifecycleManager) {
33          delegate.lifecycleManager(lifecycleManager);
34      }
35  
36      @Override
37      public Http2Connection connection() {
38          return delegate.connection();
39      }
40  
41      @Override
42      public Http2RemoteFlowController flowController() {
43          return delegate.flowController();
44      }
45  
46      @Override
47      public Http2FrameWriter frameWriter() {
48          return delegate.frameWriter();
49      }
50  
51      @Override
52      public Http2Settings pollSentSettings() {
53          return delegate.pollSentSettings();
54      }
55  
56      @Override
57      public void remoteSettings(Http2Settings settings) throws Http2Exception {
58          delegate.remoteSettings(settings);
59      }
60  
61      @Override
62      public void consumeReceivedSettings(Http2Settings settings) {
63          if (delegate instanceof Http2SettingsReceivedConsumer) {
64              ((Http2SettingsReceivedConsumer) delegate).consumeReceivedSettings(settings);
65          } else {
66              throw new IllegalStateException("delegate " + delegate + " is not an instance of " +
67                      Http2SettingsReceivedConsumer.class);
68          }
69      }
70  }