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.http.params;
29
30 import org.apache.http.util.Args;
31
32 /**
33 * Utility class for accessing connection parameters in {@link HttpParams}.
34 *
35 * @since 4.0
36 *
37 * @deprecated (4.3) use configuration classes provided 'org.apache.http.config'
38 * and 'org.apache.http.client.config'
39 */
40 @Deprecated
41 public final class HttpConnectionParams implements CoreConnectionPNames {
42
43 private HttpConnectionParams() {
44 super();
45 }
46
47 /**
48 * Obtains value of the {@link CoreConnectionPNames#SO_TIMEOUT} parameter.
49 * If not set, defaults to <code>0</code>.
50 *
51 * @param params HTTP parameters.
52 * @return SO_TIMEOUT.
53 */
54 public static int getSoTimeout(final HttpParams params) {
55 Args.notNull(params, "HTTP parameters");
56 return params.getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0);
57 }
58
59 /**
60 * Sets value of the {@link CoreConnectionPNames#SO_TIMEOUT} parameter.
61 *
62 * @param params HTTP parameters.
63 * @param timeout SO_TIMEOUT.
64 */
65 public static void setSoTimeout(final HttpParams params, final int timeout) {
66 Args.notNull(params, "HTTP parameters");
67 params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout);
68
69 }
70
71 /**
72 * Obtains value of the {@link CoreConnectionPNames#SO_REUSEADDR} parameter.
73 * If not set, defaults to <code>false</code>.
74 *
75 * @param params HTTP parameters.
76 * @return SO_REUSEADDR.
77 *
78 * @since 4.1
79 */
80 public static boolean getSoReuseaddr(final HttpParams params) {
81 Args.notNull(params, "HTTP parameters");
82 return params.getBooleanParameter(CoreConnectionPNames.SO_REUSEADDR, false);
83 }
84
85 /**
86 * Sets value of the {@link CoreConnectionPNames#SO_REUSEADDR} parameter.
87 *
88 * @param params HTTP parameters.
89 * @param reuseaddr SO_REUSEADDR.
90 *
91 * @since 4.1
92 */
93 public static void setSoReuseaddr(final HttpParams params, final boolean reuseaddr) {
94 Args.notNull(params, "HTTP parameters");
95 params.setBooleanParameter(CoreConnectionPNames.SO_REUSEADDR, reuseaddr);
96 }
97
98 /**
99 * Obtains value of the {@link CoreConnectionPNames#TCP_NODELAY} parameter.
100 * If not set, defaults to <code>true</code>.
101 *
102 * @param params HTTP parameters.
103 * @return Nagle's algorithm flag
104 */
105 public static boolean getTcpNoDelay(final HttpParams params) {
106 Args.notNull(params, "HTTP parameters");
107 return params.getBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true);
108 }
109
110 /**
111 * Sets value of the {@link CoreConnectionPNames#TCP_NODELAY} parameter.
112 *
113 * @param params HTTP parameters.
114 * @param value Nagle's algorithm flag
115 */
116 public static void setTcpNoDelay(final HttpParams params, final boolean value) {
117 Args.notNull(params, "HTTP parameters");
118 params.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, value);
119 }
120
121 /**
122 * Obtains value of the {@link CoreConnectionPNames#SOCKET_BUFFER_SIZE}
123 * parameter. If not set, defaults to <code>-1</code>.
124 *
125 * @param params HTTP parameters.
126 * @return socket buffer size
127 */
128 public static int getSocketBufferSize(final HttpParams params) {
129 Args.notNull(params, "HTTP parameters");
130 return params.getIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, -1);
131 }
132
133 /**
134 * Sets value of the {@link CoreConnectionPNames#SOCKET_BUFFER_SIZE}
135 * parameter.
136 *
137 * @param params HTTP parameters.
138 * @param size socket buffer size
139 */
140 public static void setSocketBufferSize(final HttpParams params, final int size) {
141 Args.notNull(params, "HTTP parameters");
142 params.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, size);
143 }
144
145 /**
146 * Obtains value of the {@link CoreConnectionPNames#SO_LINGER} parameter.
147 * If not set, defaults to <code>-1</code>.
148 *
149 * @param params HTTP parameters.
150 * @return SO_LINGER.
151 */
152 public static int getLinger(final HttpParams params) {
153 Args.notNull(params, "HTTP parameters");
154 return params.getIntParameter(CoreConnectionPNames.SO_LINGER, -1);
155 }
156
157 /**
158 * Sets value of the {@link CoreConnectionPNames#SO_LINGER} parameter.
159 *
160 * @param params HTTP parameters.
161 * @param value SO_LINGER.
162 */
163 public static void setLinger(final HttpParams params, final int value) {
164 Args.notNull(params, "HTTP parameters");
165 params.setIntParameter(CoreConnectionPNames.SO_LINGER, value);
166 }
167
168 /**
169 * Obtains value of the {@link CoreConnectionPNames#CONNECTION_TIMEOUT}
170 * parameter. If not set, defaults to <code>0</code>.
171 *
172 * @param params HTTP parameters.
173 * @return connect timeout.
174 */
175 public static int getConnectionTimeout(final HttpParams params) {
176 Args.notNull(params, "HTTP parameters");
177 return params.getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 0);
178 }
179
180 /**
181 * Sets value of the {@link CoreConnectionPNames#CONNECTION_TIMEOUT}
182 * parameter.
183 *
184 * @param params HTTP parameters.
185 * @param timeout connect timeout.
186 */
187 public static void setConnectionTimeout(final HttpParams params, final int timeout) {
188 Args.notNull(params, "HTTP parameters");
189 params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
190 }
191
192 /**
193 * Obtains value of the {@link CoreConnectionPNames#STALE_CONNECTION_CHECK}
194 * parameter. If not set, defaults to <code>true</code>.
195 *
196 * @param params HTTP parameters.
197 * @return stale connection check flag.
198 */
199 public static boolean isStaleCheckingEnabled(final HttpParams params) {
200 Args.notNull(params, "HTTP parameters");
201 return params.getBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, true);
202 }
203
204 /**
205 * Sets value of the {@link CoreConnectionPNames#STALE_CONNECTION_CHECK}
206 * parameter.
207 *
208 * @param params HTTP parameters.
209 * @param value stale connection check flag.
210 */
211 public static void setStaleCheckingEnabled(final HttpParams params, final boolean value) {
212 Args.notNull(params, "HTTP parameters");
213 params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, value);
214 }
215
216 /**
217 * Obtains value of the {@link CoreConnectionPNames#SO_KEEPALIVE} parameter.
218 * If not set, defaults to <code>false</code>.
219 *
220 * @param params HTTP parameters.
221 * @return SO_KEEPALIVE.
222 *
223 * @since 4.2
224 */
225 public static boolean getSoKeepalive(final HttpParams params) {
226 Args.notNull(params, "HTTP parameters");
227 return params.getBooleanParameter(CoreConnectionPNames.SO_KEEPALIVE, false);
228 }
229
230 /**
231 * Sets value of the {@link CoreConnectionPNames#SO_KEEPALIVE} parameter.
232 *
233 * @param params HTTP parameters.
234 * @param enableKeepalive SO_KEEPALIVE.
235 *
236 * @since 4.2
237 */
238 public static void setSoKeepalive(final HttpParams params, final boolean enableKeepalive) {
239 Args.notNull(params, "HTTP parameters");
240 params.setBooleanParameter(CoreConnectionPNames.SO_KEEPALIVE, enableKeepalive);
241 }
242
243 }