1 package com.maverick.multiplex; 2 3 import java.io.IOException ; 4 import java.net.InetAddress ; 5 import java.net.Socket ; 6 import java.net.UnknownHostException ; 7 8 public class MultiplexedSocketFactory implements SocketFactory { 9 10 static SocketFactory instance; 11 static Class factoryImpl = MultiplexedSocketFactory.class; 12 13 public static SocketFactory getDefault() { 14 try { 15 return instance == null ? instance = (SocketFactory) factoryImpl.newInstance() : instance; 16 } catch (Throwable t) { 17 return instance == null ? instance = new MultiplexedSocketFactory() : instance; 18 } 19 } 20 21 public static void setFactoryImpl(Class factoryImpl) { 22 MultiplexedSocketFactory.factoryImpl = factoryImpl; 23 instance = null; 24 } 25 26 public Socket createSocket(String host, int port) throws IOException , UnknownHostException { 27 return new Socket (host, port); 28 } 29 30 public Socket createSocket(InetAddress host, int port) throws IOException { 31 return new Socket (host, port); 32 } 33 34 public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException , 35 UnknownHostException { 36 return new Socket (host, port, localHost, localPort); 37 } 38 39 public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException { 40 return new Socket (address, port, localAddress, localPort); 41 } 42 }
| Popular Tags
|