00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.core.runtime.rmi;
00032
00033 import java.rmi.registry.LocateRegistry;
00034 import java.rmi.registry.Registry;
00035
00036 import org.objectweb.proactive.core.ProActiveException;
00037 import org.objectweb.proactive.core.runtime.ProActiveRuntime;
00038 import org.objectweb.proactive.core.runtime.ProActiveRuntimeAdapterForwarderImpl;
00039 import org.objectweb.proactive.core.runtime.ProActiveRuntimeAdapterImpl;
00040 import org.objectweb.proactive.core.runtime.RemoteProActiveRuntime;
00041 import org.objectweb.proactive.core.ssh.rmissh.SshRMIClientSocketFactory;
00042 import org.objectweb.proactive.core.ssh.rmissh.SshRMIServerSocketFactory;
00043 import org.objectweb.proactive.core.util.UrlBuilder;
00044
00045
00049 public class SshRmiRuntimeFactory extends RmiRuntimeFactory {
00050
00051
00052
00053 public SshRmiRuntimeFactory() throws java.io.IOException {
00054 if ((System.getSecurityManager() == null) &&
00055 !("false".equals(System.getProperty("proactive.securitymanager")))) {
00056 System.setSecurityManager(new java.rmi.RMISecurityManager());
00057 }
00058 }
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 protected ProActiveRuntime getRemoteRuntimeImpl(String s)
00076 throws ProActiveException {
00077 String host;
00078 try {
00079 host = UrlBuilder.getHostNameFromUrl(s);
00080 } catch (java.net.UnknownHostException e) {
00081 throw new ProActiveException("Unknown host: " + s, e);
00082 }
00083 int port = UrlBuilder.getPortFromUrl(s);
00084 try {
00085 Registry registry = LocateRegistry.getRegistry(host, port,
00086 new SshRMIClientSocketFactory());
00087 RemoteProActiveRuntime runtimeStub = (RemoteProActiveRuntime) registry.lookup(UrlBuilder.getNameFromUrl(
00088 s));
00089 return createRuntimeAdapter(runtimeStub);
00090 } catch (java.rmi.RemoteException e) {
00091 throw new ProActiveException("Remote", e);
00092 } catch (java.rmi.NotBoundException e) {
00093 throw new ProActiveException("NotBound", e);
00094 }
00095 }
00096
00100 protected ProActiveRuntimeAdapterImpl createRuntimeAdapter()
00101 throws ProActiveException {
00102 RmiProActiveRuntimeImpl impl;
00103 try {
00104 impl = new SshRmiProActiveRuntimeImpl(new SshRMIClientSocketFactory(),
00105 new SshRMIServerSocketFactory());
00106 } catch (java.rmi.RemoteException e) {
00107 throw new ProActiveException("Cannot create the RemoteProActiveRuntimeImpl",
00108 e);
00109 } catch (java.rmi.AlreadyBoundException e) {
00110 throw new ProActiveException("Cannot bind remoteProactiveRuntime", e);
00111 }
00112 return new ProActiveRuntimeAdapterImpl(impl);
00113 }
00114
00115 protected ProActiveRuntimeAdapterForwarderImpl createRuntimeAdapterForwarder()
00116 throws ProActiveException {
00117 RmiSshProActiveRuntimeForwarder impl;
00118 try {
00119 impl = new RmiSshProActiveRuntimeForwarder(new SshRMIClientSocketFactory(),
00120 new SshRMIServerSocketFactory());
00121 } catch (java.rmi.RemoteException e) {
00122 throw new ProActiveException("Cannot create the RemoteProActiveRuntimeImpl",
00123 e);
00124 } catch (java.rmi.AlreadyBoundException e) {
00125 throw new ProActiveException("Cannot bind remoteProactiveRuntime", e);
00126 }
00127 return new ProActiveRuntimeAdapterForwarderImpl(impl);
00128 }
00129 }