KickJava   Java API By Example, From Geeks To Geeks.

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

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

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

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

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

403     public void updateLocalNodeVirtualName() throws ProActiveException {
404         try {
405             remoteProActiveRuntime.updateLocalNodeVirtualName();
406         } catch (RemoteException re) {
407             throw new ProActiveException(re);
408         }
409     }
410
411     /* (non-Javadoc)
412      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#listVirtualNodes()
413      */

414     public void listVirtualNodes() throws ProActiveException {
415         try {
416             remoteProActiveRuntime.listVirtualNodes();
417         } catch (RemoteException re) {
418             throw new ProActiveException(re);
419         }
420     }
421
422     /* (non-Javadoc)
423      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getNodePolicyServer(java.lang.String)
424      */

425     public PolicyServer getNodePolicyServer(String JavaDoc nodeName)
426         throws ProActiveException {
427         try {
428             return remoteProActiveRuntime.getNodePolicyServer(nodeName);
429         } catch (RemoteException re) {
430             throw new ProActiveException(re);
431         }
432     }
433
434     /* (non-Javadoc)
435      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#enableSecurityIfNeeded()
436      */

437     public void enableSecurityIfNeeded() throws ProActiveException {
438         try {
439             remoteProActiveRuntime.enableSecurityIfNeeded();
440         } catch (RemoteException re) {
441             throw new ProActiveException(re);
442         }
443     }
444
445     /* (non-Javadoc)
446      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getNodeCertificate(java.lang.String)
447      */

448     public X509Certificate JavaDoc getNodeCertificate(String JavaDoc nodeName)
449         throws ProActiveException {
450         try {
451             return remoteProActiveRuntime.getNodeCertificate(nodeName);
452         } catch (RemoteException re) {
453             throw new ProActiveException(re);
454         }
455     }
456
457     /**
458      * @param nodeName
459      * @return returns all entities associated to the node
460      */

461     public ArrayList JavaDoc getEntities(String JavaDoc nodeName) throws ProActiveException {
462         try {
463             return remoteProActiveRuntime.getEntities(nodeName);
464         } catch (RemoteException re) {
465             throw new ProActiveException(re);
466         }
467     }
468
469     /**
470      * @param nodeName
471      * @return returns all entities associated to the node
472      */

473     public ArrayList JavaDoc getEntities(UniversalBody uBody) throws ProActiveException {
474         try {
475             return remoteProActiveRuntime.getEntities(uBody);
476         } catch (RemoteException re) {
477             throw new ProActiveException(re);
478         }
479     }
480
481     /**
482      * @return returns all entities associated to this runtime
483      */

484     public ArrayList JavaDoc getEntities() throws ProActiveException {
485         try {
486             return remoteProActiveRuntime.getEntities();
487         } catch (RemoteException re) {
488             throw new ProActiveException(re);
489         }
490     }
491
492     /**
493      * @see org.objectweb.proactive.Job#getJobID()
494      */

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