1 31 package org.objectweb.proactive.core.runtime.rmi; 32 33 import java.rmi.RemoteException ; 34 35 import org.objectweb.proactive.core.ProActiveException; 36 import org.objectweb.proactive.core.rmi.ClassServerHelper; 37 import org.objectweb.proactive.core.rmi.RegistryHelper; 38 import org.objectweb.proactive.core.runtime.ProActiveRuntime; 39 import org.objectweb.proactive.core.runtime.RuntimeFactory; 40 import org.objectweb.proactive.core.util.UrlBuilder; 41 42 43 public class RemoteRuntimeFactory extends RuntimeFactory { 44 protected static RegistryHelper registryHelper = new RegistryHelper(); 47 protected static ClassServerHelper classServerHelper = new ClassServerHelper(); 48 private static ProActiveRuntime defaultRmiRuntime = null; 49 50 public RemoteRuntimeFactory() throws java.io.IOException { 54 if ((System.getSecurityManager() == null) && 55 !("false".equals(System.getProperty("proactive.securitymanager")))) { 56 System.setSecurityManager(new java.rmi.RMISecurityManager ()); 57 } 58 } 60 61 public static void setClassServerClasspath(String v) { 65 classServerHelper.setClasspath(v); 66 } 67 68 public static void setShouldCreateClassServer(boolean v) { 69 classServerHelper.setShouldCreateClassServer(v); 70 } 71 72 public static void setRegistryPortNumber(int v) { 73 registryHelper.setRegistryPortNumber(v); 74 } 75 76 public static void setShouldCreateRegistry(boolean v) { 77 registryHelper.setShouldCreateRegistry(v); 78 } 79 80 protected synchronized ProActiveRuntime getProtocolSpecificRuntimeImpl() 87 throws ProActiveException { 88 if (defaultRmiRuntime == null) { 90 try { 91 registryHelper.initializeRegistry(); 92 } catch (RemoteException e) { 93 e.printStackTrace(); 94 } 95 defaultRmiRuntime = createRuntimeAdapter(); 96 } 97 98 return defaultRmiRuntime; 99 } 100 101 protected ProActiveRuntime getRemoteRuntimeImpl(String s) 102 throws ProActiveException { 103 try { 105 RemoteProActiveRuntime remoteProActiveRuntime = (RemoteProActiveRuntime) java.rmi.Naming.lookup(UrlBuilder.removeProtocol( 106 s, "rmi:")); 107 108 return createRuntimeAdapter(remoteProActiveRuntime); 110 } catch (java.rmi.RemoteException e) { 111 throw new ProActiveException("Remote", e); 112 } catch (java.rmi.NotBoundException e) { 113 throw new ProActiveException("NotBound", e); 114 } catch (java.net.MalformedURLException e) { 115 throw new ProActiveException("Malformed URL:" + s, e); 116 } 117 } 118 119 protected RemoteProActiveRuntimeAdapter createRuntimeAdapter( 120 RemoteProActiveRuntime remoteProActiveRuntime) 121 throws ProActiveException { 122 return new RemoteProActiveRuntimeAdapter(remoteProActiveRuntime); 123 } 124 125 protected RemoteProActiveRuntimeAdapter createRuntimeAdapter() 126 throws ProActiveException { 127 return new RemoteProActiveRuntimeAdapter(); 128 } 129 130 public static RegistryHelper getRegistryHelper() { 131 return registryHelper; 132 } 133 134 } 138 | Popular Tags |