org/objectweb/proactive/core/runtime/LocalNode.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.core.runtime;
00032 
00033 import java.io.IOException;
00034 import java.util.ArrayList;
00035 import java.util.Properties;
00036 
00037 import org.objectweb.proactive.Body;
00038 import org.objectweb.proactive.core.UniqueID;
00039 import org.objectweb.proactive.core.body.LocalBodyStore;
00040 import org.objectweb.proactive.core.util.log.Loggers;
00041 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00042 import org.objectweb.proactive.ext.security.ProActiveSecurityManager;
00043 
00044 
00050 public class LocalNode {
00051     private String name;
00052     private ArrayList<UniqueID> activeObjectsId;
00053     private String jobId;
00054     private ProActiveSecurityManager securityManager;
00055     private String virtualNodeName;
00056     private Properties localProperties;
00057 
00058     public LocalNode(String nodeName, String jobId,
00059         ProActiveSecurityManager securityManager, String virtualNodeName) {
00060         this.name = nodeName;
00061         this.jobId = jobId;
00062         this.securityManager = securityManager;
00063         this.virtualNodeName = virtualNodeName;
00064         this.activeObjectsId = new ArrayList<UniqueID>();
00065         this.localProperties = new Properties();
00066 
00067         if (this.securityManager != null) {
00068             ProActiveLogger.getLogger(Loggers.SECURITY_RUNTIME)
00069                            .debug("Local Node : " + this.name + " VN name : " +
00070                 this.virtualNodeName + " policyserver for app :" +
00071                 this.securityManager.getPolicyServer().getApplicationName());
00072 
00073             // setting virtual node name
00074             this.securityManager.setVNName(this.virtualNodeName);
00075 
00076             ProActiveLogger.getLogger(Loggers.SECURITY_RUNTIME)
00077                            .debug("registering node certificate for VN " +
00078                 this.virtualNodeName);
00079         }
00080     }
00081 
00085     public ArrayList<UniqueID> getActiveObjectsId() {
00086         return activeObjectsId;
00087     }
00088 
00093     public void setActiveObjects(ArrayList<UniqueID> activeObjects) {
00094         this.activeObjectsId = activeObjects;
00095     }
00096 
00100     public String getJobId() {
00101         return jobId;
00102     }
00103 
00107     public void setJobId(String jobId) {
00108         this.jobId = jobId;
00109     }
00110 
00114     public String getName() {
00115         return name;
00116     }
00117 
00121     public void setName(String name) {
00122         this.name = name;
00123     }
00124 
00128     public ProActiveSecurityManager getSecurityManager() {
00129         return securityManager;
00130     }
00131 
00135     public void setSecurityManager(ProActiveSecurityManager securityManager) {
00136         this.securityManager = securityManager;
00137     }
00138 
00143     public String getVirtualNodeName() {
00144         return virtualNodeName;
00145     }
00146 
00150     public void setVirtualNodeName(String virtualNodeName) {
00151         this.virtualNodeName = virtualNodeName;
00152     }
00153 
00154     public void terminateActiveObjects() {
00155     }
00156 
00157     public ArrayList getActiveObjects() {
00158         ArrayList localBodies = new ArrayList();
00159         LocalBodyStore localBodystore = LocalBodyStore.getInstance();
00160 
00161         if (activeObjectsId == null) {
00162             // Probably the node is killed
00163             return localBodies;
00164         }
00165 
00166         synchronized (activeObjectsId) {
00167             for (int i = 0; i < activeObjectsId.size(); i++) {
00168                 UniqueID bodyID = (UniqueID) activeObjectsId.get(i);
00169 
00170                 //check if the body is still on this vm
00171                 Body body = localBodystore.getLocalBody(bodyID);
00172 
00173                 if (body == null) {
00174                     //runtimeLogger.warn("body null");
00175                     // the body with the given ID is not any more on this ProActiveRuntime
00176                     // unregister it from this ProActiveRuntime
00177                     activeObjectsId.remove(bodyID);
00178                 } else {
00179                     //the body is on this runtime then return adapter and class name of the reified
00180                     //object to enable the construction of stub-proxy couple.
00181                     ArrayList bodyAndObjectClass = new ArrayList(2);
00182 
00183                     //adapter
00184                     bodyAndObjectClass.add(0, body.getRemoteAdapter());
00185 
00186                     //className
00187                     bodyAndObjectClass.add(1,
00188                         body.getReifiedObject().getClass().getName());
00189                     localBodies.add(bodyAndObjectClass);
00190                 }
00191             }
00192         }
00193         return localBodies;
00194     }
00195 
00200     public void unregisterBody(UniqueID bodyID) {
00201         activeObjectsId.remove(bodyID);
00202     }
00203 
00209     public void registerBody(UniqueID bodyID) {
00210         activeObjectsId.add(bodyID);
00211     }
00212 
00213     public void terminate() {
00214         ArrayList activeObjects = this.getActiveObjectsId();
00215 
00216         for (int i = 0; i < activeObjects.size(); i++) {
00217             UniqueID bodyID = (UniqueID) activeObjects.get(i);
00218 
00219             //check if the body is still on this vm
00220             Body body = LocalBodyStore.getInstance().getLocalBody(bodyID);
00221 
00222             if (body != null) {
00223                 try {
00224                     ProActiveLogger.getLogger(Loggers.NODE)
00225                                    .info("node " + this.name +
00226                         " is being killed, terminating body " + bodyID);
00227                     body.terminate();
00228                 } catch (IOException e) {
00229                     e.printStackTrace();
00230                 }
00231             }
00232         }
00233     }
00234 
00242     public Object setProperty(String key, String value) {
00243         return this.localProperties.setProperty(key, value);
00244     }
00245 
00252     public String getProperty(String key) {
00253         return this.localProperties.getProperty(key);
00254     }
00255 }

Generated on Mon Jan 22 15:16:09 2007 for ProActive by  doxygen 1.5.1