KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > runtime > rmi > 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.rmi;
32
33 import java.rmi.RemoteException JavaDoc;
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 final static int MAX_RETRY = 5;
45
//protected java.util.Random random;
46
protected static RegistryHelper registryHelper = new RegistryHelper();
47     protected static ClassServerHelper classServerHelper = new ClassServerHelper();
48     private static ProActiveRuntime defaultRmiRuntime = null;
49
50     //
51
// -- CONSTRUCTORS -----------------------------------------------
52
//
53
public RemoteRuntimeFactory() throws java.io.IOException JavaDoc {
54         if ((System.getSecurityManager() == null) &&
55                 !("false".equals(System.getProperty("proactive.securitymanager")))) {
56             System.setSecurityManager(new java.rmi.RMISecurityManager JavaDoc());
57         }
58         //registryHelper.initializeRegistry();
59
}
60
61     //
62
// -- PUBLIC METHODS -----------------------------------------------
63
//
64
public static void setClassServerClasspath(String JavaDoc 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     //
81
// -- PROTECTED METHODS -----------------------------------------------
82
//
83
// protected ProActiveRuntime createRemoteRuntimeImpl(String s, boolean replacePreviousBinding) throws ProActiveException {
84
// return createRuntimeAdapter(s, replacePreviousBinding);
85
// }
86
protected synchronized ProActiveRuntime getProtocolSpecificRuntimeImpl()
87         throws ProActiveException {
88         //return createRuntimeAdapter(s,false);
89
if (defaultRmiRuntime == null) {
90             try {
91                 registryHelper.initializeRegistry();
92             } catch (RemoteException JavaDoc e) {
93                 e.printStackTrace();
94             }
95             defaultRmiRuntime = createRuntimeAdapter();
96         }
97
98         return defaultRmiRuntime;
99     }
100
101     protected ProActiveRuntime getRemoteRuntimeImpl(String JavaDoc s)
102         throws ProActiveException {
103         //if (s == null) return null;
104
try {
105             RemoteProActiveRuntime remoteProActiveRuntime = (RemoteProActiveRuntime) java.rmi.Naming.lookup(UrlBuilder.removeProtocol(
106                         s, "rmi:"));
107
108             //System.out.println(remoteProActiveRuntime.getClass().getName());
109
return createRuntimeAdapter(remoteProActiveRuntime);
110         } catch (java.rmi.RemoteException JavaDoc e) {
111             throw new ProActiveException("Remote", e);
112         } catch (java.rmi.NotBoundException JavaDoc e) {
113             throw new ProActiveException("NotBound", e);
114         } catch (java.net.MalformedURLException JavaDoc 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     //
135
// -- PRIVATE METHODS -----------------------------------------------
136
//
137
}
138
Popular Tags