1 /*
2 * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0.1/httpcore/src/main/java/org/apache/http/params/HttpConnectionParams.java $
3 * $Revision: 744530 $
4 * $Date: 2009-02-14 18:09:27 +0100 (Sat, 14 Feb 2009) $
5 *
6 * ====================================================================
7 * Licensed to the Apache Software Foundation (ASF) under one
8 * or more contributor license agreements. See the NOTICE file
9 * distributed with this work for additional information
10 * regarding copyright ownership. The ASF licenses this file
11 * to you under the Apache License, Version 2.0 (the
12 * "License"); you may not use this file except in compliance
13 * with the License. You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing,
18 * software distributed under the License is distributed on an
19 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20 * KIND, either express or implied. See the License for the
21 * specific language governing permissions and limitations
22 * under the License.
23 * ====================================================================
24 *
25 * This software consists of voluntary contributions made by many
26 * individuals on behalf of the Apache Software Foundation. For more
27 * information on the Apache Software Foundation, please see
28 * <http://www.apache.org/>.
29 *
30 */
31
32 package org.apache.http.params;
33
34 /**
35 * Utility class for accessing connection parameters in {@link HttpParams}.
36 *
37 *
38 * @version $Revision: 744530 $
39 *
40 * @since 4.0
41 */
42 public final class HttpConnectionParams implements CoreConnectionPNames {
43
44 private HttpConnectionParams() {
45 super();
46 }
47
48 /**
49 * Obtains value of the {@link CoreConnectionPNames#SO_TIMEOUT} parameter.
50 * If not set, defaults to <code>0</code>.
51 *
52 * @param params HTTP parameters.
53 * @return SO_TIMEOUT.
54 */
55 public static int getSoTimeout(final HttpParams params) {
56 if (params == null) {
57 throw new IllegalArgumentException("HTTP parameters may not be null");
58 }
59 return params.getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0);
60 }
61
62 /**
63 * Sets value of the {@link CoreConnectionPNames#SO_TIMEOUT} parameter.
64 *
65 * @param params HTTP parameters.
66 * @param timeout SO_TIMEOUT.
67 */
68 public static void setSoTimeout(final HttpParams params, int timeout) {
69 if (params == null) {
70 throw new IllegalArgumentException("HTTP parameters may not be null");
71 }
72 params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout);
73
74 }
75
76 /**
77 * Obtains value of the {@link CoreConnectionPNames#TCP_NODELAY} parameter.
78 * If not set, defaults to <code>true</code>.
79 *
80 * @param params HTTP parameters.
81 * @return Nagle's algorithm flag
82 */
83 public static boolean getTcpNoDelay(final HttpParams params) {
84 if (params == null) {
85 throw new IllegalArgumentException("HTTP parameters may not be null");
86 }
87 return params.getBooleanParameter
88 (CoreConnectionPNames.TCP_NODELAY, true);
89 }
90
91 /**
92 * Sets value of the {@link CoreConnectionPNames#TCP_NODELAY} parameter.
93 *
94 * @param params HTTP parameters.
95 * @param value Nagle's algorithm flag
96 */
97 public static void setTcpNoDelay(final HttpParams params, boolean value) {
98 if (params == null) {
99 throw new IllegalArgumentException("HTTP parameters may not be null");
100 }
101 params.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, value);
102 }
103
104 /**
105 * Obtains value of the {@link CoreConnectionPNames#SOCKET_BUFFER_SIZE}
106 * parameter. If not set, defaults to <code>-1</code>.
107 *
108 * @param params HTTP parameters.
109 * @return socket buffer size
110 */
111 public static int getSocketBufferSize(final HttpParams params) {
112 if (params == null) {
113 throw new IllegalArgumentException("HTTP parameters may not be null");
114 }
115 return params.getIntParameter
116 (CoreConnectionPNames.SOCKET_BUFFER_SIZE, -1);
117 }
118
119 /**
120 * Sets value of the {@link CoreConnectionPNames#SOCKET_BUFFER_SIZE}
121 * parameter.
122 *
123 * @param params HTTP parameters.
124 * @param size socket buffer size
125 */
126 public static void setSocketBufferSize(final HttpParams params, int size) {
127 if (params == null) {
128 throw new IllegalArgumentException("HTTP parameters may not be null");
129 }
130 params.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, size);
131 }
132
133 /**
134 * Obtains value of the {@link CoreConnectionPNames#SO_LINGER} parameter.
135 * If not set, defaults to <code>-1</code>.
136 *
137 * @param params HTTP parameters.
138 * @return SO_LINGER.
139 */
140 public static int getLinger(final HttpParams params) {
141 if (params == null) {
142 throw new IllegalArgumentException("HTTP parameters may not be null");
143 }
144 return params.getIntParameter(CoreConnectionPNames.SO_LINGER, -1);
145 }
146
147 /**
148 * Sets value of the {@link CoreConnectionPNames#SO_LINGER} parameter.
149 *
150 * @param params HTTP parameters.
151 * @param value SO_LINGER.
152 */
153 public static void setLinger(final HttpParams params, int value) {
154 if (params == null) {
155 throw new IllegalArgumentException("HTTP parameters may not be null");
156 }
157 params.setIntParameter(CoreConnectionPNames.SO_LINGER, value);
158 }
159
160 /**
161 * Obtains value of the {@link CoreConnectionPNames#CONNECTION_TIMEOUT}
162 * parameter. If not set, defaults to <code>0</code>.
163 *
164 * @param params HTTP parameters.
165 * @return connect timeout.
166 */
167 public static int getConnectionTimeout(final HttpParams params) {
168 if (params == null) {
169 throw new IllegalArgumentException("HTTP parameters may not be null");
170 }
171 return params.getIntParameter
172 (CoreConnectionPNames.CONNECTION_TIMEOUT, 0);
173 }
174
175 /**
176 * Sets value of the {@link CoreConnectionPNames#CONNECTION_TIMEOUT}
177 * parameter.
178 *
179 * @param params HTTP parameters.
180 * @param timeout connect timeout.
181 */
182 public static void setConnectionTimeout(final HttpParams params, int timeout) {
183 if (params == null) {
184 throw new IllegalArgumentException("HTTP parameters may not be null");
185 }
186 params.setIntParameter
187 (CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
188 }
189
190 /**
191 * Obtains value of the {@link CoreConnectionPNames#STALE_CONNECTION_CHECK}
192 * parameter. If not set, defaults to <code>true</code>.
193 *
194 * @param params HTTP parameters.
195 * @return stale connection check flag.
196 */
197 public static boolean isStaleCheckingEnabled(final HttpParams params) {
198 if (params == null) {
199 throw new IllegalArgumentException("HTTP parameters may not be null");
200 }
201 return params.getBooleanParameter
202 (CoreConnectionPNames.STALE_CONNECTION_CHECK, true);
203 }
204
205 /**
206 * Sets value of the {@link CoreConnectionPNames#STALE_CONNECTION_CHECK}
207 * parameter.
208 *
209 * @param params HTTP parameters.
210 * @param value stale connection check flag.
211 */
212 public static void setStaleCheckingEnabled(final HttpParams params, boolean value) {
213 if (params == null) {
214 throw new IllegalArgumentException("HTTP parameters may not be null");
215 }
216 params.setBooleanParameter
217 (CoreConnectionPNames.STALE_CONNECTION_CHECK, value);
218 }
219
220 }