2
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/params/HttpConnectionParams.java,v 1.6 2004/09/15 20:32:21 olegk Exp $
4
* $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
6
* ====================================================================
8
* Licensed to the Apache Software Foundation (ASF) under one or more
9
* contributor license agreements. See the NOTICE file distributed with
10
* this work for additional information regarding copyright ownership.
11
* The ASF licenses this file to You under the Apache License, Version 2.0
12
* (the "License"); you may not use this file except in compliance with
13
* the License. You may obtain a copy of the License at
15
* http://www.apache.org/licenses/LICENSE-2.0
17
* Unless required by applicable law or agreed to in writing, software
18
* distributed under the License is distributed on an "AS IS" BASIS,
19
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
* See the License for the specific language governing permissions and
21
* limitations under the License.
22
* ====================================================================
24
* This software consists of voluntary contributions made by many
25
* individuals on behalf of the Apache Software Foundation. For more
26
* information on the Apache Software Foundation, please see
27
* <http://www.apache.org/>.
31
package org.apache.commons.httpclient.params;
34
* This class represents a collection of HTTP protocol parameters applicable to
35
* {@link org.apache.commons.httpclient.HttpConnection HTTP connections}.
36
* Protocol parameters may be linked together to form a hierarchy. If a particular
37
* parameter value has not been explicitly defined in the collection itself, its
38
* value will be drawn from the parent collection of parameters.
40
* @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
42
* @version $Revision: 480424 $
46
public class HttpConnectionParams extends DefaultHttpParams {
49
* Defines the default socket timeout (<tt>SO_TIMEOUT</tt>) in milliseconds which is the
50
* timeout for waiting for data. A timeout value of zero is interpreted as an infinite
51
* timeout. This value is used when no socket timeout is set in the
52
* {@link HttpMethodParams HTTP method parameters}.
54
* This parameter expects a value of type {@link Integer}.
56
* @see java.net.SocketOptions#SO_TIMEOUT
58
public static final String SO_TIMEOUT = "http.socket.timeout";
61
* Determines whether Nagle's algorithm is to be used. The Nagle's algorithm
62
* tries to conserve bandwidth by minimizing the number of segments that are
63
* sent. When applications wish to decrease network latency and increase
64
* performance, they can disable Nagle's algorithm (that is enable TCP_NODELAY).
65
* Data will be sent earlier, at the cost of an increase in bandwidth consumption.
67
* This parameter expects a value of type {@link Boolean}.
69
* @see java.net.SocketOptions#TCP_NODELAY
71
public static final String TCP_NODELAY = "http.tcp.nodelay";
74
* Determines a hint the size of the underlying buffers used by the platform
75
* for outgoing network I/O. This value is a suggestion to the kernel from
76
* the application about the size of buffers to use for the data to be sent
79
* This parameter expects a value of type {@link Integer}.
81
* @see java.net.SocketOptions#SO_SNDBUF
83
public static final String SO_SNDBUF = "http.socket.sendbuffer";
86
* Determines a hint the size of the underlying buffers used by the platform
87
* for incoming network I/O. This value is a suggestion to the kernel from
88
* the application about the size of buffers to use for the data to be received
91
* This parameter expects a value of type {@link Integer}.
93
* @see java.net.SocketOptions#SO_RCVBUF
95
public static final String SO_RCVBUF = "http.socket.receivebuffer";
98
* Sets SO_LINGER with the specified linger time in seconds. The maximum timeout
99
* value is platform specific. Value <tt>0</tt> implies that the option is disabled.
100
* Value <tt>-1</tt> implies that the JRE default is used. The setting only affects
103
* This parameter expects a value of type {@link Integer}.
105
* @see java.net.SocketOptions#SO_LINGER
107
public static final String SO_LINGER = "http.socket.linger";
110
* Determines the timeout until a connection is etablished. A value of zero
111
* means the timeout is not used. The default value is zero.
113
* This parameter expects a value of type {@link Integer}.
116
public static final String CONNECTION_TIMEOUT = "http.connection.timeout";
119
* Determines whether stale connection check is to be used. Disabling
120
* stale connection check may result in slight performance improvement
121
* at the risk of getting an I/O error when executing a request over a
122
* connection that has been closed at the server side.
124
* This parameter expects a value of type {@link Boolean}.
127
public static final String STALE_CONNECTION_CHECK = "http.connection.stalecheck";
130
* Creates a new collection of parameters with the collection returned
131
* by {@link #getDefaultParams()} as a parent. The collection will defer
132
* to its parent for a default value if a particular parameter is not
133
* explicitly set in the collection itself.
135
* @see #getDefaultParams()
137
public HttpConnectionParams() {
142
* Returns the default socket timeout (<tt>SO_TIMEOUT</tt>) in milliseconds which is the
143
* timeout for waiting for data. A timeout value of zero is interpreted as an infinite
144
* timeout. This value is used when no socket timeout is set in the
145
* {@link HttpMethodParams HTTP method parameters}.
147
* @return timeout in milliseconds
149
public int getSoTimeout() {
150
return getIntParameter(SO_TIMEOUT, 0);
154
* Sets the default socket timeout (<tt>SO_TIMEOUT</tt>) in milliseconds which is the
155
* timeout for waiting for data. A timeout value of zero is interpreted as an infinite
156
* timeout. This value is used when no socket timeout is set in the
157
* {@link HttpMethodParams HTTP method parameters}.
159
* @param timeout Timeout in milliseconds
161
public void setSoTimeout(int timeout) {
162
setIntParameter(SO_TIMEOUT, timeout);
166
* Determines whether Nagle's algorithm is to be used. The Nagle's algorithm
167
* tries to conserve bandwidth by minimizing the number of segments that are
168
* sent. When applications wish to decrease network latency and increase
169
* performance, they can disable Nagle's algorithm (that is enable TCP_NODELAY).
170
* Data will be sent earlier, at the cost of an increase in bandwidth consumption.
172
* @param value <tt>true</tt> if the Nagle's algorithm is to NOT be used
173
* (that is enable TCP_NODELAY), <tt>false</tt> otherwise.
175
public void setTcpNoDelay(boolean value) {
176
setBooleanParameter(TCP_NODELAY, value);
180
* Tests if Nagle's algorithm is to be used.
182
* @return <tt>true</tt> if the Nagle's algorithm is to NOT be used
183
* (that is enable TCP_NODELAY), <tt>false</tt> otherwise.
185
public boolean getTcpNoDelay() {
186
return getBooleanParameter(TCP_NODELAY, true);
190
* Returns a hint the size of the underlying buffers used by the platform for
191
* outgoing network I/O. This value is a suggestion to the kernel from the
192
* application about the size of buffers to use for the data to be sent over
195
* @return the hint size of the send buffer
197
public int getSendBufferSize() {
198
return getIntParameter(SO_SNDBUF, -1);
202
* Sets a hint the size of the underlying buffers used by the platform for
203
* outgoing network I/O. This value is a suggestion to the kernel from the
204
* application about the size of buffers to use for the data to be sent over
207
* @param size the hint size of the send buffer
209
public void setSendBufferSize(int size) {
210
setIntParameter(SO_SNDBUF, size);
214
* Returns a hint the size of the underlying buffers used by the platform
215
* for incoming network I/O. This value is a suggestion to the kernel from
216
* the application about the size of buffers to use for the data to be received
219
* @return the hint size of the send buffer
221
public int getReceiveBufferSize() {
222
return getIntParameter(SO_RCVBUF, -1);
226
* Sets a hint the size of the underlying buffers used by the platform
227
* for incoming network I/O. This value is a suggestion to the kernel from
228
* the application about the size of buffers to use for the data to be received
231
* @param size the hint size of the send buffer
233
public void setReceiveBufferSize(int size) {
234
setIntParameter(SO_RCVBUF, size);
238
* Returns linger-on-close timeout. Value <tt>0</tt> implies that the option is
239
* disabled. Value <tt>-1</tt> implies that the JRE default is used.
241
* @return the linger-on-close timeout
243
public int getLinger() {
244
return getIntParameter(SO_LINGER, -1);
248
* Returns linger-on-close timeout. This option disables/enables immediate return
249
* from a close() of a TCP Socket. Enabling this option with a non-zero Integer
250
* timeout means that a close() will block pending the transmission and
251
* acknowledgement of all data written to the peer, at which point the socket is
252
* closed gracefully. Value <tt>0</tt> implies that the option is
253
* disabled. Value <tt>-1</tt> implies that the JRE default is used.
255
* @param value the linger-on-close timeout
257
public void setLinger(int value) {
258
setIntParameter(SO_LINGER, value);
262
* Returns the timeout until a connection is etablished. A value of zero
263
* means the timeout is not used. The default value is zero.
265
* @return timeout in milliseconds.
267
public int getConnectionTimeout() {
268
return getIntParameter(CONNECTION_TIMEOUT, 0);
272
* Sets the timeout until a connection is etablished. A value of zero
273
* means the timeout is not used. The default value is zero.
275
* @param timeout Timeout in milliseconds.
277
public void setConnectionTimeout(int timeout) {
278
setIntParameter(CONNECTION_TIMEOUT, timeout);
282
* Tests whether stale connection check is to be used. Disabling
283
* stale connection check may result in slight performance improvement
284
* at the risk of getting an I/O error when executing a request over a
285
* connection that has been closed at the server side.
287
* @return <tt>true</tt> if stale connection check is to be used,
288
* <tt>false</tt> otherwise.
290
public boolean isStaleCheckingEnabled() {
291
return getBooleanParameter(STALE_CONNECTION_CHECK, true);
295
* Defines whether stale connection check is to be used. Disabling
296
* stale connection check may result in slight performance improvement
297
* at the risk of getting an I/O error when executing a request over a
298
* connection that has been closed at the server side.
300
* @param value <tt>true</tt> if stale connection check is to be used,
301
* <tt>false</tt> otherwise.
303
public void setStaleCheckingEnabled(boolean value) {
304
setBooleanParameter(STALE_CONNECTION_CHECK, value);