1 25 package org.objectweb.carol.jndi.registry; 26 27 import java.io.IOException ; 28 import java.net.ServerSocket ; 29 import java.net.Socket ; 30 import java.rmi.RemoteException ; 31 import java.rmi.server.RMISocketFactory ; 32 33 38 public class RMIFixedPortFirewallSocketFactory extends RMISocketFactory { 39 40 43 private static RMISocketFactory factory = null; 44 45 48 private static ServerSocket exportedObjectfixedSocket = null; 49 50 53 private int exportedObjectsPort; 54 55 59 private RMIFixedPortFirewallSocketFactory(int port) { 60 super(); 61 this.exportedObjectsPort = port; 62 } 63 64 73 public ServerSocket createServerSocket(int port) throws IOException { 74 if (port == 0 && exportedObjectfixedSocket != null) { 75 return exportedObjectfixedSocket; 76 } 77 ServerSocket ss = new ServerSocket (port); 78 if (port == exportedObjectsPort) { 80 exportedObjectfixedSocket = ss; 81 } 82 return ss; 83 } 84 85 93 public Socket createSocket(String host, int port) throws IOException { 94 return new Socket (host, port); 95 } 96 97 103 public static RMISocketFactory register(int port) throws RemoteException { 104 if (factory == null) { 105 factory = new RMIFixedPortFirewallSocketFactory(port); 106 107 try { 109 RMISocketFactory.setSocketFactory(factory); 110 111 } catch (IOException ioe) { 112 throw new RemoteException ("Cannot set the default registry factory :", ioe); 113 } 114 115 116 } 117 return factory; 118 } 119 120 } 121 | Popular Tags |