View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.hc.core5.http2.impl.nio;
29  
30  import java.io.IOException;
31  import java.net.SocketAddress;
32  import java.nio.ByteBuffer;
33  
34  import javax.net.ssl.SSLSession;
35  
36  import org.apache.hc.core5.http.EndpointDetails;
37  import org.apache.hc.core5.http.HttpException;
38  import org.apache.hc.core5.http.ProtocolVersion;
39  import org.apache.hc.core5.http.impl.nio.HttpConnectionEventHandler;
40  import org.apache.hc.core5.io.CloseMode;
41  import org.apache.hc.core5.reactor.IOSession;
42  import org.apache.hc.core5.util.Args;
43  import org.apache.hc.core5.util.Timeout;
44  
45  class AbstractH2IOEventHandler implements HttpConnectionEventHandler {
46  
47      final AbstractH2StreamMultiplexer streamMultiplexer;
48  
49      AbstractH2IOEventHandler(final AbstractH2StreamMultiplexer streamMultiplexer) {
50          this.streamMultiplexer = Args.notNull(streamMultiplexer, "Stream multiplexer");
51      }
52  
53      @Override
54      public void connected(final IOSession session) throws IOException {
55          try {
56              streamMultiplexer.onConnect();
57          } catch (final HttpException ex) {
58              streamMultiplexer.onException(ex);
59          }
60      }
61  
62      @Override
63      public void inputReady(final IOSession session, final ByteBuffer src) throws IOException {
64          try {
65              streamMultiplexer.onInput(src);
66          } catch (final HttpException ex) {
67              streamMultiplexer.onException(ex);
68          }
69      }
70  
71      @Override
72      public void outputReady(final IOSession session) throws IOException {
73          try {
74              streamMultiplexer.onOutput();
75          } catch (final HttpException ex) {
76              streamMultiplexer.onException(ex);
77          }
78      }
79  
80      @Override
81      public void timeout(final IOSession session, final Timeout timeout) throws IOException {
82          try {
83              streamMultiplexer.onTimeout(timeout);
84          } catch (final HttpException ex) {
85              streamMultiplexer.onException(ex);
86          }
87      }
88  
89      @Override
90      public void exception(final IOSession session, final Exception cause) {
91          streamMultiplexer.onException(cause);
92      }
93  
94      @Override
95      public void disconnected(final IOSession session) {
96          streamMultiplexer.onDisconnect();
97      }
98  
99      @Override
100     public void close() throws IOException {
101         streamMultiplexer.close();
102     }
103 
104     @Override
105     public void close(final CloseMode closeMode) {
106         streamMultiplexer.close(closeMode);
107     }
108 
109     @Override
110     public boolean isOpen() {
111         return streamMultiplexer.isOpen();
112     }
113 
114     @Override
115     public void setSocketTimeout(final Timeout timeout) {
116         streamMultiplexer.setSocketTimeout(timeout);
117     }
118 
119     @Override
120     public SSLSession getSSLSession() {
121         return streamMultiplexer.getSSLSession();
122     }
123 
124     @Override
125     public EndpointDetails getEndpointDetails() {
126         return streamMultiplexer.getEndpointDetails();
127     }
128 
129     @Override
130     public Timeout getSocketTimeout() {
131         return streamMultiplexer.getSocketTimeout();
132     }
133 
134     @Override
135     public ProtocolVersion getProtocolVersion() {
136         return streamMultiplexer.getProtocolVersion();
137     }
138 
139     @Override
140     public SocketAddress getRemoteAddress() {
141         return streamMultiplexer.getRemoteAddress();
142     }
143 
144     @Override
145     public SocketAddress getLocalAddress() {
146         return streamMultiplexer.getLocalAddress();
147     }
148 
149 }