00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
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             
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             
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                 
00171                 Body body = localBodystore.getLocalBody(bodyID);
00172 
00173                 if (body == null) {
00174                     
00175                     
00176                     
00177                     activeObjectsId.remove(bodyID);
00178                 } else {
00179                     
00180                     
00181                     ArrayList bodyAndObjectClass = new ArrayList(2);
00182 
00183                     
00184                     bodyAndObjectClass.add(0, body.getRemoteAdapter());
00185 
00186                     
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             
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 }