KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > runtime > rmi > RemoteProActiveRuntimeAdapter


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 org.objectweb.proactive.Body;
34 import org.objectweb.proactive.core.ProActiveException;
35 import org.objectweb.proactive.core.body.UniversalBody;
36 import org.objectweb.proactive.core.descriptor.data.VirtualNode;
37 import org.objectweb.proactive.core.mop.ConstructorCall;
38 import org.objectweb.proactive.core.mop.ConstructorCallExecutionFailedException;
39 import org.objectweb.proactive.core.node.NodeException;
40 import org.objectweb.proactive.core.process.UniversalProcess;
41 import org.objectweb.proactive.core.runtime.ProActiveRuntime;
42 import org.objectweb.proactive.core.runtime.VMInformation;
43 import org.objectweb.proactive.ext.security.PolicyServer;
44 import org.objectweb.proactive.ext.security.ProActiveSecurityManager;
45
46 import java.io.IOException JavaDoc;
47 import java.io.Serializable JavaDoc;
48
49 import java.lang.reflect.InvocationTargetException JavaDoc;
50
51 import java.rmi.UnmarshalException JavaDoc;
52
53 import java.security.cert.X509Certificate JavaDoc;
54
55 import java.util.ArrayList JavaDoc;
56
57
58 /**
59  * An adapter for a RemoteProActiveRuntime to be able to receive remote calls. This helps isolate RMI-specific
60  * code into a small set of specific classes, thus enabling reuse if we one day decide to switch
61  * to another remote objects library.
62  * @see <a HREF="http://www.javaworld.com/javaworld/jw-11-2000/jw-1110-smartproxy.html">smartProxy Pattern.</a>
63  */

64 public class RemoteProActiveRuntimeAdapter implements ProActiveRuntime,
65     Serializable JavaDoc {
66     //-----------Protected Members--------------------------------
67
protected RemoteProActiveRuntime remoteProActiveRuntime;
68     protected VMInformation vmInformation;
69     protected String JavaDoc proActiveRuntimeURL;
70
71     //this boolean is used when killing the runtime. Indeed in case of co-allocation, we avoid a second call to the runtime
72
// which is already dead
73
protected boolean alreadykilled = false;
74
75     //
76
// -- Constructors -----------------------------------------------
77
//
78
public RemoteProActiveRuntimeAdapter() throws ProActiveException {
79         try {
80             this.remoteProActiveRuntime = createRemoteProActiveRuntime();
81
82             //System.out.println(remoteProActiveRuntime.getClass().getName());
83
this.vmInformation = remoteProActiveRuntime.getVMInformation();
84             this.proActiveRuntimeURL = remoteProActiveRuntime.getURL();
85         } catch (java.rmi.RemoteException JavaDoc e) {
86             throw new ProActiveException("Cannot create the remoteProactiveRuntime or get the VMInformation from the RemoteProActiveRuntime",
87                 e);
88         } catch (java.rmi.AlreadyBoundException JavaDoc e) {
89             throw new ProActiveException(
90                 "Cannot bind remoteProactiveRuntime to" + proActiveRuntimeURL, e);
91         }
92     }
93
94     public RemoteProActiveRuntimeAdapter(
95         RemoteProActiveRuntime remoteProActiveRuntime)
96         throws ProActiveException {
97         this.remoteProActiveRuntime = remoteProActiveRuntime;
98
99         try {
100             this.vmInformation = remoteProActiveRuntime.getVMInformation();
101             this.proActiveRuntimeURL = remoteProActiveRuntime.getURL();
102         } catch (java.rmi.RemoteException JavaDoc re) {
103             throw new ProActiveException(re);
104         }
105     }
106
107     //
108
// -- PUBLIC METHODS -----------------------------------------------
109
//
110
public boolean equals(Object JavaDoc o) {
111         if (!(o instanceof RemoteProActiveRuntimeAdapter)) {
112             return false;
113         }
114         RemoteProActiveRuntimeAdapter runtime = (RemoteProActiveRuntimeAdapter) o;
115         return remoteProActiveRuntime.equals(runtime.remoteProActiveRuntime);
116     }
117
118     public int hashCode() {
119         return remoteProActiveRuntime.hashCode();
120     }
121
122     //
123
// -- Implements ProActiveRuntime -----------------------------------------------
124
//
125
public String JavaDoc createLocalNode(String JavaDoc nodeName,
126         boolean replacePreviousBinding, PolicyServer ps, String JavaDoc vname, String JavaDoc jobId)
127         throws NodeException {
128         try {
129             return remoteProActiveRuntime.createLocalNode(nodeName,
130                 replacePreviousBinding, ps, vname, jobId);
131         } catch (java.rmi.RemoteException JavaDoc e) {
132             throw new NodeException(e);
133         }
134     }
135
136     public void killAllNodes() throws ProActiveException {
137         try {
138             remoteProActiveRuntime.killAllNodes();
139         } catch (java.rmi.RemoteException JavaDoc re) {
140             throw new ProActiveException(re);
141             // behavior to be defined
142
}
143     }
144
145     public void killNode(String JavaDoc nodeName) throws ProActiveException {
146         try {
147             remoteProActiveRuntime.killNode(nodeName);
148         } catch (java.rmi.RemoteException JavaDoc re) {
149             throw new ProActiveException(re);
150         }
151     }
152
153     // public void createLocalVM(JVMProcess jvmProcess)
154
// throws IOException,ProActiveException
155
// {
156
// try{
157
// remoteProActiveRuntime.createLocalVM(jvmProcess);
158
// }catch(java.rmi.RemoteException re){
159
// throw new ProActiveException(re);
160
// }
161
// }
162
public void createVM(UniversalProcess remoteProcess)
163         throws IOException JavaDoc, ProActiveException {
164         try {
165             remoteProActiveRuntime.createVM(remoteProcess);
166         } catch (java.rmi.RemoteException JavaDoc re) {
167             throw new ProActiveException(re);
168         }
169     }
170
171     // public Node[] getLocalNodes() throws ProActiveException
172
// {
173
// try{
174
// return remoteProActiveRuntime.getLocalNodes();
175
// }catch(java.rmi.RemoteException re){
176
// throw new ProActiveException(re);
177
// // behavior to be defined
178
// }
179
// }
180
public String JavaDoc[] getLocalNodeNames() throws ProActiveException {
181         try {
182             return remoteProActiveRuntime.getLocalNodeNames();
183         } catch (java.rmi.RemoteException JavaDoc re) {
184             throw new ProActiveException(re);
185             // behavior to be defined
186
}
187     }
188
189     // public String getLocalNode(String nodeName) throws ProActiveException
190
// {
191
// try{
192
// return remoteProActiveRuntime.getLocalNode(nodeName);
193
// }catch(java.rmi.RemoteException re){
194
// throw new ProActiveException(re);
195
// // behavior to be defined
196
// }
197
// }
198
//
199
//
200
// public String getNode(String nodeName) throws ProActiveException
201
// {
202
// try{
203
// return remoteProActiveRuntime.getNode(nodeName);
204
// }catch(java.rmi.RemoteException re){
205
// throw new ProActiveException(re);
206
// // behavior to be defined
207
// }
208
// }
209
// public String getDefaultNodeName() throws ProActiveException{
210
// try{
211
// return remoteProActiveRuntime.getDefaultNodeName();
212
// }catch(java.rmi.RemoteException re){
213
// throw new ProActiveException(re);
214
// // behavior to be defined
215
// }
216
// }
217
public VMInformation getVMInformation() {
218         return vmInformation;
219     }
220
221     public void register(ProActiveRuntime proActiveRuntimeDist,
222         String JavaDoc proActiveRuntimeName, String JavaDoc creatorID, String JavaDoc creationProtocol,
223         String JavaDoc vmName) {
224         try {
225             //System.out.println("register in adapter"+remoteProActiveRuntime.getURL());
226
remoteProActiveRuntime.register(proActiveRuntimeDist,
227                 proActiveRuntimeName, creatorID, creationProtocol, vmName);
228         } catch (java.rmi.RemoteException JavaDoc re) {
229             re.printStackTrace();
230             // behavior to be defined
231
}
232     }
233
234     public ProActiveRuntime[] getProActiveRuntimes() throws ProActiveException {
235         try {
236             return remoteProActiveRuntime.getProActiveRuntimes();
237         } catch (java.rmi.RemoteException JavaDoc re) {
238             throw new ProActiveException(re);
239             // behavior to be defined
240
}
241     }
242
243     public ProActiveRuntime getProActiveRuntime(String JavaDoc proActiveRuntimeName)
244         throws ProActiveException {
245         try {
246             return remoteProActiveRuntime.getProActiveRuntime(proActiveRuntimeName);
247         } catch (java.rmi.RemoteException JavaDoc re) {
248             throw new ProActiveException(re);
249             // behavior to be defined
250
}
251     }
252
253     public void killRT(boolean softly) throws Exception JavaDoc {
254         try {
255             if (!alreadykilled) {
256                 remoteProActiveRuntime.killRT(softly);
257             }
258             alreadykilled = true;
259         } catch (UnmarshalException JavaDoc e) {
260             //here should be caught the exception from System.exit
261
alreadykilled = true;
262             throw e;
263         } catch (java.rmi.RemoteException JavaDoc re) {
264             throw new ProActiveException(re);
265         }
266     }
267
268     public String JavaDoc getURL() throws ProActiveException {
269         return proActiveRuntimeURL;
270         // try{
271
// return remoteProActiveRuntime.getURL();
272
// }catch(java.rmi.RemoteException re){
273
// throw new ProActiveException(re);
274
// // behavior to be defined
275
// }
276
}
277
278     public ArrayList JavaDoc getActiveObjects(String JavaDoc nodeName)
279         throws ProActiveException {
280         try {
281             return remoteProActiveRuntime.getActiveObjects(nodeName);
282         } catch (java.rmi.RemoteException JavaDoc re) {
283             throw new ProActiveException(re);
284         }
285     }
286
287     public ArrayList JavaDoc getActiveObjects(String JavaDoc nodeName, String JavaDoc objectName)
288         throws ProActiveException {
289         try {
290             return remoteProActiveRuntime.getActiveObjects(nodeName, objectName);
291         } catch (java.rmi.RemoteException JavaDoc re) {
292             throw new ProActiveException(re);
293         }
294     }
295
296     public VirtualNode getVirtualNode(String JavaDoc virtualNodeName)
297         throws ProActiveException {
298         try {
299             return remoteProActiveRuntime.getVirtualNode(virtualNodeName);
300         } catch (java.rmi.RemoteException JavaDoc re) {
301             throw new ProActiveException(re);
302         }
303     }
304
305     public void registerVirtualNode(String JavaDoc virtualNodeName,
306         boolean replacePreviousBinding) throws ProActiveException {
307         try {
308             remoteProActiveRuntime.registerVirtualNode(virtualNodeName,
309                 replacePreviousBinding);
310         } catch (java.rmi.RemoteException JavaDoc re) {
311             throw new ProActiveException(re);
312         }
313     }
314
315     public void unregisterVirtualNode(String JavaDoc virtualNodeName)
316         throws ProActiveException {
317         try {
318             remoteProActiveRuntime.unregisterVirtualNode(virtualNodeName);
319         } catch (java.rmi.RemoteException JavaDoc re) {
320             throw new ProActiveException(re);
321         }
322     }
323
324     public void unregisterAllVirtualNodes() throws ProActiveException {
325         try {
326             remoteProActiveRuntime.unregisterAllVirtualNodes();
327         } catch (java.rmi.RemoteException JavaDoc re) {
328             throw new ProActiveException(re);
329         }
330     }
331
332     public UniversalBody createBody(String JavaDoc nodeName,
333         ConstructorCall bodyConstructorCall, boolean isNodeLocal)
334         throws ProActiveException, ConstructorCallExecutionFailedException,
335             InvocationTargetException JavaDoc {
336         try {
337             return remoteProActiveRuntime.createBody(nodeName,
338                 bodyConstructorCall, isNodeLocal);
339         } catch (java.rmi.RemoteException JavaDoc re) {
340             throw new ProActiveException(re);
341         }
342     }
343
344     public UniversalBody receiveBody(String JavaDoc nodeName, Body body)
345         throws ProActiveException {
346         try {
347             return remoteProActiveRuntime.receiveBody(nodeName, body);
348         } catch (java.rmi.RemoteException JavaDoc re) {
349             throw new ProActiveException(re);
350         }
351     }
352
353     // SECURITY
354

355     
356     public PolicyServer getPolicyServer() throws ProActiveException {
357         try {
358             return remoteProActiveRuntime.getPolicyServer();
359         } catch (java.rmi.RemoteException JavaDoc re) {
360             throw new ProActiveException(re);
361         }
362     }
363
364     public void setProActiveSecurityManager(ProActiveSecurityManager ps)
365         throws ProActiveException {
366         try {
367             remoteProActiveRuntime.setProActiveSecurityManager(ps);
368         } catch (java.rmi.RemoteException JavaDoc re) {
369             throw new ProActiveException(re);
370         }
371     }
372
373     /* (non-Javadoc)
374      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getCreatorCertificate()
375      */

376     public X509Certificate JavaDoc getCreatorCertificate() throws ProActiveException {
377         try {
378             return remoteProActiveRuntime.getCreatorCertificate();
379         } catch (java.rmi.RemoteException JavaDoc re) {
380             throw new ProActiveException(re);
381         }
382     }
383
384     public String JavaDoc getVNName(String JavaDoc nodename) throws ProActiveException {
385         try {
386             return remoteProActiveRuntime.getVNName(nodename);
387         } catch (java.rmi.RemoteException JavaDoc re) {
388             throw new ProActiveException(re);
389         }
390     }
391
392     /* (non-Javadoc)
393      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#setDefaultNodeVirtualNodeName(java.lang.String)
394      */

395     public void setDefaultNodeVirtualNodeName(String JavaDoc s)
396         throws ProActiveException {
397         try {
398             remoteProActiveRuntime.setDefaultNodeVirtualNodeNAme(s);
399         } catch (java.rmi.RemoteException JavaDoc re) {
400             throw new ProActiveException(re);
401         }
402     }
403
404     /* (non-Javadoc)
405      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#updateLocalNodeVirtualName()
406      */

407     public void listVirtualNodes() throws ProActiveException {
408         try {
409             remoteProActiveRuntime.updateLocalNodeVirtualName();
410         } catch (java.rmi.RemoteException JavaDoc re) {
411             throw new ProActiveException(re);
412         }
413     }
414
415     /* (non-Javadoc)
416      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getNodePolicyServer(java.lang.String)
417      */

418     public PolicyServer getNodePolicyServer(String JavaDoc nodeName)
419         throws ProActiveException {
420         try {
421             return remoteProActiveRuntime.getNodePolicyServer(nodeName);
422         } catch (java.rmi.RemoteException JavaDoc re) {
423             throw new ProActiveException(re);
424         }
425     }
426
427     /* (non-Javadoc)
428      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#enableSecurityIfNeeded()
429      */

430     public void enableSecurityIfNeeded() throws ProActiveException {
431         try {
432             remoteProActiveRuntime.enableSecurityIfNeeded();
433         } catch (java.rmi.RemoteException JavaDoc re) {
434             throw new ProActiveException(re);
435         }
436     }
437
438     /* (non-Javadoc)
439      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getNodeCertificate(java.lang.String)
440      */

441     public X509Certificate JavaDoc getNodeCertificate(String JavaDoc nodeName)
442         throws ProActiveException {
443         try {
444             return remoteProActiveRuntime.getNodeCertificate(nodeName);
445         } catch (java.rmi.RemoteException JavaDoc re) {
446             throw new ProActiveException(re);
447         }
448     }
449
450     /**
451      * @param nodeName
452      * @return returns all entities associated to the node
453      */

454     public ArrayList JavaDoc getEntities(String JavaDoc nodeName) throws ProActiveException {
455         try {
456             return remoteProActiveRuntime.getEntities(nodeName);
457         } catch (java.rmi.RemoteException JavaDoc re) {
458             throw new ProActiveException(re);
459         }
460     }
461
462     /**
463      * @param nodeName
464      * @return returns all entities associated to the node
465      */

466     public ArrayList JavaDoc getEntities(UniversalBody uBody) throws ProActiveException {
467         try {
468             return remoteProActiveRuntime.getEntities(uBody);
469         } catch (java.rmi.RemoteException JavaDoc re) {
470             throw new ProActiveException(re);
471         }
472     }
473
474     /**
475      * @return returns all entities associated to this runtime
476      */

477     public ArrayList JavaDoc getEntities() throws ProActiveException {
478         try {
479             return remoteProActiveRuntime.getEntities();
480         } catch (java.rmi.RemoteException JavaDoc re) {
481             throw new ProActiveException(re);
482         }
483     }
484
485     /**
486      * @see org.objectweb.proactive.Job#getJobID()
487      */

488     public String JavaDoc getJobID() {
489         return vmInformation.getJobID();
490     }
491
492     /**
493      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getJobID(java.lang.String)
494      */

495     public String JavaDoc getJobID(String JavaDoc nodeUrl) throws ProActiveException {
496         try {
497             return remoteProActiveRuntime.getJobID(nodeUrl);
498         } catch (java.rmi.RemoteException JavaDoc re) {
499             throw new ProActiveException(re);
500         }
501     }
502
503     //
504
// -- PROTECTED METHODS -----------------------------------------------
505
//
506
protected RemoteProActiveRuntime createRemoteProActiveRuntime()
507         throws java.rmi.RemoteException JavaDoc, java.rmi.AlreadyBoundException JavaDoc {
508         return new RemoteProActiveRuntimeImpl();
509     }
510 }
511
Popular Tags