1 package org.sapia.ubik.net; 2 3 import java.io.IOException ; 4 5 import java.net.Socket ; 6 7 import java.rmi.server.RMIClientSocketFactory ; 8 9 10 20 public class SocketConnectionFactory implements ConnectionFactory { 21 protected ClassLoader _loader; 22 protected RMIClientSocketFactory _clientSocketFactory; 23 24 public SocketConnectionFactory() { 25 this(Thread.currentThread().getContextClassLoader()); 26 } 27 28 public SocketConnectionFactory(RMIClientSocketFactory client) { 29 this(Thread.currentThread().getContextClassLoader()); 30 _clientSocketFactory = client; 31 } 32 33 public SocketConnectionFactory(RMIClientSocketFactory client, 34 ClassLoader loader) { 35 this(loader); 36 _clientSocketFactory = client; 37 } 38 39 public SocketConnectionFactory(ClassLoader loader) { 40 _loader = loader; 41 } 42 43 46 public Connection newConnection(String host, int port) 47 throws IOException { 48 if (_clientSocketFactory == null) { 49 return new SocketConnection(new Socket (host, port), _loader); 50 } else { 51 return new SocketConnection(_clientSocketFactory.createSocket(host, port), 52 _loader); 53 } 54 } 55 56 62 public Connection newConnection(Socket sock) throws IOException { 63 return new SocketConnection(sock, _loader); 64 } 65 } 66 | Popular Tags |