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