KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > runtime > ProActiveRuntimeImpl


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;
32
33 //
34
import org.objectweb.proactive.Body;
35 import org.objectweb.proactive.core.UniqueID;
36 import org.objectweb.proactive.core.body.LocalBodyStore;
37 import org.objectweb.proactive.core.body.UniversalBody;
38 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
39 import org.objectweb.proactive.core.descriptor.data.VirtualNode;
40 import org.objectweb.proactive.core.descriptor.data.VirtualNodeImpl;
41 import org.objectweb.proactive.core.event.RuntimeRegistrationEvent;
42 import org.objectweb.proactive.core.event.RuntimeRegistrationEventProducerImpl;
43 import org.objectweb.proactive.core.mop.ConstructorCall;
44 import org.objectweb.proactive.core.mop.ConstructorCallExecutionFailedException;
45 import org.objectweb.proactive.core.node.NodeException;
46 import org.objectweb.proactive.core.process.UniversalProcess;
47 import org.objectweb.proactive.core.util.UrlBuilder;
48 import org.objectweb.proactive.ext.security.Entity;
49 import org.objectweb.proactive.ext.security.EntityCertificate;
50 import org.objectweb.proactive.ext.security.EntityVirtualNode;
51 import org.objectweb.proactive.ext.security.PolicyServer;
52 import org.objectweb.proactive.ext.security.ProActiveSecurityManager;
53 import org.objectweb.proactive.ext.security.SecurityNotAvailableException;
54
55 import java.io.File JavaDoc;
56 import java.io.IOException JavaDoc;
57
58 import java.security.PrivateKey JavaDoc;
59 import java.security.Provider JavaDoc;
60 import java.security.Security JavaDoc;
61 import java.security.cert.X509Certificate JavaDoc;
62
63 import java.util.ArrayList JavaDoc;
64 import java.util.Enumeration JavaDoc;
65 import java.util.Hashtable JavaDoc;
66 import java.util.Random JavaDoc;
67
68
69 /**
70  * <p>
71  * Implementation of ProActiveRuntime
72  * </p>
73  *
74  * @author ProActive Team
75  * @version 1.0, 2001/10/23
76  * @since ProActive 0.91
77  *
78  */

79 public class ProActiveRuntimeImpl extends RuntimeRegistrationEventProducerImpl
80     implements ProActiveRuntime {
81     //
82
// -- STATIC MEMBERS -----------------------------------------------------------
83
//
84
//the Unique instance of ProActiveRuntime
85
private static ProActiveRuntime proActiveRuntime = new ProActiveRuntimeImpl();
86     private static Random JavaDoc prng = null; // new Random();
87

88     private static synchronized int getNextInt() {
89         if (prng == null) {
90             prng = new Random JavaDoc();
91         }
92         return prng.nextInt();
93     }
94
95     // map nodes and an ArrayList of PolicyServer
96
private java.util.Hashtable JavaDoc policyServerMap;
97
98     // creator certificate
99
private X509Certificate JavaDoc creatorCertificate;
100     private X509Certificate JavaDoc certificate;
101     private PrivateKey JavaDoc privateKey;
102
103     // link to domain policy server
104
// private PolicyServer policyServer;
105
private ProActiveSecurityManager psm;
106     private String JavaDoc defaultNodeVirtualNode = null;
107
108     //
109
// -- PRIVATE MEMBERS -----------------------------------------------------------
110
//
111
private VMInformation vmInformation;
112
113     // map nodes and an ArrayList of Active Objects Id
114
private java.util.Hashtable JavaDoc nodeMap;
115
116     // map nodes and their job id;
117
private Hashtable JavaDoc nodeJobIdMap;
118
119     //map VirtualNodes and their names
120
private java.util.Hashtable JavaDoc virtualNodesMap;
121
122     //map descriptor and their url
123
private java.util.Hashtable JavaDoc descriptorMap;
124
125     // map proActiveRuntime registered on this VM and their names
126
private java.util.Hashtable JavaDoc proActiveRuntimeMap;
127
128     //
129
// -- CONSTRUCTORS -----------------------------------------------------------
130
//
131
// singleton
132
private ProActiveRuntimeImpl() {
133         try {
134             this.nodeMap = new java.util.Hashtable JavaDoc();
135
136             this.vmInformation = new VMInformationImpl();
137             this.proActiveRuntimeMap = new java.util.Hashtable JavaDoc();
138             this.virtualNodesMap = new java.util.Hashtable JavaDoc();
139             this.descriptorMap = new java.util.Hashtable JavaDoc();
140             this.policyServerMap = new java.util.Hashtable JavaDoc();
141             this.nodeJobIdMap = new java.util.Hashtable JavaDoc();
142             String JavaDoc file = System.getProperties().getProperty("proactive.runtime.security");
143
144             if ((file != null) && new File JavaDoc(file).exists()) {
145                 // loading security from a file
146
logger.info("Runtime : loading policy file" + file);
147                 Provider JavaDoc myProvider = new org.bouncycastle.jce.provider.BouncyCastleProvider();
148                 Security.addProvider(myProvider);
149                 // policyServer = ProActiveSecurityDescriptorHandler.createPolicyServer(file);
150
psm = new ProActiveSecurityManager(file);
151             } else {
152                 // creating a generic certificate
153
logger.info("Runtime : loading policy file is null");
154                 //Object[] tmp = ProActiveSecurity.generateGenericCertificate();
155
//certificate = (X509Certificate) tmp[0];
156
//privateKey = (PrivateKey) tmp[1];
157
}
158
159             //System.out.println(vmInformation.getVMID().toString());
160
} catch (java.net.UnknownHostException JavaDoc e) {
161             //System.out.println();
162
logger.fatal(" !!! Cannot do a reverse lookup on that host");
163             // System.out.println();
164
e.printStackTrace();
165             System.exit(1);
166         } catch (IOException JavaDoc e) {
167             e.printStackTrace();
168         }
169     }
170
171     //
172
// -- PUBLIC METHODS -----------------------------------------------------------
173
//
174
public static ProActiveRuntime getProActiveRuntime() {
175         return proActiveRuntime;
176     }
177
178     /**
179      * Register the given VirtualNode on this ProActiveRuntime. This method cannot be called remotely.
180      * @param vn the virtualnode to register
181      * @param vnname the name of the VirtualNode to register
182      */

183     public void registerLocalVirtualNode(VirtualNode vn, String JavaDoc vnName) {
184         //System.out.println("vn "+vnName+" registered");
185
virtualNodesMap.put(vnName, vn);
186     }
187
188     public void registerDescriptor(String JavaDoc url, ProActiveDescriptor pad) {
189         descriptorMap.put(url, pad);
190     }
191
192     public ProActiveDescriptor getDescriptor(String JavaDoc url) {
193         return (ProActiveDescriptor) descriptorMap.get(url);
194     }
195
196     public void removeDescriptor(String JavaDoc url) {
197         descriptorMap.remove(url);
198     }
199
200     //
201
// -- Implements ProActiveRuntime -----------------------------------------------
202
//
203

204     /**
205      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#createLocalNode(String, boolean, PolicyServer, String, String)
206      */

207     public String JavaDoc createLocalNode(String JavaDoc nodeName,
208         boolean replacePreviousBinding, PolicyServer ps, String JavaDoc vnName,
209         String JavaDoc jobId) throws NodeException {
210         //Node node = new NodeImpl(this,nodeName);
211
//System.out.println("node created with name "+nodeName+"on proActiveruntime "+this);
212
if (replacePreviousBinding) {
213             if (nodeMap.get(nodeName) != null) {
214                 nodeMap.remove(nodeName);
215                 nodeJobIdMap.remove(nodeName);
216             }
217         }
218         if (!replacePreviousBinding && (nodeMap.get(nodeName) != null)) {
219             throw new NodeException("Node " + nodeName +
220                 " already created on this ProActiveRuntime. To overwrite this node, use true for replacePreviousBinding");
221         }
222
223         nodeMap.put(nodeName, new java.util.ArrayList JavaDoc());
224         nodeJobIdMap.put(nodeName, jobId);
225
226         if ((vnName != null) && (vnName.equals("currentJVM"))) {
227             // if Jvm has been started using the currentJVM tag
228
vnName = defaultNodeVirtualNode;
229             logger.debug(
230                 "++++++++++++++++++++++++++++++++++++++++++++CurrentJVM Tag ! Local Node : " +
231                 nodeName + " VN name : " + vnName + " policyserver " + ps);
232         } else {
233             logger.debug(
234                 "----------------------------------------Local Node : " +
235                 nodeName + " VN name : " + vnName + " policyserver " + ps);
236         }
237
238         if (ps != null) {
239             logger.debug("generating node certificate");
240             ps.generateNodeCertificate(vnName + " " + nodeName, vmInformation);
241             policyServerMap.put(nodeName, ps);
242         }
243
244         if (vnName != null) {
245             virtualNodesMap.put(nodeName, vnName);
246         }
247
248         return nodeName;
249     }
250
251     /**
252      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#killAllNodes()
253      */

254     public void killAllNodes() {
255         virtualNodesMap.clear();
256         policyServerMap.clear();
257         nodeMap.clear();
258     }
259
260     /**
261      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#killNode(String)
262      */

263     public void killNode(String JavaDoc nodeName) {
264         virtualNodesMap.remove(nodeName);
265         policyServerMap.remove(nodeName);
266         nodeMap.remove(nodeName);
267     }
268
269     /**
270      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#createVM(UniversalProcess)
271      */

272     public void createVM(UniversalProcess remoteProcess)
273         throws java.io.IOException JavaDoc {
274         remoteProcess.startProcess();
275     }
276
277     /**
278      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getLocalNodeNames()
279      */

280     public String JavaDoc[] getLocalNodeNames() {
281         int i = 0;
282         String JavaDoc[] nodeNames;
283         synchronized (nodeMap) {
284             nodeNames = new String JavaDoc[nodeMap.size()];
285             for (java.util.Enumeration JavaDoc e = nodeMap.keys(); e.hasMoreElements();) {
286                 nodeNames[i] = (String JavaDoc) e.nextElement();
287                 i++;
288             }
289         }
290         return nodeNames;
291     }
292
293     /**
294      *@see org.objectweb.proactive.core.runtime.ProActiveRuntime#getVMInformation()
295      */

296     public VMInformation getVMInformation() {
297         return vmInformation;
298     }
299
300     /**
301        <<<<<<< ProActiveRuntimeImpl.java
302      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#register(ProActiveRuntime, String, String, String, String)
303        =======
304      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#register(ProActiveRuntime, String, String, String,String)
305        >>>>>>> 1.18
306      */

307     public void register(ProActiveRuntime proActiveRuntimeDist,
308         String JavaDoc proActiveRuntimeName, String JavaDoc creatorID, String JavaDoc creationProtocol,
309         String JavaDoc vmName) {
310         //System.out.println("register in Impl");
311
//System.out.println("thread"+Thread.currentThread().getName());
312
//System.out.println(vmInformation.getVMID().toString());
313
proActiveRuntimeMap.put(proActiveRuntimeName, proActiveRuntimeDist);
314         notifyListeners(this, RuntimeRegistrationEvent.RUNTIME_REGISTERED,
315             proActiveRuntimeName, creatorID, creationProtocol, vmName);
316     }
317
318     /**
319      *@see org.objectweb.proactive.core.runtime.ProActiveRuntime#getProActiveRuntimes()
320      */

321     public ProActiveRuntime[] getProActiveRuntimes() {
322         int i = 0;
323         ProActiveRuntime[] runtimeArray;
324         synchronized (proActiveRuntimeMap) {
325             runtimeArray = new ProActiveRuntime[proActiveRuntimeMap.size()];
326             for (java.util.Enumeration JavaDoc e = proActiveRuntimeMap.elements();
327                     e.hasMoreElements();) {
328                 runtimeArray[i] = (ProActiveRuntime) e.nextElement();
329                 i++;
330             }
331         }
332         return runtimeArray;
333     }
334
335     /**
336      *@see org.objectweb.proactive.core.runtime.ProActiveRuntime#getProActiveRuntime(String)
337      */

338     public ProActiveRuntime getProActiveRuntime(String JavaDoc proActiveRuntimeName) {
339         return (ProActiveRuntime) proActiveRuntimeMap.get(proActiveRuntimeName);
340     }
341
342     /**
343      *@see org.objectweb.proactive.core.runtime.ProActiveRuntime#killRT(boolean)
344      */

345     public void killRT(boolean softly) {
346         System.exit(0);
347     }
348
349     /**
350      *@see org.objectweb.proactive.core.runtime.ProActiveRuntime#getURL()
351      */

352     public String JavaDoc getURL() {
353         return "//" + vmInformation.getInetAddress().getCanonicalHostName() +
354         "/" + vmInformation.getName();
355     }
356
357     public ArrayList JavaDoc getActiveObjects(String JavaDoc nodeName) {
358         // we have to clone the array otherwise modifications done on nodeMap
359
// would be reflected on the temp variable bodyArray
360
ArrayList JavaDoc bodyArray = (ArrayList JavaDoc) ((ArrayList JavaDoc) nodeMap.get(nodeName)).clone();
361
362         //the array to return
363
ArrayList JavaDoc localBodies = new ArrayList JavaDoc();
364         LocalBodyStore localBodystore = LocalBodyStore.getInstance();
365         for (int i = 0; i < bodyArray.size(); i++) {
366             UniqueID bodyID = (UniqueID) bodyArray.get(i);
367
368             //check if the body is still on this vm
369
Body body = localBodystore.getLocalBody(bodyID);
370             if (body == null) {
371                 runtimeLogger.warn("body null");
372                 // the body with the given ID is not any more on this ProActiveRuntime
373
// unregister it from this ProActiveRuntime
374
unregisterBody(nodeName, bodyID);
375             } else {
376                 //the body is on this runtime then return adapter and class name of the reified
377
//object to enable the construction of stub-proxy couple.
378
ArrayList JavaDoc bodyAndObjectClass = new ArrayList JavaDoc(2);
379
380                 //adapter
381
bodyAndObjectClass.add(0, body.getRemoteAdapter());
382                 //className
383
bodyAndObjectClass.add(1,
384                     body.getReifiedObject().getClass().getName());
385                 localBodies.add(bodyAndObjectClass);
386             }
387         }
388         return localBodies;
389     }
390
391     public VirtualNode getVirtualNode(String JavaDoc virtualNodeName) {
392         // System.out.println("i am in get vn ");
393
return (VirtualNode) virtualNodesMap.get(virtualNodeName);
394     }
395
396     public void registerVirtualNode(String JavaDoc virtualNodeName,
397         boolean replacePreviousBinding) {
398         //This method has no effect here since the virtualNode has been registered in some registry
399
//like RMI or JINI
400
}
401
402     public void unregisterVirtualNode(String JavaDoc virtualNodeName) {
403         removeRuntimeRegistrationEventListener((VirtualNodeImpl) virtualNodesMap.get(
404                 virtualNodeName));
405         virtualNodesMap.remove(virtualNodeName);
406     }
407
408     public void unregisterAllVirtualNodes() {
409         virtualNodesMap.clear();
410     }
411
412     /**
413      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getJobID(java.lang.String)
414      */

415     public String JavaDoc getJobID(String JavaDoc nodeUrl) {
416         String JavaDoc name = UrlBuilder.getNameFromUrl(nodeUrl);
417         return (String JavaDoc) nodeJobIdMap.get(name);
418     }
419
420     public ArrayList JavaDoc getActiveObjects(String JavaDoc nodeName, String JavaDoc objectName) {
421         // we have to clone the array otherwise modifications done on nodeMap
422
// would be reflected on the temp variable bodyArray
423
ArrayList JavaDoc bodyArray = (ArrayList JavaDoc) ((ArrayList JavaDoc) nodeMap.get(nodeName)).clone();
424
425         //the array to return
426
ArrayList JavaDoc localBodies = new ArrayList JavaDoc();
427         LocalBodyStore localBodystore = LocalBodyStore.getInstance();
428         for (int i = 0; i < bodyArray.size(); i++) {
429             UniqueID bodyID = (UniqueID) bodyArray.get(i);
430
431             //check if the body is still on this vm
432
Body body = localBodystore.getLocalBody(bodyID);
433             if (body == null) {
434                 runtimeLogger.warn("body null");
435                 // the body with the given ID is not any more on this ProActiveRuntime
436
// unregister it from this ProActiveRuntime
437
unregisterBody(nodeName, bodyID);
438             } else {
439                 String JavaDoc objectClass = body.getReifiedObject().getClass().getName();
440
441                 // if the reified object is of the specified type
442
// return the body adapter
443
if (objectClass.equals((String JavaDoc) objectName)) {
444                     localBodies.add(body.getRemoteAdapter());
445                 }
446             }
447         }
448         return localBodies;
449     }
450
451     /**
452      *@see org.objectweb.proactive.core.runtime.ProActiveRuntime#createBody(String, ConstructorCall, boolean)
453      */

454     public UniversalBody createBody(String JavaDoc nodeName,
455         ConstructorCall bodyConstructorCall, boolean isLocal)
456         throws ConstructorCallExecutionFailedException,
457             java.lang.reflect.InvocationTargetException JavaDoc {
458         // System.out.println("XXXXXX creating body on " + this.getURL());
459
// ProActiveConfiguration.getConfiguration().dumpAddedProperties();
460
Body localBody = (Body) bodyConstructorCall.execute();
461
462         // SECURITY
463
try {
464             localBody.getProActiveSecurityManager().setPolicyServer((PolicyServer) policyServerMap.get(
465                     nodeName));
466         } catch (IOException JavaDoc e) {
467             e.printStackTrace();
468         } catch (SecurityNotAvailableException e) {
469             // do nothing
470
// security not available
471
}
472
473         registerBody(nodeName, localBody);
474
475         if (isLocal) {
476             // if the body and proxy are on the same vm, returns the local view
477
//System.out.println("body and proxy on the same vm");
478
//System.out.println(localBody.getReifiedObject().getClass().getName());
479
//register the body in the nodemap
480
return (UniversalBody) localBody;
481         } else {
482             //otherwise return the adapter
483
//System.out.println ("RemoteProActiveImpl.createBody "+vmInformation.getInetAddress().getHostName() +" -> new "+bodyConstructorCall.getTargetClassName()+" on node "+nodeName);
484
//System.out.println ("RemoteProActiveRuntimeImpl.localBody created localBody="+localBody+" on node "+nodeName);
485
return localBody.getRemoteAdapter();
486         }
487     }
488
489     /**
490      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#receiveBody(String, Body)
491      */

492     public UniversalBody receiveBody(String JavaDoc nodeName, Body body) {
493         UniversalBody boa = body.getRemoteAdapter();
494         try {
495             boa.getProActiveSecurityManager().setPolicyServer((PolicyServer) policyServerMap.get(
496                     nodeName));
497         } catch (IOException JavaDoc e) {
498             e.printStackTrace();
499         } catch (SecurityNotAvailableException e) {
500             // do nothing
501
}
502
503         registerBody(nodeName, body);
504         return boa;
505     }
506
507     // private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
508
// System.out.println("I am in runtime serialization ");
509
// out.defaultWriteObject();
510
// }
511
// //
512
// // --------------------Implements AbstractDeploymentEventProducer---------------------
513
// //
514
//
515
// protected void notifyOneListener(ProActiveListener proActiveListener, ProActiveEvent event){
516
// RuntimeRegistrationEvent runtimeRegistrationEvent = (RuntimeRegistrationEvent) event;
517
// RuntimeRegistrationEventListener runtimeRegistrationEventListener = (RuntimeRegistrationEventListener)proActiveListener;
518
// //notify the listener that a registration occurs
519
// runtimeRegistrationEventListener.runtimeRegistered(runtimeRegistrationEvent);
520
// }
521
//
522
//
523
//
524
// //
525
// // -- PRIVATE METHODS -----------------------------------------------
526
// //
527
//
528
// private void notifyListeners(ProActiveRuntime proActiveRuntime,int type,String registeredRuntimeName, String creatorID, String protocol){
529
// if (hasListeners()){
530
// notifyAllListeners(new RuntimeRegistrationEvent(proActiveRuntime, type, registeredRuntimeName, creatorID, protocol));
531
// }
532
// else System.out.println("no listener");
533
// }
534

535     /**
536      * Registers the specified body at the nodeName key in the <code>nodeMap</code>.
537      * In fact it is the <code>UniqueID</code> of the body that is attached to the nodeName
538      * in the <code>nodeMap</code>
539      * @param nodeName. The name where to attached the body in the <code>nodeMap</code>
540      * @param body. The body to register
541      */

542     private void registerBody(String JavaDoc nodeName, Body body) {
543         UniqueID bodyID = body.getID();
544         ArrayList JavaDoc bodyList = (ArrayList JavaDoc) nodeMap.get(nodeName);
545         synchronized (bodyList) {
546             if (!bodyList.contains(bodyID)) {
547                 //System.out.println("in registerbody id = "+ bodyID.toString());
548
bodyList.add(bodyID);
549             }
550         }
551
552         //ArrayList test = ((ArrayList)nodeMap.get(nodeName));
553
//UniqueID id = (UniqueID)test.get(0);
554
//UniqueID id1 = (UniqueID)test.get(1);
555
//System.out.println("id "+id.toString());
556
//System.out.println("id "+id1.toString());
557
}
558
559     /**
560      * Unregisters the specified <code>UniqueID</code> from the <code>nodeMap</code> at the
561      * nodeName key
562      * @param nodeName. The key where to remove the <code>UniqueID</code>
563      * @param bodyID. The <code>UniqueID</code> to remove
564      */

565     private void unregisterBody(String JavaDoc nodeName, UniqueID bodyID) {
566         //System.out.println("in remove id= "+ bodyID.toString());
567
//System.out.println("array size "+((ArrayList)nodeMap.get(nodeName)).size());
568
ArrayList JavaDoc bodyList = (ArrayList JavaDoc) nodeMap.get(nodeName);
569         synchronized (bodyList) {
570             bodyList.remove(bodyID);
571             //System.out.println("array size "+((ArrayList)nodeMap.get(nodeName)).size());
572
}
573     }
574
575     ///**
576
// * Method BuildDefaultNodeName.
577
// * @param nodeName
578
// */
579
// private String BuildDefaultNodeName() throws java.net.UnknownHostException
580
// {
581
// return "//"+vmInformation.getInetAddress().getHostName()+"/Node"+removeRuntime(getVMInformation().getName());
582
// }
583
//
584
// private static String removeRuntime(String url){
585
// String tmp = url;
586
// tmp = url.substring(5);
587
// return tmp;
588
// }
589
//
590
// -- INNER CLASSES -----------------------------------------------
591
//
592
protected static class VMInformationImpl implements VMInformation,
593         java.io.Serializable JavaDoc {
594         private java.net.InetAddress JavaDoc hostInetAddress;
595
596         //the Unique ID of the JVM
597
private java.rmi.dgc.VMID JavaDoc uniqueVMID;
598         private String JavaDoc name;
599         private String JavaDoc processCreatorId;
600         private String JavaDoc jobId;
601
602         public VMInformationImpl() throws java.net.UnknownHostException JavaDoc {
603             this.uniqueVMID = UniqueID.getCurrentVMID();
604             hostInetAddress = java.net.InetAddress.getLocalHost();
605             String JavaDoc hostName = hostInetAddress.getCanonicalHostName();
606             this.processCreatorId = "jvm";
607
608             // this.name = "PA_RT" +
609
// Integer.toString(new java.security.SecureRandom().nextInt()) +
610
// "_" + hostName;
611
String JavaDoc random = Integer.toString(ProActiveRuntimeImpl.getNextInt());
612             this.name = "PA_RT" + random + "_" + hostName;
613             if (System.getProperty("proactive.jobid") != null) {
614                 this.jobId = System.getProperty("proactive.jobid");
615             } else {
616                 //if the property is null, no need to generate another random, take the one in name
617
this.jobId = "JOB-" + random;
618             }
619         }
620
621         //
622
// -- PUBLIC METHODS -----------------------------------------------
623
//
624
//
625
// -- implements VMInformation -----------------------------------------------
626
//
627
public java.rmi.dgc.VMID JavaDoc getVMID() {
628             return uniqueVMID;
629         }
630
631         public String JavaDoc getName() {
632             return name;
633         }
634
635         public java.net.InetAddress JavaDoc getInetAddress() {
636             return hostInetAddress;
637         }
638
639         public String JavaDoc getCreationProtocolID() {
640             return this.processCreatorId;
641         }
642
643         public void setCreationProtocolID(String JavaDoc protocolId) {
644             this.processCreatorId = protocolId;
645         }
646
647         /**
648          * @see org.objectweb.proactive.Job#getJobID()
649          */

650         public String JavaDoc getJobID() {
651             return this.jobId;
652         }
653     }
654
655     // SECURITY
656

657     /* (non-Javadoc)
658      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getCreatorCertificate()
659      */

660     public X509Certificate JavaDoc getCreatorCertificate() {
661         return creatorCertificate;
662     }
663
664     /* (non-Javadoc)
665      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getPolicyServer()
666      */

667     public PolicyServer getPolicyServer() {
668         // System.out.println("return my policy server " + policyServer);
669
if (psm != null) {
670             return psm.getPolicyServer();
671         }
672         return null;
673     }
674
675     public String JavaDoc getVNName(String JavaDoc nodeName) {
676         return (String JavaDoc) virtualNodesMap.get(nodeName);
677     }
678
679     /**
680      * set policy server to all virtual nodes
681      */

682     public void setProActiveSecurityManager(ProActiveSecurityManager server) {
683         if (psm != null) {
684             return;
685         }
686         psm = server;
687     }
688
689     /* (non-Javadoc)
690      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#setDefaultNodeVirtualNodeName(java.lang.String)
691      */

692     public void setDefaultNodeVirtualNodeName(String JavaDoc s) {
693         System.out.println(
694             " ************************ **********************************setting current node as currentJVM tag " +
695             s);
696         defaultNodeVirtualNode = s;
697     }
698
699     public void listVirtualNodes() {
700
701         /*
702            if (defaultNodeVirtualNode != null) {
703            String nodeName = null;
704                                            try {
705                                                                            nodeName = NodeFactory.getDefaultNode().getNodeInformation().getURL();
706                                                            } catch (NodeException e) {
707                                                                            e.printStackTrace();
708                                                            }
709            distantVNMap.put(nodeName,defaultNodeVirtualNode);
710            }
711          */

712         System.out.println("Local node 1");
713
714         for (Enumeration JavaDoc e = nodeMap.keys(); e.hasMoreElements();) {
715             //VirtualNode vn =(VirtualNode) e.nextElement();
716
String JavaDoc key = (String JavaDoc) e.nextElement();
717             System.out.println("local element " + key);
718         }
719
720         System.out.println("Local node ");
721         for (Enumeration JavaDoc e = virtualNodesMap.elements(); e.hasMoreElements();) {
722             String JavaDoc key = (String JavaDoc) e.nextElement();
723
724             //String s = (String) distantVNMap.get(key);
725
System.out.println(" node " + key + " belongs to ");
726         }
727     }
728
729     /* (non-Javadoc)
730      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getNodePolicyServer(java.lang.String)
731      */

732     public PolicyServer getNodePolicyServer(String JavaDoc nodeName) {
733         return (PolicyServer) policyServerMap.get(nodeName);
734     }
735
736     /* (non-Javadoc)
737      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#enableSecurityIfNeeded()
738      */

739     public void enableSecurityIfNeeded() {
740
741         /* Enumeration e = virtualNodesMap.elements();
742            for (; e.hasMoreElements(); ){
743                    VirtualNode vn = (VirtualNode) e.nextElement();
744                    logger.debug("Setting VN " + vn+"-");
745                    logger.debug(vn.getName() );
746                    logger.debug(" - policyserver " + policyServer);
747                    vn.setPolicyServer(policyServer);
748            }
749          */

750     }
751
752     /** (non-Javadoc)
753      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getNodeCertificate(java.lang.String)
754      */

755     public X509Certificate JavaDoc getNodeCertificate(String JavaDoc nodeName) {
756         PolicyServer ps = null;
757
758         ps = (PolicyServer) policyServerMap.get(nodeName);
759         if (ps != null) {
760             return ps.getCertificate();
761         }
762         return null;
763     }
764
765     /* (non-Javadoc)
766      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getEntities(java.lang.String)
767      */

768     public ArrayList JavaDoc getEntities(String JavaDoc nodeName) {
769         PolicyServer ps = null;
770         Entity nodeEntity = null;
771         String JavaDoc nodeVirtualName = (String JavaDoc) virtualNodesMap.get(nodeName);
772         ps = (PolicyServer) policyServerMap.get(nodeName);
773
774         if (ps != null) {
775             nodeEntity = new EntityVirtualNode(nodeVirtualName,
776                     ps.getApplicationCertificate(), ps.getCertificate());
777         }
778
779         ArrayList JavaDoc entities = null;
780
781         //entities = getEntities();
782
if (entities == null) {
783             entities = new ArrayList JavaDoc();
784         }
785
786         entities.add(nodeEntity);
787         return entities;
788     }
789
790     /* (non-Javadoc)
791      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getEntities(org.objectweb.proactive.core.body.UniversalBody)
792      */

793     public ArrayList JavaDoc getEntities(UniversalBody uBody) {
794         try {
795             return uBody.getEntities();
796         } catch (SecurityNotAvailableException e) {
797             return null;
798         } catch (IOException JavaDoc e) {
799             e.printStackTrace();
800         }
801         return null;
802     }
803
804     /* (non-Javadoc)
805      * @see org.objectweb.proactive.core.runtime.ProActiveRuntime#getEntities()
806      */

807     public ArrayList JavaDoc getEntities() {
808         PolicyServer policyServer = psm.getPolicyServer();
809         Entity e = new EntityCertificate(policyServer.getApplicationCertificate(),
810                 policyServer.getCertificate());
811         ArrayList JavaDoc array = new ArrayList JavaDoc();
812         array.add(e);
813
814         return array;
815     }
816
817     /**
818      * @see org.objectweb.proactive.Job#getJobID()
819      */

820     public String JavaDoc getJobID() {
821         return vmInformation.getJobID();
822     }
823 }
824
Popular Tags