00001 /* 00002 * ################################################################ 00003 * 00004 * ProActive: The Java(TM) library for Parallel, Distributed, 00005 * Concurrent computing with Security and Mobility 00006 * 00007 * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis 00008 * Contact: proactive@objectweb.org 00009 * 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2.1 of the License, or any later version. 00014 * 00015 * This library is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public 00021 * License along with this library; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 * USA 00024 * 00025 * Initial developer(s): The ProActive Team 00026 * http://www.inria.fr/oasis/ProActive/contacts.html 00027 * Contributor(s): 00028 * 00029 * ################################################################ 00030 */ 00031 package org.objectweb.proactive.core.runtime.ibis; 00032 00033 import org.objectweb.proactive.core.ProActiveException; 00034 import org.objectweb.proactive.core.rmi.ClassServerHelper; 00035 import org.objectweb.proactive.core.rmi.RegistryHelper; 00036 import org.objectweb.proactive.core.runtime.ProActiveRuntime; 00037 import org.objectweb.proactive.core.runtime.ProActiveRuntimeAdapterImpl; 00038 import org.objectweb.proactive.core.runtime.RemoteProActiveRuntime; 00039 import org.objectweb.proactive.core.runtime.RuntimeFactory; 00040 import org.objectweb.proactive.core.util.IbisProperties; 00041 import org.objectweb.proactive.core.util.UrlBuilder; 00042 00043 import ibis.rmi.AlreadyBoundException; 00044 import ibis.rmi.RemoteException; 00045 00046 00047 public class IbisRuntimeFactory extends RuntimeFactory { 00048 00049 static { 00050 IbisProperties.load(); 00051 } 00052 00053 //protected final static int MAX_RETRY = 5; 00054 //protected java.util.Random random; 00055 protected static RegistryHelper registryHelper = new RegistryHelper(); 00056 protected static ClassServerHelper classServerHelper = new ClassServerHelper(); 00057 private static ProActiveRuntime defaultRmiRuntime = null; 00058 00059 // 00060 // -- CONSTRUCTORS ----------------------------------------------- 00061 // 00062 public IbisRuntimeFactory() throws java.io.IOException { 00063 if ((System.getSecurityManager() == null) && 00064 !("false".equals(System.getProperty("proactive.securitymanager")))) { 00065 System.setSecurityManager(new java.rmi.RMISecurityManager()); 00066 } 00067 00068 registryHelper.initializeRegistry(); 00069 } 00070 00071 // 00072 // -- PUBLIC METHODS ----------------------------------------------- 00073 // 00074 public static void setClassServerClasspath(String v) { 00075 classServerHelper.setClasspath(v); 00076 } 00077 00078 public static void setShouldCreateClassServer(boolean v) { 00079 classServerHelper.setShouldCreateClassServer(v); 00080 } 00081 00082 public static void setRegistryPortNumber(int v) { 00083 registryHelper.setRegistryPortNumber(v); 00084 } 00085 00086 public static void setShouldCreateRegistry(boolean v) { 00087 registryHelper.setShouldCreateRegistry(v); 00088 } 00089 00090 // 00091 // -- PROTECTED METHODS ----------------------------------------------- 00092 // 00093 // protected ProActiveRuntime createRemoteRuntimeImpl(String s, boolean replacePreviousBinding) throws ProActiveException { 00094 // return createRuntimeAdapter(s, replacePreviousBinding); 00095 // } 00096 protected synchronized ProActiveRuntime getProtocolSpecificRuntimeImpl() 00097 throws ProActiveException { 00098 //return createRuntimeAdapter(s,false); 00099 if (defaultRmiRuntime == null) { 00100 defaultRmiRuntime = createRuntimeAdapter(); 00101 } 00102 00103 return defaultRmiRuntime; 00104 } 00105 00106 protected ProActiveRuntime getRemoteRuntimeImpl(String s) 00107 throws ProActiveException { 00108 //if (s == null) return null; 00109 if (runtimeLogger.isDebugEnabled()) { 00110 runtimeLogger.debug("looking for " + s); 00111 } 00112 00113 try { 00114 RemoteProActiveRuntime remoteProActiveRuntime = (RemoteProActiveRuntime) ibis.rmi.Naming.lookup(UrlBuilder.removeProtocol( 00115 s, "ibis:")); 00116 00117 if (runtimeLogger.isDebugEnabled()) { 00118 runtimeLogger.debug(remoteProActiveRuntime.getClass().getName()); 00119 } 00120 00121 return createRuntimeAdapter(remoteProActiveRuntime); 00122 } catch (ibis.rmi.RemoteException e) { 00123 throw new ProActiveException("Remote", e); 00124 } catch (ibis.rmi.NotBoundException e) { 00125 throw new ProActiveException("NotBound", e); 00126 } catch (java.net.MalformedURLException e) { 00127 throw new ProActiveException("Malformed URL:" + s, e); 00128 } 00129 } 00130 00131 protected ProActiveRuntimeAdapterImpl createRuntimeAdapter() 00132 throws ProActiveException { 00133 IbisProActiveRuntimeImpl impl; 00134 00135 try { 00136 impl = new IbisProActiveRuntimeImpl(); 00137 } catch (RemoteException e) { 00138 throw new ProActiveException("Cannot create the RemoteProActiveRuntimeImpl", 00139 e); 00140 } catch (AlreadyBoundException e) { 00141 throw new ProActiveException("Cannot bind remoteProactiveRuntime", e); 00142 } 00143 00144 return new ProActiveRuntimeAdapterImpl(impl); 00145 } 00146 00147 protected static RegistryHelper getRegistryHelper() { 00148 return registryHelper; 00149 } 00150 00151 // 00152 // -- PRIVATE METHODS ----------------------------------------------- 00153 // 00154 }