1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 }