KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > rmi > server > transport > http > HttpClientConnectionPool


1 package org.sapia.ubik.rmi.server.transport.http;
2
3 import java.rmi.RemoteException JavaDoc;
4
5 import org.apache.commons.httpclient.HttpClient;
6 import org.sapia.ubik.net.Connection;
7 import org.sapia.ubik.net.Pool;
8 import org.sapia.ubik.net.Uri;
9 import org.sapia.ubik.net.UriSyntaxException;
10 import org.sapia.ubik.rmi.server.transport.Connections;
11 import org.sapia.ubik.rmi.server.transport.RmiConnection;
12
13
14 /**
15  * This class implements the <code>Connections</code> interface over Jakarta's
16  * HTTP client. It does not do pooling, and leaves connection management to the
17  * HTTP client.
18  *
19  * @author Yanick Duchesne
20  * <dl>
21  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2004 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
22  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
23  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
24  * </dl>
25  */

26 public class HttpClientConnectionPool implements Connections {
27   private HttpAddress _address;
28   private HttpClient _client = new HttpClient();
29   private InternalPool _pool = new InternalPool();
30
31   /**
32    * @param address the address of the target server.
33    */

34   public HttpClientConnectionPool(HttpAddress address)
35     throws UriSyntaxException {
36     _address = address;
37   }
38
39   /**
40    * @param transportType the "transport type" identifier.
41    * @param serverUri the address of the target server.
42    */

43   public HttpClientConnectionPool(Uri serverUri) {
44     _address = new HttpAddress(serverUri);
45   }
46
47   /**
48    * @see org.sapia.ubik.rmi.server.transport.Connections#acquire()
49    */

50   public RmiConnection acquire() throws RemoteException JavaDoc {
51     try {
52       return ((HttpRmiClientConnection) _pool.acquire()).setUp(_client, _address);
53     } catch (Exception JavaDoc e) {
54       if (e instanceof RemoteException JavaDoc) {
55         throw (RemoteException JavaDoc) e;
56       }
57
58       throw new RemoteException JavaDoc("Could acquire connection", e);
59     }
60   }
61
62   /**
63    * @see org.sapia.ubik.rmi.server.transport.Connections#clear()
64    */

65   public void clear() {
66   }
67
68   /**
69    * @see org.sapia.ubik.rmi.server.transport.Connections#getTransportType()
70    */

71   public String JavaDoc getTransportType() {
72     return _address.getTransportType();
73   }
74
75   /**
76    * @see org.sapia.ubik.rmi.server.transport.Connections#release(org.sapia.ubik.net.Connection)
77    */

78   public void release(Connection conn) {
79     conn.close();
80     _pool.release(conn);
81   }
82
83   ///// INNER CLASS /////////////////////////////////////////////////////////////
84
static class InternalPool extends Pool {
85     /**
86      * @see org.sapia.ubik.net.Pool#doNewObject()
87      */

88     protected Object JavaDoc doNewObject() throws Exception JavaDoc {
89       return new HttpRmiClientConnection();
90     }
91   }
92 }
93
Popular Tags