1 package org.sapia.ubik.rmi.server.transport.http; 2 3 import java.rmi.RemoteException ; 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 26 public class JdkClientConnectionPool implements Connections { 27 private HttpAddress _address; 28 private InternalPool _pool = new InternalPool(); 29 30 34 public JdkClientConnectionPool(HttpAddress address) throws UriSyntaxException { 35 _address = address; 36 } 37 38 42 public JdkClientConnectionPool(String transportType, Uri serverUri) { 43 _address = new HttpAddress(serverUri); 44 } 45 46 49 public RmiConnection acquire() throws RemoteException { 50 try { 51 return ((JdkRmiClientConnection) _pool.acquire()).setUp(_address); 52 } catch (Exception e) { 53 if (e instanceof RemoteException ) { 54 throw (RemoteException ) e; 55 } 56 57 throw new RemoteException ("Could acquire connection", e); 58 } 59 } 60 61 64 public void clear() { 65 } 66 67 70 public String getTransportType() { 71 return _address.getTransportType(); 72 } 73 74 77 public void release(Connection conn) { 78 conn.close(); 79 _pool.release(conn); 80 } 81 82 static class InternalPool extends Pool { 84 87 protected Object doNewObject() throws Exception { 88 return new JdkRmiClientConnection(); 89 } 90 } 91 } 92 | Popular Tags |