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 package org.apache.http.impl.nio;
28
29 import org.apache.http.HttpResponseFactory;
30 import org.apache.http.annotation.Immutable;
31 import org.apache.http.impl.DefaultHttpResponseFactory;
32 import org.apache.http.nio.NHttpClientConnection;
33 import org.apache.http.nio.NHttpConnectionFactory;
34 import org.apache.http.nio.reactor.IOSession;
35 import org.apache.http.nio.util.ByteBufferAllocator;
36 import org.apache.http.nio.util.HeapByteBufferAllocator;
37 import org.apache.http.params.HttpConnectionParams;
38 import org.apache.http.params.HttpParams;
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 @Immutable
56 public class DefaultNHttpClientConnectionFactory
57 implements NHttpConnectionFactory<DefaultNHttpClientConnection> {
58
59 private final HttpResponseFactory responseFactory;
60 private final ByteBufferAllocator allocator;
61 private final HttpParams params;
62
63 public DefaultNHttpClientConnectionFactory(
64 final HttpResponseFactory responseFactory,
65 final ByteBufferAllocator allocator,
66 final HttpParams params) {
67 super();
68 if (responseFactory == null) {
69 throw new IllegalArgumentException("HTTP response factory may not be null");
70 }
71 if (allocator == null) {
72 throw new IllegalArgumentException("Byte buffer allocator may not be null");
73 }
74 if (params == null) {
75 throw new IllegalArgumentException("HTTP parameters may not be null");
76 }
77 this.responseFactory = responseFactory;
78 this.allocator = allocator;
79 this.params = params;
80 }
81
82 public DefaultNHttpClientConnectionFactory(final HttpParams params) {
83 this(new DefaultHttpResponseFactory(), new HeapByteBufferAllocator(), params);
84 }
85
86 protected DefaultNHttpClientConnection createConnection(
87 final IOSession session,
88 final HttpResponseFactory responseFactory,
89 final ByteBufferAllocator allocator,
90 final HttpParams params) {
91 return new DefaultNHttpClientConnection(session, responseFactory, allocator, params);
92 }
93
94 public DefaultNHttpClientConnection createConnection(final IOSession session) {
95 DefaultNHttpClientConnection conn = createConnection(session, this.responseFactory, this.allocator, this.params);
96 int timeout = HttpConnectionParams.getSoTimeout(this.params);
97 conn.setSocketTimeout(timeout);
98 return conn;
99 }
100
101 }