jericho 01/05/05 00:00:48
Modified: src/webdav/client/src/org/apache/webdav/lib
WebdavSession.java
Log:
- Back to the past!
- Follow the http 1.1 spec not to support multiple connections.
- We're allowed an http client instance with the same credentials
to the same server. I hope It's resonable. ^^
- If you want to use more than 1 connection, you should get to work
with an http connection on another VM. Thanks to Remy the comment. :)
Revision Changes Path
1.6 +57 -55
jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavSession.java
Index: WebdavSession.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavSession.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- WebdavSession.java 2001/05/04 08:16:11 1.5
+++ WebdavSession.java 2001/05/05 07:00:48 1.6
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavSession.java,v
1.5 2001/05/04 08:16:11 jericho Exp $
- * $Revision: 1.5 $
- * $Date: 2001/05/04 08:16:11 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavSession.java,v
1.6 2001/05/05 07:00:48 jericho Exp $
+ * $Revision: 1.6 $
+ * $Date: 2001/05/05 07:00:48 $
*
* ====================================================================
*
@@ -64,6 +64,7 @@
package org.apache.webdav.lib;
import java.io.IOException;
+import java.util.Hashtable;
import java.util.Vector;
import java.util.Enumeration;
import java.net.MalformedURLException;
@@ -77,6 +78,14 @@
* This WebdavSession class is for the multi-session management of
* WebDAV clients. This class saves and restores the requested client.
*
+ * Clients that use persistent connections SHOULD limit the number of
+ * simultaneous connections that they maintain to a given server. A
+ * single-user client SHOULD NOT maintain more than 2 connections with
+ * any server or proxy. A proxy SHOULD use up to 2*N connections to
+ * another server or proxy, where N is the number of simultaneously
+ * active users. These guidelines are intended to improve HTTP response
+ * times and avoid congestion.
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Park, Sung-Gu</a>
*/
public class WebdavSession {
@@ -87,7 +96,7 @@
/**
* Infomation hashtable for WebDAV clients HTTP/1.1 communication.
*/
- private static Vector clientInfo = new Vector();
+ private static Hashtable clientInfo = new Hashtable();
/**
@@ -124,25 +133,24 @@
* @return An instance of <code>HttpClient</code>.
* @exception IOException
*/
- public HttpClient getSessionInstance(HttpURL httpURL)
+ public synchronized HttpClient getSessionInstance(HttpURL httpURL)
throws IOException {
-
- synchronized (clientInfo) {
- HttpClient client = new HttpClient();
- client.startSession(httpURL.toURL());
+
+ String authority = httpURL.getAuthority();
+ HttpClient client = (HttpClient) clientInfo.get(authority);
+ if (client == null) {
+ client = new HttpClient();
+ client.startSession(httpURL.getHost(), httpURL.getPort());
String userName = httpURL.getUserName();
if (userName != null && userName.length() > 0) {
String password = httpURL.getPassword();
client.setCredentials(new Credentials(userName, password));
- }
- //client.getProgressUtil().addProgressListener(this);
- String authority = httpURL.getAuthority();
- if (!clientInfo.contains(authority)) {
- clientInfo.addElement(authority);
}
-
- return client;
+ clientInfo.put(authority, client);
}
+ //client.getProgressUtil().addProgressListener(this);
+
+ return client;
}
@@ -156,22 +164,26 @@
public boolean isSession(HttpURL httpURL)
throws MalformedURLException {
- String authority = httpURL.getAuthority();
- return isSession(authority);
+ return isSession(httpURL.getAuthority());
}
- /**
+ /**
* Test a session to be connected.
*
* @param authority The authority string.
* @return true if connected aleady.
* @exception MalformedURLException
*/
- public boolean isSession(String authority) {
- synchronized (clientInfo) {
- return (clientInfo.contains(authority)) ? true : false;
+ public synchronized boolean isSession(String authority) {
+
+ Enumeration authorities = clientInfo.keys();
+ while (authorities.hasMoreElements()) {
+ if (authority.equals((String) authorities.nextElement())) {
+ return true;
+ }
}
+ return false;
}
@@ -180,22 +192,20 @@
* The <code>partOfAuthority</code> can be user or host part.
*
* @param partOfAuthority The part of the authority string.
- * @return Authorities to have the given string.
+ * @return Authorities to include the given string.
*/
- public Enumeration findSessions(String partOfAuthority) {
-
- synchronized (clientInfo) {
- Vector sessions = new Vector();
- Enumeration authorities = clientInfo.elements();
- while (authorities.hasMoreElements()) {
- String authority = (String) authorities.nextElement();
- if (authority.indexOf(partOfAuthority) >= 0) {
- sessions.addElement(authority);
- }
+ public synchronized Enumeration findSessions(String partOfAuthority) {
+
+ Vector sessions = new Vector();
+ Enumeration authorities = clientInfo.keys();
+ while (authorities.hasMoreElements()) {
+ String authority = (String) authorities.nextElement();
+ if (authority.indexOf(partOfAuthority) >= 0) {
+ sessions.addElement(authority);
}
-
- return sessions.elements();
}
+
+ return sessions.elements();
}
@@ -204,37 +214,29 @@
*
* @return Authorities of all session.
*/
- public Enumeration getSessions() {
- synchronized (clientInfo) {
- return clientInfo.elements();
- }
+ public synchronized Enumeration getSessions() {
+ return clientInfo.keys();
}
- /**
+ /**
* Close an session and delete the connection information.
*
* @param client The HttpClient instance.
* @exception IOException Error in closing socket.
*/
- public void closeSession(HttpClient client)
+ public synchronized void closeSession(HttpClient client)
throws IOException {
- synchronized (clientInfo) {
- HttpURL httpURL =
- new HttpURL(client.getUserName(), client.getPassword(),
- client.getHost(), client.getPort());
- String authority = httpURL.getAuthority();
- if (isSession(authority)) {
- clientInfo.removeElement(authority);
- // Remove the progress listener.
- //webdavClient.getProgressUtil().addProgressListener(this);
- }
-
- client.endSession();
- }
+ client.endSession();
+ HttpURL httpURL =
+ new HttpURL(client.getUserName(), client.getPassword(),
+ client.getHost(), client.getPort());
+ clientInfo.remove(httpURL.getAuthority());
+ // Remove the progress listener.
+ // webdavClient.getProgressUtil().addProgressListener(this);
}
-
+
/**
* Progressing by the progress event.