KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > runtime > jini > JiniRuntimeAdapter


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.jini;
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
48 import java.lang.reflect.InvocationTargetException JavaDoc;
49
50 import java.rmi.RemoteException JavaDoc;
51
52 import java.security.cert.X509Certificate JavaDoc;
53
54 import java.util.ArrayList JavaDoc;
55
56
57 /**
58  * An adapter for a JiniRuntime to be able to receive remote calls. This helps isolate JINI-specific
59  * code into a small set of specific classes, thus enabling reuse if we one day decide to switch
60  * to another remote objects library.
61  * @see <a HREF="http://www.javaworld.com/javaworld/jw-11-2000/jw-1110-smartproxy.html">smartProxy Pattern.</a>
62  */

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

336     /* (non-Javadoc)
337      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getCreatorCertificate()
338      */

339     public X509Certificate JavaDoc getCreatorCertificate() throws ProActiveException {
340         try {
341             return jiniRuntime.getCreatorCertificate();
342         } catch (RemoteException JavaDoc e) {
343             throw new ProActiveException(e);
344         }
345     }
346
347     /* (non-Javadoc)
348      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getPolicyServer()
349      */

350     public PolicyServer getPolicyServer() throws ProActiveException {
351         try {
352             return jiniRuntime.getPolicyServer();
353         } catch (RemoteException JavaDoc e) {
354             throw new ProActiveException(e);
355         }
356     }
357
358     public String JavaDoc getVNName(String JavaDoc Nodename) throws ProActiveException {
359         try {
360             return jiniRuntime.getVNName(Nodename);
361         } catch (java.rmi.RemoteException JavaDoc re) {
362             throw new ProActiveException(re);
363         }
364     }
365
366     public void setProActiveSecurityManager(ProActiveSecurityManager ps)
367         throws ProActiveException {
368         try {
369             jiniRuntime.setProActiveSecurityManager(ps);
370         } catch (RemoteException JavaDoc e) {
371             throw new ProActiveException(e);
372         }
373     }
374
375     /* (non-Javadoc)
376      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#setDefaultNodeVirtualNodeName(java.lang.String)
377      */

378     public void setDefaultNodeVirtualNodeName(String JavaDoc s)
379         throws ProActiveException {
380         try {
381             jiniRuntime.setDefaultNodeVirtualNodeName(s);
382         } catch (RemoteException JavaDoc e) {
383             throw new ProActiveException(e);
384         }
385     }
386
387     /* (non-Javadoc)
388      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#updateLocalNodeVirtualName()
389      */

390     public void listVirtualNodes() throws ProActiveException {
391         try {
392             jiniRuntime.updateLocalNodeVirtualName();
393         } catch (RemoteException JavaDoc e) {
394             throw new ProActiveException(e);
395         }
396     }
397
398     /* (non-Javadoc)
399      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getNodePolicyServer(java.lang.String)
400      */

401     public PolicyServer getNodePolicyServer(String JavaDoc nodeName)
402         throws ProActiveException {
403         try {
404             return jiniRuntime.getNodePolicyServer(nodeName);
405         } catch (RemoteException JavaDoc e) {
406             throw new ProActiveException(e);
407         }
408     }
409
410     /* (non-Javadoc)
411      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#enableSecurityIfNeeded()
412      */

413     public void enableSecurityIfNeeded() throws ProActiveException {
414         try {
415             jiniRuntime.enableSecurityIfNeeded();
416         } catch (RemoteException JavaDoc e) {
417             throw new ProActiveException(e);
418         }
419     }
420
421     /* (non-Javadoc)
422      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getNodeCertificate(java.lang.String)
423      */

424     public X509Certificate JavaDoc getNodeCertificate(String JavaDoc nodeName)
425         throws ProActiveException {
426         try {
427             return jiniRuntime.getNodeCertificate(nodeName);
428         } catch (RemoteException JavaDoc e) {
429             throw new ProActiveException(e);
430         }
431     }
432
433     /**
434      * @param nodeName
435      * @return returns all entities associated to the node
436      */

437     public ArrayList JavaDoc getEntities(String JavaDoc nodeName) throws ProActiveException {
438         try {
439             return jiniRuntime.getEntities(nodeName);
440         } catch (java.rmi.RemoteException JavaDoc re) {
441             throw new ProActiveException(re);
442         }
443     }
444
445     /**
446      * @param nodeName
447      * @return returns all entities associated to the node
448      */

449     public ArrayList JavaDoc getEntities(UniversalBody uBody) throws ProActiveException {
450         try {
451             return jiniRuntime.getEntities(uBody);
452         } catch (java.rmi.RemoteException JavaDoc re) {
453             throw new ProActiveException(re);
454         }
455     }
456
457     /**
458      * @return returns all entities associated to this runtime
459      */

460     public ArrayList JavaDoc getEntities() throws ProActiveException {
461         try {
462             return jiniRuntime.getEntities();
463         } catch (java.rmi.RemoteException JavaDoc re) {
464             throw new ProActiveException(re);
465         }
466     }
467
468     /**
469      * @see org.objectweb.proactive.Job#getJobID()
470      */

471     public String JavaDoc getJobID() {
472         return vmInformation.getJobID();
473     }
474
475     /**
476      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getJobID(java.lang.String)
477      */

478     public String JavaDoc getJobID(String JavaDoc nodeUrl) throws ProActiveException {
479         try {
480             return jiniRuntime.getJobID(nodeUrl);
481         } catch (java.rmi.RemoteException JavaDoc re) {
482             throw new ProActiveException(re);
483         }
484     }
485
486     //
487
// -- PROTECTED METHODS -----------------------------------------------
488
//
489
protected JiniRuntime createJiniRuntime() throws java.rmi.RemoteException JavaDoc {
490         return new JiniRuntimeImpl();
491     }
492 }
493
Popular Tags