KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > runtime > ibis > RemoteRuntimeFactory


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

31 package org.objectweb.proactive.core.runtime.ibis;
32
33 import org.apache.log4j.Logger;
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.IbisProperties;
41 import org.objectweb.proactive.core.util.UrlBuilder;
42
43
44 public class RemoteRuntimeFactory extends RuntimeFactory {
45     protected static Logger logger = Logger.getLogger(RemoteRuntimeFactory.class.getName());
46
47     static {
48         IbisProperties.load();
49     }
50
51     //protected final static int MAX_RETRY = 5;
52
//protected java.util.Random random;
53
protected static RegistryHelper registryHelper = new RegistryHelper();
54     protected static ClassServerHelper classServerHelper = new ClassServerHelper();
55     private static ProActiveRuntime defaultRmiRuntime = null;
56
57     //
58
// -- CONSTRUCTORS -----------------------------------------------
59
//
60
public RemoteRuntimeFactory() throws java.io.IOException JavaDoc {
61         if ((System.getSecurityManager() == null) &&
62                 !("false".equals(System.getProperty("proactive.securitymanager")))) {
63             System.setSecurityManager(new java.rmi.RMISecurityManager JavaDoc());
64         }
65
66         registryHelper.initializeRegistry();
67     }
68
69     //
70
// -- PUBLIC METHODS -----------------------------------------------
71
//
72
public static void setClassServerClasspath(String JavaDoc v) {
73         classServerHelper.setClasspath(v);
74     }
75
76     public static void setShouldCreateClassServer(boolean v) {
77         classServerHelper.setShouldCreateClassServer(v);
78     }
79
80     public static void setRegistryPortNumber(int v) {
81         registryHelper.setRegistryPortNumber(v);
82     }
83
84     public static void setShouldCreateRegistry(boolean v) {
85         registryHelper.setShouldCreateRegistry(v);
86     }
87
88     //
89
// -- PROTECTED METHODS -----------------------------------------------
90
//
91
// protected ProActiveRuntime createRemoteRuntimeImpl(String s, boolean replacePreviousBinding) throws ProActiveException {
92
// return createRuntimeAdapter(s, replacePreviousBinding);
93
// }
94
protected synchronized ProActiveRuntime getProtocolSpecificRuntimeImpl()
95         throws ProActiveException {
96         //return createRuntimeAdapter(s,false);
97
if (defaultRmiRuntime == null) {
98             defaultRmiRuntime = createRuntimeAdapter();
99         }
100
101         return defaultRmiRuntime;
102     }
103
104     protected ProActiveRuntime getRemoteRuntimeImpl(String JavaDoc s)
105         throws ProActiveException {
106         //if (s == null) return null;
107
if (logger.isDebugEnabled()) {
108             logger.debug("looking for " + s);
109         }
110         try {
111             RemoteProActiveRuntime remoteProActiveRuntime = (RemoteProActiveRuntime) ibis.rmi.Naming.lookup(UrlBuilder.removeProtocol(s,"ibis:"));
112             if (logger.isDebugEnabled()) {
113                 logger.debug(remoteProActiveRuntime.getClass().getName());
114             }
115             return createRuntimeAdapter(remoteProActiveRuntime);
116         } catch (ibis.rmi.RemoteException e) {
117             throw new ProActiveException("Remote", e);
118         } catch (ibis.rmi.NotBoundException e) {
119             throw new ProActiveException("NotBound", e);
120         } catch (java.net.MalformedURLException JavaDoc e) {
121             throw new ProActiveException("Malformed URL:" + s, e);
122         }
123     }
124
125     protected RemoteProActiveRuntimeAdapter createRuntimeAdapter(
126         RemoteProActiveRuntime remoteProActiveRuntime)
127         throws ProActiveException {
128         return new RemoteProActiveRuntimeAdapter(remoteProActiveRuntime);
129     }
130
131     protected RemoteProActiveRuntimeAdapter createRuntimeAdapter()
132         throws ProActiveException {
133         return new RemoteProActiveRuntimeAdapter();
134     }
135
136     protected static RegistryHelper getRegistryHelper() {
137         return registryHelper;
138     }
139
140     //
141
// -- PRIVATE METHODS -----------------------------------------------
142
//
143
}
144
Popular Tags