marcsaeg 02/04/12 14:15:17
Modified: httpclient/src/java/org/apache/commons/httpclient
HttpMultiClient.java
Log:
Added support for connection timeouts (waiting for HttpConnectionManager
to find a connection) and SO_TIMEOUT values for HttpConnections.
Revision Changes Path
1.3 +60 -7
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMultiClient.java
Index: HttpMultiClient.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMultiClient.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HttpMultiClient.java 15 Mar 2002 23:28:59 -0000 1.2
+++ HttpMultiClient.java 12 Apr 2002 21:15:17 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMultiClient.java,v
1.2 2002/03/15 23:28:59 marcsaeg Exp $
- * $Revision: 1.2 $
- * $Date: 2002/03/15 23:28:59 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMultiClient.java,v
1.3 2002/04/12 21:15:17 marcsaeg Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/04/12 21:15:17 $
* ====================================================================
*
* The Apache Software License, Version 1.1
@@ -87,6 +87,8 @@
private HttpSharedState state = null;
private HttpConnectionManager mgr = new HttpConnectionManager();
private boolean strictMode = true;
+ private int timeoutConnection = 0;
+ private int timeoutRequest = 0;
// ----------------------------------------------------------- Constructors
@@ -103,7 +105,7 @@
/**
* Set the shared state.
*
- * @param state - the new shared state
+ * @param state the new shared state
*
* @see #getState()
*
@@ -156,9 +158,59 @@
}
/**
+ * Sets the connection timeout. The connection timeout is how long (in
milliseconds) HttpMultiClient
+ * will block in executeMethod waiting for connection to the requested server to
+ * become available. Setting the connection timeout to 0 will cause
executeMethod() to
+ * block indefinitely (this is the default behaviour).
+ *
+ * @param timeout the time, in milliseconds, to block waiting for an available
connection
+ * @see #getConnectionTimeout
+ * @see #executeMethod
+ */
+ public void setConnectionTimeout(int timeout)
+ {
+ this.timeoutConnection = timeout;
+ }
+
+ /**
+ * Returns the value of connection timeout.
+ *
+ * @return the connection timeout value
+ * @see #setConnectionTimeout
+ */
+ public int getConnectionTimeout()
+ {
+ return timeoutConnection;
+ }
+
+ /**
+ * Sets the request timeout. The executeMethod method calls
HttpConnection.setSoTimeout()
+ * with this value before executing the request.
+ *
+ * @param timeout the SoTimeout value, in milliseconds
+ * @see #getRequestTimeout
+ * @see HttpConnection#setSoTimeout
+ */
+ public void setRequestTimeout(int timeout)
+ {
+ this.timeoutRequest = timeout;
+ }
+
+ /**
+ * Returns the value of the request timeout.
+ *
+ * @return the request timeout
+ * @see setRequestTimeout
+ */
+ public int getRequestTimeout()
+ {
+ return timeoutRequest;
+ }
+
+ /**
*
* Execute the given {@link HttpUrlMethod} using my current
- * {@link HttpConnection connection} and {@link HttpState}.
+ * {@link HttpConnection connection} and {@link HttpState}.
*
* @param method the {@link HttpMethod} to execute. Must be non-null.
* @return the method's response code
@@ -175,7 +227,8 @@
throw new NullPointerException("method parameter");
}
- HttpConnection connection = mgr.getConnection(method.getUrl());
+ HttpConnection connection = mgr.getConnection(method.getUrl(),
timeoutConnection);
+ connection.setSoTimeout(timeoutRequest);
int status = 0;
@@ -183,7 +236,7 @@
try
{
- status = method.execute(getState(),connection);
+ status = method.execute(getState(), connection);
}
catch (java.io.IOException ex)
{
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>