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.http.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.io.CloseMode;
40  import org.apache.hc.core5.reactor.IOSession;
41  import org.apache.hc.core5.util.Args;
42  import org.apache.hc.core5.util.Timeout;
43  
44  class AbstractHttp1IOEventHandler implements HttpConnectionEventHandler {
45  
46      final AbstractHttp1StreamDuplexer<?, ?> streamDuplexer;
47  
48      AbstractHttp1IOEventHandler(final AbstractHttp1StreamDuplexer<?, ?> streamDuplexer) {
49          this.streamDuplexer = Args.notNull(streamDuplexer, "Stream multiplexer");
50      }
51  
52      @Override
53      public void connected(final IOSession session) throws IOException {
54          try {
55              streamDuplexer.onConnect();
56          } catch (final HttpException ex) {
57              streamDuplexer.onException(ex);
58          }
59      }
60  
61      @Override
62      public void inputReady(final IOSession session, final ByteBuffer src) throws IOException {
63          try {
64              streamDuplexer.onInput(src);
65          } catch (final HttpException ex) {
66              streamDuplexer.onException(ex);
67          }
68      }
69  
70      @Override
71      public void outputReady(final IOSession session) throws IOException {
72          try {
73              streamDuplexer.onOutput();
74          } catch (final HttpException ex) {
75              streamDuplexer.onException(ex);
76          }
77      }
78  
79      @Override
80      public void timeout(final IOSession session, final Timeout timeout) throws IOException {
81          try {
82              streamDuplexer.onTimeout(timeout);
83          } catch (final HttpException ex) {
84              streamDuplexer.onException(ex);
85          }
86      }
87  
88      @Override
89      public void exception(final IOSession session, final Exception cause) {
90          streamDuplexer.onException(cause);
91      }
92  
93      @Override
94      public void disconnected(final IOSession session) {
95          streamDuplexer.onDisconnect();
96      }
97  
98      @Override
99      public void close() throws IOException {
100         streamDuplexer.close();
101     }
102 
103     @Override
104     public void close(final CloseMode closeMode) {
105         streamDuplexer.close(closeMode);
106     }
107 
108     @Override
109     public boolean isOpen() {
110         return streamDuplexer.isOpen();
111     }
112 
113     @Override
114     public void setSocketTimeout(final Timeout timeout) {
115         streamDuplexer.setSocketTimeout(timeout);
116     }
117 
118     @Override
119     public SSLSession getSSLSession() {
120         return streamDuplexer.getSSLSession();
121     }
122 
123     @Override
124     public EndpointDetails getEndpointDetails() {
125         return streamDuplexer.getEndpointDetails();
126     }
127 
128     @Override
129     public Timeout getSocketTimeout() {
130         return streamDuplexer.getSocketTimeout();
131     }
132 
133     @Override
134     public ProtocolVersion getProtocolVersion() {
135         return streamDuplexer.getProtocolVersion();
136     }
137 
138     @Override
139     public SocketAddress getRemoteAddress() {
140         return streamDuplexer.getRemoteAddress();
141     }
142 
143     @Override
144     public SocketAddress getLocalAddress() {
145         return streamDuplexer.getLocalAddress();
146     }
147 
148 }