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.http.impl.nio;
29
30 import java.io.IOException;
31
32 import org.apache.http.HttpResponseFactory;
33 import org.apache.http.impl.DefaultHttpResponseFactory;
34 import org.apache.http.impl.nio.reactor.AbstractIODispatch;
35 import org.apache.http.nio.NHttpClientHandler;
36 import org.apache.http.nio.NHttpClientIOTarget;
37 import org.apache.http.nio.reactor.IOSession;
38 import org.apache.http.nio.util.ByteBufferAllocator;
39 import org.apache.http.nio.util.HeapByteBufferAllocator;
40 import org.apache.http.params.HttpConnectionParams;
41 import org.apache.http.params.HttpParams;
42 import org.apache.http.util.Args;
43
44
45
46
47
48
49
50
51
52 @Deprecated
53 public class DefaultClientIOEventDispatch extends AbstractIODispatch<NHttpClientIOTarget> {
54
55 protected final NHttpClientHandler handler;
56 protected final ByteBufferAllocator allocator;
57 protected final HttpParams params;
58
59
60
61
62
63
64
65
66 public DefaultClientIOEventDispatch(
67 final NHttpClientHandler handler,
68 final HttpParams params) {
69 super();
70 Args.notNull(handler, "HTTP client handler");
71 Args.notNull(params, "HTTP parameters");
72 this.allocator = createByteBufferAllocator();
73 this.handler = handler;
74 this.params = params;
75 }
76
77
78
79
80
81
82
83
84
85
86 protected ByteBufferAllocator createByteBufferAllocator() {
87 return HeapByteBufferAllocator.INSTANCE;
88 }
89
90
91
92
93
94
95
96
97
98
99
100 protected HttpResponseFactory createHttpResponseFactory() {
101 return DefaultHttpResponseFactory.INSTANCE;
102 }
103
104
105
106
107
108
109
110
111
112
113
114
115 @Override
116 protected NHttpClientIOTarget createConnection(final IOSession session) {
117 return new DefaultNHttpClientConnection(
118 session,
119 createHttpResponseFactory(),
120 this.allocator,
121 this.params);
122 }
123
124 @Override
125 protected void onConnected(final NHttpClientIOTarget conn) {
126 final int timeout = HttpConnectionParams.getSoTimeout(this.params);
127 conn.setSocketTimeout(timeout);
128
129 final Object attachment = conn.getContext().getAttribute(IOSession.ATTACHMENT_KEY);
130 this.handler.connected(conn, attachment);
131 }
132
133 @Override
134 protected void onClosed(final NHttpClientIOTarget conn) {
135 this.handler.closed(conn);
136 }
137
138 @Override
139 protected void onException(final NHttpClientIOTarget conn, final IOException ex) {
140 this.handler.exception(conn, ex);
141 }
142
143 @Override
144 protected void onInputReady(final NHttpClientIOTarget conn) {
145 conn.consumeInput(this.handler);
146 }
147
148 @Override
149 protected void onOutputReady(final NHttpClientIOTarget conn) {
150 conn.produceOutput(this.handler);
151 }
152
153 @Override
154 protected void onTimeout(final NHttpClientIOTarget conn) {
155 this.handler.timeout(conn);
156 }
157
158 }