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