KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.sapia.ubik.rmi.server.transport.http;
2
3 import java.rmi.RemoteException JavaDoc;
4
5 import org.sapia.ubik.net.Connection;
6 import org.sapia.ubik.net.Pool;
7 import org.sapia.ubik.net.Uri;
8 import org.sapia.ubik.net.UriSyntaxException;
9 import org.sapia.ubik.rmi.server.transport.Connections;
10 import org.sapia.ubik.rmi.server.transport.RmiConnection;
11
12
13 /**
14  * This class implements the <code>Connections</code> interface over the JDK's
15  * HTTP support classes (<code>URL</code>, <code>HttpURLConnection</code>). It is
16  * a sub-optimal implementation used only if the Jakarta HTTP client classes are not
17  * in the classpath.
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 JdkClientConnectionPool implements Connections {
27   private HttpAddress _address;
28   private InternalPool _pool = new InternalPool();
29
30   /**
31    * @param transportType the "transport type" identifier.
32    * @param address the address of the target server.
33    */

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

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

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

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

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

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

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