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