1 7 8 package javax.management.remote.rmi; 9 10 import java.io.IOException ; 11 import java.rmi.NoSuchObjectException ; 12 import java.rmi.Remote ; 13 import java.rmi.RemoteException ; 14 import java.rmi.server.RMIClientSocketFactory ; 15 import java.rmi.server.RMIServerSocketFactory ; 16 import java.rmi.server.UnicastRemoteObject ; 17 import java.rmi.server.RemoteObject ; 18 import java.util.Map ; 19 import java.util.Collections ; 20 import javax.security.auth.Subject ; 21 22 import com.sun.jmx.remote.internal.RMIExporter; 23 24 34 public class RMIJRMPServerImpl extends RMIServerImpl { 35 57 public RMIJRMPServerImpl(int port, 58 RMIClientSocketFactory csf, 59 RMIServerSocketFactory ssf, 60 Map <String ,?> env) 61 throws IOException { 62 63 super(env); 64 65 if (port < 0) 66 throw new IllegalArgumentException ("Negative port: " + port); 67 68 this.port = port; 69 this.csf = csf; 70 this.ssf = ssf; 71 this.env = (env == null) ? Collections.EMPTY_MAP : env; 72 } 73 74 protected void export() throws IOException { 75 export(this); 76 } 77 78 private void export(Remote obj) throws RemoteException { 79 RMIExporter exporter = 80 (RMIExporter) env.get(RMIExporter.EXPORTER_ATTRIBUTE); 81 if (exporter == null) 82 UnicastRemoteObject.exportObject(obj, port, csf, ssf); 83 else 84 exporter.exportObject(obj, port, csf, ssf); 85 } 86 87 private void unexport(Remote obj, boolean force) 88 throws NoSuchObjectException { 89 RMIExporter exporter = 90 (RMIExporter) env.get(RMIExporter.EXPORTER_ATTRIBUTE); 91 if (exporter == null) 92 UnicastRemoteObject.unexportObject(obj, force); 93 else 94 exporter.unexportObject(obj, force); 95 } 96 97 protected String getProtocol() { 98 return "rmi"; 99 } 100 101 109 public Remote toStub() throws IOException { 110 return RemoteObject.toStub(this); 111 } 112 113 131 protected RMIConnection makeClient(String connectionId, Subject subject) 132 throws IOException { 133 134 if (connectionId == null) 135 throw new NullPointerException ("Null connectionId"); 136 137 RMIConnection client = 138 new RMIConnectionImpl (this, connectionId, getDefaultClassLoader(), 139 subject, env); 140 export(client); 141 return client; 142 } 143 144 protected void closeClient(RMIConnection client) throws IOException { 145 unexport(client, true); 146 } 147 148 156 protected void closeServer() throws IOException { 157 unexport(this, true); 158 } 159 160 private final int port; 161 private final RMIClientSocketFactory csf; 162 private final RMIServerSocketFactory ssf; 163 private final Map env; 164 } 165 | Popular Tags |