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.File;
00034 import java.io.IOException;
00035 import java.io.Serializable;
00036 import java.lang.reflect.InvocationTargetException;
00037 import java.lang.reflect.Method;
00038 import java.security.PublicKey;
00039 import java.security.SecureRandom;
00040 import java.security.cert.X509Certificate;
00041 import java.util.ArrayList;
00042 import java.util.Enumeration;
00043
00044 import org.apache.log4j.MDC;
00045 import org.objectweb.proactive.ActiveObjectCreationException;
00046 import org.objectweb.proactive.Body;
00047 import org.objectweb.proactive.ProActive;
00048 import org.objectweb.proactive.core.ProActiveException;
00049 import org.objectweb.proactive.core.UniqueID;
00050 import org.objectweb.proactive.core.body.AbstractBody;
00051 import org.objectweb.proactive.core.body.ActiveBody;
00052 import org.objectweb.proactive.core.body.BodyAdapter;
00053 import org.objectweb.proactive.core.body.LocalBodyStore;
00054 import org.objectweb.proactive.core.body.UniversalBody;
00055 import org.objectweb.proactive.core.body.ft.checkpointing.Checkpoint;
00056 import org.objectweb.proactive.core.body.proxy.UniversalBodyProxy;
00057 import org.objectweb.proactive.core.config.ProActiveConfiguration;
00058 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
00059 import org.objectweb.proactive.core.descriptor.data.VirtualNode;
00060 import org.objectweb.proactive.core.descriptor.data.VirtualNodeImpl;
00061 import org.objectweb.proactive.core.descriptor.util.RefactorPAD;
00062 import org.objectweb.proactive.core.event.RuntimeRegistrationEvent;
00063 import org.objectweb.proactive.core.event.RuntimeRegistrationEventProducerImpl;
00064 import org.objectweb.proactive.core.gc.GarbageCollector;
00065 import org.objectweb.proactive.core.mop.ConstructorCall;
00066 import org.objectweb.proactive.core.mop.ConstructorCallExecutionFailedException;
00067 import org.objectweb.proactive.core.mop.JavassistByteCodeStubBuilder;
00068 import org.objectweb.proactive.core.mop.MOPClassLoader;
00069 import org.objectweb.proactive.core.mop.Utils;
00070 import org.objectweb.proactive.core.node.NodeException;
00071 import org.objectweb.proactive.core.process.ExternalProcess;
00072 import org.objectweb.proactive.core.process.UniversalProcess;
00073 import org.objectweb.proactive.core.rmi.FileProcess;
00074 import org.objectweb.proactive.core.util.ClassDataCache;
00075 import org.objectweb.proactive.core.util.UrlBuilder;
00076 import org.objectweb.proactive.core.util.log.Loggers;
00077 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00078 import org.objectweb.proactive.ext.security.Communication;
00079 import org.objectweb.proactive.ext.security.PolicyServer;
00080 import org.objectweb.proactive.ext.security.ProActiveSecurity;
00081 import org.objectweb.proactive.ext.security.ProActiveSecurityManager;
00082 import org.objectweb.proactive.ext.security.SecurityContext;
00083 import org.objectweb.proactive.ext.security.SecurityEntity;
00084 import org.objectweb.proactive.ext.security.crypto.KeyExchangeException;
00085 import org.objectweb.proactive.ext.security.domain.SecurityDomain;
00086 import org.objectweb.proactive.ext.security.exceptions.InvalidPolicyFile;
00087 import org.objectweb.proactive.ext.security.exceptions.RenegotiateSessionException;
00088 import org.objectweb.proactive.ext.security.exceptions.SecurityNotAvailableException;
00089 import org.objectweb.proactive.ext.security.securityentity.Entity;
00090 import org.objectweb.proactive.ext.security.securityentity.EntityCertificate;
00091 import org.objectweb.proactive.ext.security.securityentity.EntityVirtualNode;
00092
00093
00104 public class ProActiveRuntimeImpl extends RuntimeRegistrationEventProducerImpl
00105 implements ProActiveRuntime, LocalProActiveRuntime {
00106
00107
00108
00109
00110 private static ProActiveRuntime proActiveRuntime;
00111
00112 static {
00113 if (ProActiveConfiguration.isForwarder()) {
00114 proActiveRuntime = new ProActiveRuntimeForwarderImpl();
00115 } else {
00116 proActiveRuntime = new ProActiveRuntimeImpl();
00117 }
00118 }
00119
00120 private static SecureRandom prng = null;
00121
00122
00123 private static ProActiveSecurityManager runtimeSecurityManager;
00124
00125
00126 private java.util.Hashtable<String,LocalNode> nodeMap;
00127 private String defaultNodeVirtualNode = null;
00128
00129
00130
00131
00132 private VMInformation vmInformation;
00133
00134
00135 private java.util.Hashtable<String, VirtualNode> virtualNodesMap;
00136
00137
00138 private java.util.Hashtable<String, ProActiveDescriptor> descriptorMap;
00139
00140
00141 private java.util.Hashtable<String, ProActiveRuntime> proActiveRuntimeMap;
00142 private java.util.Hashtable proActiveRuntimeForwarderMap;
00143
00144
00145 private java.util.Set<String> runtimeAcquaintancesURL;
00146 private ProActiveRuntime parentRuntime;
00147
00148
00149
00150
00151
00152 protected ProActiveRuntimeImpl() {
00153 try {
00154 this.vmInformation = new VMInformationImpl();
00155 this.proActiveRuntimeMap = new java.util.Hashtable<String, ProActiveRuntime>();
00156 this.proActiveRuntimeForwarderMap = new java.util.Hashtable();
00157 this.runtimeAcquaintancesURL = java.util.Collections.synchronizedSortedSet(new java.util.TreeSet<String>());
00158 this.virtualNodesMap = new java.util.Hashtable<String, VirtualNode>();
00159 this.descriptorMap = new java.util.Hashtable<String, ProActiveDescriptor>();
00160 this.nodeMap = new java.util.Hashtable<String,LocalNode>();
00161
00162 try {
00163 String file = System.getProperties()
00164 .getProperty("proactive.runtime.security");
00165 ProActiveSecurity.loadProvider();
00166
00167 if ((file != null) && new File(file).exists()) {
00168
00169 ProActiveRuntimeImpl.runtimeSecurityManager = new ProActiveSecurityManager(file);
00170 logger.info(
00171 "ProActive Security Policy (proactive.runtime.security) using " +
00172 file);
00173
00174
00175 String domainURL = System.getProperties()
00176 .getProperty("proactive.runtime.domain.url");
00177
00178 if (domainURL != null) {
00179 SecurityEntity domain = (SecurityDomain) ProActive.lookupActive("org.objectweb.proactive.ext.security.domain.SecurityDomain",
00180 domainURL);
00181 ProActiveRuntimeImpl.runtimeSecurityManager.setParent(domain);
00182 }
00183 } else {
00184 logger.debug(
00185 "ProActive Security Policy (proactive.runtime.security) not set. Runtime Security disabled ");
00186 }
00187 } catch (InvalidPolicyFile e) {
00188 e.printStackTrace();
00189 } catch (ActiveObjectCreationException e) {
00190 e.printStackTrace();
00191 }
00192
00193
00194 } catch (java.net.UnknownHostException e) {
00195
00196 logger.fatal(" !!! Cannot do a reverse lookup on that host");
00197
00198
00199 e.printStackTrace();
00200 System.exit(1);
00201 } catch (IOException e) {
00202 e.printStackTrace();
00203 }
00204
00205
00206 MDC.remove("runtime");
00207 MDC.put("runtime", getURL());
00208 }
00209
00210 public static synchronized int getNextInt() {
00211 if (prng == null) {
00212 prng = new SecureRandom();
00213 }
00214
00215 return prng.nextInt();
00216 }
00217
00218
00219
00220
00221 public static ProActiveRuntime getProActiveRuntime() {
00222 return proActiveRuntime;
00223 }
00224
00225
00226
00227
00228
00232 public void registerLocalVirtualNode(VirtualNode vn, String vnName) {
00233
00234 virtualNodesMap.put(vnName, vn);
00235 }
00236
00240 public void setParent(ProActiveRuntime parentPARuntime) {
00241 if (parentRuntime == null) {
00242 parentRuntime = parentPARuntime;
00243 runtimeAcquaintancesURL.add(parentPARuntime.getURL());
00244 } else {
00245 runtimeLogger.error("Parent runtime already set!");
00246 }
00247 }
00248
00249 public void registerDescriptor(String url, ProActiveDescriptor pad) {
00250 descriptorMap.put(url, pad);
00251 }
00252
00253 public ProActiveDescriptor getDescriptor(String url,
00254 boolean isHierarchicalSearch) throws IOException, ProActiveException {
00255 ProActiveDescriptor pad = descriptorMap.get(url);
00256
00257
00258 if (pad != null) {
00259
00260 if (isHierarchicalSearch) {
00261 return RefactorPAD.buildNoMainPAD(pad);
00262 } else {
00263
00264 return pad;
00265 }
00266 } else if (!isHierarchicalSearch) {
00267 return null;
00268 } else {
00269 if (parentRuntime == null) {
00270 throw new IOException(
00271 "Descriptor cannot be found hierarchically since this runtime has no parent");
00272 }
00273
00274 return parentRuntime.getDescriptor(url, true);
00275 }
00276 }
00277
00278 public void removeDescriptor(String url) {
00279 descriptorMap.remove(url);
00280 }
00281
00282
00283
00284
00285
00289 public String createLocalNode(String nodeName,
00290 boolean replacePreviousBinding,
00291 ProActiveSecurityManager nodeSecurityManager, String vnName,
00292 String jobId) throws NodeException {
00293 if (!replacePreviousBinding && (nodeMap.get(nodeName) != null)) {
00294 throw new NodeException("Node " + nodeName +
00295 " already created on this ProActiveRuntime. To overwrite this node, use true for replacePreviousBinding");
00296 }
00297
00298 if (nodeSecurityManager != null) {
00299
00300 nodeSecurityManager.setParent(this);
00301 }
00302
00303 LocalNode newNode = new LocalNode(nodeName, jobId, nodeSecurityManager,
00304 vnName);
00305
00306 if (replacePreviousBinding && (nodeMap.get(nodeName) != null)) {
00307 newNode.setActiveObjects(nodeMap.get(nodeName).getActiveObjectsId());
00308 nodeMap.remove(nodeName);
00309 }
00310
00311 nodeMap.put(nodeName, newNode);
00312
00313 return nodeName;
00314 }
00315
00319 public void killAllNodes() {
00320 for (Enumeration<String> e = nodeMap.keys(); e.hasMoreElements();) {
00321 String nodeName = e.nextElement();
00322 killNode(nodeName);
00323 }
00324 }
00325
00329 public void killNode(String nodeName) {
00330 LocalNode localNode = nodeMap.get(nodeName);
00331 localNode.terminate();
00332 nodeMap.remove(nodeName);
00333 }
00334
00338 public void createVM(UniversalProcess remoteProcess)
00339 throws java.io.IOException {
00340 remoteProcess.startProcess();
00341 }
00342
00346 public String[] getLocalNodeNames() {
00347 int i = 0;
00348 String[] nodeNames;
00349
00350 synchronized (nodeMap) {
00351 nodeNames = new String[nodeMap.size()];
00352
00353 for (java.util.Enumeration<String> e = nodeMap.keys(); e.hasMoreElements();) {
00354 nodeNames[i] = e.nextElement();
00355 i++;
00356 }
00357 }
00358
00359 return nodeNames;
00360 }
00361
00365 public VMInformation getVMInformation() {
00366 return vmInformation;
00367 }
00368
00372 public void register(ProActiveRuntime proActiveRuntimeDist,
00373 String proActiveRuntimeName, String creatorID, String creationProtocol,
00374 String vmName) {
00375
00376
00377
00378 proActiveRuntimeMap.put(proActiveRuntimeName, proActiveRuntimeDist);
00379 notifyListeners(this, RuntimeRegistrationEvent.RUNTIME_REGISTERED,
00380 proActiveRuntimeDist, creatorID, creationProtocol, vmName);
00381 }
00382
00386 public void unregister(ProActiveRuntime proActiveRuntimeDist,
00387 String proActiveRuntimeUrl, String creatorID, String creationProtocol,
00388 String vmName) {
00389 this.proActiveRuntimeMap.remove(proActiveRuntimeUrl);
00390 notifyListeners(this, RuntimeRegistrationEvent.RUNTIME_UNREGISTERED,
00391 proActiveRuntimeDist, creatorID, creationProtocol, vmName);
00392 }
00393
00397 public ProActiveRuntime[] getProActiveRuntimes() {
00398 int i = 0;
00399 ProActiveRuntime[] runtimeArray;
00400
00401 synchronized (proActiveRuntimeMap) {
00402 runtimeArray = new ProActiveRuntime[proActiveRuntimeMap.size()];
00403
00404 for (java.util.Enumeration<ProActiveRuntime> e = proActiveRuntimeMap.elements();
00405 e.hasMoreElements();) {
00406 runtimeArray[i] = e.nextElement();
00407 i++;
00408 }
00409 }
00410
00411 return runtimeArray;
00412 }
00413
00417 public ProActiveRuntime getProActiveRuntime(String proActiveRuntimeName) {
00418 return proActiveRuntimeMap.get(proActiveRuntimeName);
00419 }
00420
00424 public void addAcquaintance(String proActiveRuntimeName) {
00425 runtimeAcquaintancesURL.add(proActiveRuntimeName);
00426 }
00427
00431 public String[] getAcquaintances() {
00432 String[] urls;
00433
00434 synchronized (runtimeAcquaintancesURL) {
00435 urls = new String[runtimeAcquaintancesURL.size()];
00436
00437 java.util.Iterator<String> iter = runtimeAcquaintancesURL.iterator();
00438
00439 for (int i = 0; i < urls.length; i++)
00440 urls[i] = iter.next();
00441 }
00442
00443 return urls;
00444 }
00445
00449 public void rmAcquaintance(String proActiveRuntimeName) {
00450 runtimeAcquaintancesURL.remove(proActiveRuntimeName);
00451 }
00452
00456 public void killRT(boolean softly) {
00457 killAllNodes();
00458 System.exit(0);
00459 }
00460
00464 public String getURL() {
00465 return "//" +
00466 UrlBuilder.getHostNameorIP(vmInformation.getInetAddress()) + "/" +
00467 vmInformation.getName();
00468 }
00469
00470 public ArrayList<ArrayList<Serializable>> getActiveObjects(String nodeName) {
00471
00472 ArrayList<ArrayList<Serializable>> localBodies = new ArrayList<ArrayList<Serializable>>();
00473 LocalBodyStore localBodystore = LocalBodyStore.getInstance();
00474 ArrayList<UniqueID> bodyList = nodeMap.get(nodeName).getActiveObjectsId();
00475
00476 if (bodyList == null) {
00477
00478 return localBodies;
00479 }
00480
00481 synchronized (bodyList) {
00482 for (int i = 0; i < bodyList.size(); i++) {
00483 UniqueID bodyID = bodyList.get(i);
00484
00485
00486 Body body = localBodystore.getLocalBody(bodyID);
00487
00488 if (body == null) {
00489
00490
00491
00492 unregisterBody(nodeName, bodyID);
00493 } else {
00494
00495
00496 ArrayList<Serializable> bodyAndObjectClass = new ArrayList<Serializable>(2);
00497
00498
00499 bodyAndObjectClass.add(0, body.getRemoteAdapter());
00500
00501
00502 bodyAndObjectClass.add(1,
00503 body.getReifiedObject().getClass().getName());
00504 localBodies.add(bodyAndObjectClass);
00505 }
00506 }
00507
00508 return localBodies;
00509 }
00510 }
00511
00512 public VirtualNode getVirtualNode(String virtualNodeName) {
00513
00514 return virtualNodesMap.get(virtualNodeName);
00515 }
00516
00517 public void registerVirtualNode(String virtualNodeName,
00518 boolean replacePreviousBinding) {
00519
00520
00521 }
00522
00523 public void unregisterVirtualNode(String virtualNodeName) {
00524 removeRuntimeRegistrationEventListener((VirtualNodeImpl) virtualNodesMap.get(
00525 virtualNodeName));
00526 virtualNodesMap.remove(virtualNodeName);
00527 }
00528
00529 public void unregisterAllVirtualNodes() {
00530 virtualNodesMap.clear();
00531 }
00532
00536 public String getJobID(String nodeUrl) {
00537 String name = UrlBuilder.getNameFromUrl(nodeUrl);
00538
00539 LocalNode localNode = nodeMap.get(name);
00540 return localNode.getJobId();
00541 }
00542
00543 public ArrayList<BodyAdapter> getActiveObjects(String nodeName, String className) {
00544
00545 ArrayList<BodyAdapter> localBodies = new ArrayList<BodyAdapter>();
00546 LocalBodyStore localBodystore = LocalBodyStore.getInstance();
00547 ArrayList<UniqueID> bodyList = nodeMap.get(nodeName).getActiveObjectsId();
00548
00549 if (bodyList == null) {
00550
00551 return localBodies;
00552 }
00553
00554 synchronized (bodyList) {
00555 for (int i = 0; i < bodyList.size(); i++) {
00556 UniqueID bodyID = bodyList.get(i);
00557
00558
00559 Body body = localBodystore.getLocalBody(bodyID);
00560
00561 if (body == null) {
00562
00563
00564
00565 unregisterBody(nodeName, bodyID);
00566 } else {
00567 String objectClass = body.getReifiedObject().getClass()
00568 .getName();
00569
00570
00571
00572 if (objectClass.equals((String) className)) {
00573 localBodies.add(body.getRemoteAdapter());
00574 }
00575 }
00576 }
00577
00578 return localBodies;
00579 }
00580 }
00581
00585 public UniversalBody createBody(String nodeName,
00586 ConstructorCall bodyConstructorCall, boolean isLocal)
00587 throws ConstructorCallExecutionFailedException,
00588 java.lang.reflect.InvocationTargetException {
00589 Body localBody = (Body) bodyConstructorCall.execute();
00590
00591
00592 try {
00593 ProActiveSecurityManager objectSecurityManager = ((AbstractBody) localBody).getProActiveSecurityManager();
00594
00595 if (objectSecurityManager != null) {
00596 ProActiveSecurityManager nodeSecurityManager = this.nodeMap.get(nodeName).getSecurityManager();
00597 objectSecurityManager.setParent(nodeSecurityManager);
00598 }
00599 } catch (SecurityNotAvailableException e) {
00600
00601 } catch (IOException e) {
00602
00603 e.printStackTrace();
00604 }
00605
00606 ProActiveLogger.getLogger(Loggers.RUNTIME).debug("nodeName " +
00607 nodeName);
00608 registerBody(nodeName, localBody);
00609
00610 if (GarbageCollector.isBuildingTopology()) {
00611 ((AbstractBody) localBody).updateReferences(UniversalBodyProxy.getIncomingReferences());
00612 }
00613
00614 if (isLocal) {
00615
00616
00617
00618
00619 return (UniversalBody) localBody;
00620 } else {
00621
00622
00623
00624 return localBody.getRemoteAdapter();
00625 }
00626 }
00627
00631 public UniversalBody receiveBody(String nodeName, Body body) {
00632 try {
00633 ((AbstractBody) body).getProActiveSecurityManager()
00634 .setParent(this.nodeMap.get(nodeName).getSecurityManager());
00635 } catch (SecurityNotAvailableException e) {
00636
00637
00638 } catch (IOException e) {
00639 e.printStackTrace();
00640 }
00641
00642 registerBody(nodeName, body);
00643
00644 return body.getRemoteAdapter();
00645 }
00646
00650 public UniversalBody receiveCheckpoint(String nodeURL, Checkpoint ckpt,
00651 int inc) {
00652 runtimeLogger.debug("Receive a checkpoint for recovery");
00653
00654
00655 Body ret = ckpt.recover();
00656
00657
00658 ret.updateNodeURL(nodeURL);
00659
00660 String nodeName = UrlBuilder.getNameFromUrl(nodeURL);
00661
00662
00663
00664 LocalBodyStore.getInstance().setCurrentThreadBody(ret);
00665 ((AbstractBody) ret).getFTManager()
00666 .beforeRestartAfterRecovery(ckpt.getCheckpointInfo(), inc);
00667 LocalBodyStore.getInstance().setCurrentThreadBody(null);
00668
00669
00670 this.registerBody(nodeName, ret);
00671
00672
00673 if (runtimeLogger.isDebugEnabled()) {
00674 runtimeLogger.debug(ret.getID() + " is restarting activity...");
00675 }
00676
00677 ((ActiveBody) ret).startBody();
00678
00679
00680 return null;
00681 }
00682
00689 private void registerBody(String nodeName, Body body) {
00690 UniqueID bodyID = body.getID();
00691 ArrayList<UniqueID> bodyList = nodeMap.get(nodeName).getActiveObjectsId();
00692
00693 synchronized (bodyList) {
00694 if (!bodyList.contains(bodyID)) {
00695
00696 bodyList.add(bodyID);
00697 }
00698 }
00699 }
00700
00707 private void unregisterBody(String nodeName, UniqueID bodyID) {
00708
00709
00710 ArrayList<UniqueID> bodyList = nodeMap.get(nodeName).getActiveObjectsId();
00711
00712 synchronized (bodyList) {
00713 bodyList.remove(bodyID);
00714
00715
00716 }
00717 }
00718
00719
00720
00724 public static void setProActiveSecurityManager(
00725 ProActiveSecurityManager server) {
00726 if (runtimeSecurityManager != null) {
00727 return;
00728 }
00729
00730 runtimeSecurityManager = server;
00731 }
00732
00733
00734
00735
00736 public void setDefaultNodeVirtualNodeName(String s) {
00737 ProActiveLogger.getLogger(Loggers.SECURITY)
00738 .debug(" setting current node as currentJVM tag " + s);
00739 defaultNodeVirtualNode = s;
00740 }
00741
00742
00743
00744
00745 public ArrayList<Entity> getEntities(String nodeName) {
00746 ProActiveSecurityManager nodeSecurityManager = null;
00747 Entity nodeEntity = null;
00748 String nodeVirtualName = nodeMap.get(nodeName).getVirtualNodeName();
00749 nodeSecurityManager = nodeMap.get(nodeName).getSecurityManager();
00750
00751 if (nodeSecurityManager != null) {
00752 nodeEntity = new EntityVirtualNode(nodeVirtualName,
00753 nodeSecurityManager.getPolicyServer()
00754 .getApplicationCertificate(),
00755 nodeSecurityManager.getCertificate());
00756 }
00757
00758 ArrayList<Entity> entities = null;
00759
00760
00761 if (entities == null) {
00762 entities = new ArrayList<Entity>();
00763 }
00764
00765 entities.add(nodeEntity);
00766
00767 return entities;
00768 }
00769
00775 public ArrayList getEntities(SecurityEntity securityEntity) {
00776 if (true) {
00777 throw new RuntimeException();
00778 }
00779
00780 return null;
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819 }
00820
00821
00822
00823
00824 public ArrayList<Entity> getEntities() {
00825 PolicyServer policyServer = null;
00826
00827 if ((runtimeSecurityManager != null) &&
00828 ((policyServer = runtimeSecurityManager.getPolicyServer()) != null)) {
00829 Entity e = new EntityCertificate(policyServer.getApplicationCertificate(),
00830 runtimeSecurityManager.getCertificate());
00831 ArrayList<Entity> array = new ArrayList<Entity>();
00832 array.add(e);
00833
00834 return array;
00835 }
00836
00837 return null;
00838 }
00839
00843 public SecurityContext getPolicy(SecurityContext sc)
00844 throws SecurityNotAvailableException {
00845 if (runtimeSecurityManager == null) {
00846 return sc;
00847 }
00848
00849 PolicyServer policyServer = runtimeSecurityManager.getPolicyServer();
00850
00851 return policyServer.getPolicy(sc);
00852 }
00853
00857 public String getJobID() {
00858 return vmInformation.getJobID();
00859 }
00860
00861 public byte[] getClassDataFromParentRuntime(String className)
00862 throws ProActiveException {
00863 byte[] classData = null;
00864
00865 if (parentRuntime != null) {
00866 classData = parentRuntime.getClassDataFromThisRuntime(className);
00867
00868 if (classData == null) {
00869
00870 classData = parentRuntime.getClassDataFromParentRuntime(className);
00871 }
00872
00873 if (classData != null) {
00874
00875 ClassDataCache.instance().addClassData(className, classData);
00876
00877 if (runtimeLogger.isDebugEnabled()) {
00878 runtimeLogger.debug(getURL() + " -- > Returning class " +
00879 className + " found in " + parentRuntime.getURL());
00880 }
00881
00882 return classData;
00883 }
00884 }
00885
00886 return null;
00887 }
00888
00889 public synchronized byte[] getClassDataFromThisRuntime(String className)
00890 throws ProActiveException {
00891 byte[] classData = null;
00892
00893
00894
00895 classData = ClassDataCache.instance().getClassData(className);
00896
00897
00898 if (classData != null) {
00899 return classData;
00900 }
00901
00902 try {
00903
00904 classData = FileProcess.getBytesFromResource(className);
00905 } catch (IOException e2) {
00906 e2.printStackTrace();
00907 }
00908
00909 if (classData != null) {
00910 ClassDataCache.instance().addClassData(className, classData);
00911
00912 return classData;
00913 }
00914
00915 if (parentRuntime == null) {
00916
00917 classData = generateStub(className);
00918
00919 if (classData != null) {
00920 return classData;
00921 }
00922 }
00923
00924 return null;
00925 }
00926
00927 public void launchMain(String className, String[] parameters)
00928 throws ClassNotFoundException, NoSuchMethodException, ProActiveException {
00929 Class mainClass = Class.forName(className);
00930 Method mainMethod = mainClass.getMethod("main",
00931 new Class[] { String[].class });
00932 new LauncherThread(mainMethod, parameters).start();
00933 }
00934
00935 public void newRemote(String className)
00936 throws ClassNotFoundException, ProActiveException {
00937 Class remoteClass = Class.forName(className);
00938 new LauncherThread(remoteClass).start();
00939 }
00940
00941
00942 public byte[] generateStub(String className) {
00943 byte[] classData = null;
00944
00945 if (Utils.isStubClassName(className)) {
00946
00947
00948
00949
00950 String classname = Utils.convertStubClassNameToClassName(className);
00951
00952
00953
00954
00955
00956
00957 if (MOPClassLoader.BYTE_CODE_MANIPULATOR.equals("javassist")) {
00958 classData = JavassistByteCodeStubBuilder.create(classname, null);
00959 } else {
00960
00961 System.err.println(
00962 "byteCodeManipulator argument is optionnal. If specified, it can only be set to javassist (ASM is no longer supported).");
00963 System.err.println(
00964 "Any other setting will result in the use of javassist, the default bytecode manipulator framework");
00965 }
00966
00967
00968
00969 }
00970
00971 if (classData != null) {
00972 ClassDataCache.instance().addClassData(className, classData);
00973
00974 return classData;
00975 }
00976
00977
00978 classData = org.objectweb.proactive.core.component.gen.Utils.getClassData(className);
00979
00980 if (classData != null) {
00981 ClassDataCache.instance().addClassData(className, classData);
00982
00983 return classData;
00984 }
00985
00986 return null;
00987 }
00988
00989
00990
00991
00992 public void terminateSession(long sessionID)
00993 throws SecurityNotAvailableException {
00994 runtimeSecurityManager.terminateSession(sessionID);
00995 }
00996
00997
00998
00999
01000 public X509Certificate getCertificate()
01001 throws SecurityNotAvailableException {
01002 return runtimeSecurityManager.getCertificate();
01003 }
01004
01005
01006
01007
01008 public ProActiveSecurityManager getProActiveSecurityManager() {
01009 return runtimeSecurityManager;
01010 }
01011
01012
01013
01014
01015 public long startNewSession(Communication policy)
01016 throws SecurityNotAvailableException, RenegotiateSessionException {
01017 return runtimeSecurityManager.startNewSession(policy);
01018 }
01019
01020
01021
01022
01023 public PublicKey getPublicKey() throws SecurityNotAvailableException {
01024 return runtimeSecurityManager.getPublicKey();
01025 }
01026
01027
01028
01029
01030 public byte[] randomValue(long sessionID, byte[] clientRandomValue)
01031 throws SecurityNotAvailableException {
01032 try {
01033 return runtimeSecurityManager.randomValue(sessionID,
01034 clientRandomValue);
01035 } catch (Exception e) {
01036 e.printStackTrace();
01037 }
01038
01039 return null;
01040 }
01041
01042
01043
01044
01045 public byte[][] publicKeyExchange(long sessionID, byte[] myPublicKey,
01046 byte[] myCertificate, byte[] signature)
01047 throws SecurityNotAvailableException, RenegotiateSessionException {
01048 if (runtimeSecurityManager != null) {
01049 try {
01050 return runtimeSecurityManager.publicKeyExchange(sessionID,
01051 myPublicKey, myCertificate, signature);
01052 } catch (KeyExchangeException e) {
01053 e.printStackTrace();
01054 }
01055 } else {
01056 throw new SecurityNotAvailableException();
01057 }
01058
01059 return null;
01060 }
01061
01062
01063
01064
01065 public byte[][] secretKeyExchange(long sessionID, byte[] encodedAESKey,
01066 byte[] encodedIVParameters, byte[] encodedClientMacKey,
01067 byte[] encodedLockData, byte[] parametersSignature)
01068 throws SecurityNotAvailableException, RenegotiateSessionException {
01069 return runtimeSecurityManager.secretKeyExchange(sessionID,
01070 encodedAESKey, encodedIVParameters, encodedClientMacKey,
01071 encodedLockData, parametersSignature);
01072 }
01073
01074
01075
01076
01077 public byte[] getCertificateEncoded() throws SecurityNotAvailableException {
01078 return runtimeSecurityManager.getCertificateEncoded();
01079 }
01080
01081 public ExternalProcess getProcessToDeploy(
01082 ProActiveRuntime proActiveRuntimeDist, String creatorID, String vmName,
01083 String padURL) throws ProActiveException {
01084 ProActiveDescriptor pad = descriptorMap.get(padURL);
01085
01086 if (pad == null) {
01087 logger.info("Cannot find descriptor, " + padURL);
01088
01089 return null;
01090 }
01091
01092 notifyListeners(this,
01093 RuntimeRegistrationEvent.FORWARDER_RUNTIME_REGISTERED,
01094 proActiveRuntimeDist, creatorID, null, vmName);
01095
01096 return pad.getHierarchicalProcess(vmName);
01097 }
01098
01099 public String getVNName(String nodename) throws ProActiveException {
01100 return nodeMap.get(nodename).getVirtualNodeName();
01101 }
01102
01103
01104
01105
01106 protected static class VMInformationImpl implements VMInformation,
01107 java.io.Serializable {
01108 private java.net.InetAddress hostInetAddress;
01109
01110
01111 private java.rmi.dgc.VMID uniqueVMID;
01112 private String name;
01113 private String processCreatorId;
01114 private String jobId;
01115 private String hostName;
01116 private DeployerTag deployerTag;
01117
01118 public VMInformationImpl() throws java.net.UnknownHostException {
01119 this.uniqueVMID = UniqueID.getCurrentVMID();
01120 hostInetAddress = java.net.InetAddress.getLocalHost();
01121 hostName = UrlBuilder.getHostNameorIP(hostInetAddress);
01122 this.processCreatorId = "jvm";
01123
01124
01125
01126
01127 String random = Integer.toString(ProActiveRuntimeImpl.getNextInt());
01128
01129 if (System.getProperty("proactive.runtime.name") != null) {
01130 this.name = System.getProperty("proactive.runtime.name");
01131
01132 if (this.name.indexOf("PA_JVM") < 0) {
01133 runtimeLogger.warn(
01134 "WARNING !!! The name of a ProActiveRuntime MUST contain PA_JVM string \n" +
01135 "WARNING !!! Property proactive.runtime.name does not contain PA_JVM. This name is not adapted to IC2D tool");
01136 }
01137 } else {
01138 this.name = "PA_JVM" + random + "_" + hostName;
01139 }
01140
01141 if (System.getProperty("proactive.jobid") != null) {
01142 this.jobId = System.getProperty("proactive.jobid");
01143 } else {
01144
01145 this.jobId = "JOB-" + random;
01146 }
01147
01148 deployerTag = new DeployerTag(ProActiveConfiguration.getGroupInformation());
01149 }
01150
01151
01152
01153
01154
01155
01156
01157 public java.rmi.dgc.VMID getVMID() {
01158 return uniqueVMID;
01159 }
01160
01161 public String getName() {
01162 return name;
01163 }
01164
01165 public java.net.InetAddress getInetAddress() {
01166 return hostInetAddress;
01167 }
01168
01169 public String getCreationProtocolID() {
01170 return this.processCreatorId;
01171 }
01172
01173 public void setCreationProtocolID(String protocolId) {
01174 this.processCreatorId = protocolId;
01175 }
01176
01180 public String getJobID() {
01181 return this.jobId;
01182 }
01183
01187 public String getHostName() {
01188 return this.hostName;
01189 }
01190
01194 public String getDescriptorVMName() {
01195 return name;
01196 }
01197
01201 public DeployerTag getDeployerTag() {
01202 return deployerTag;
01203 }
01204 }
01205
01206
01207
01208
01209
01213 private class LauncherThread extends Thread {
01214 private boolean launchMain;
01215 private Method mainMethod;
01216 private Class remoteClass;
01217 private String[] parameters;
01218
01219 public LauncherThread(Class remoteClass) {
01220 this.remoteClass = remoteClass;
01221 launchMain = false;
01222 }
01223
01224 public LauncherThread(Method mainMethod, String[] parameters) {
01225 this.mainMethod = mainMethod;
01226 this.parameters = parameters;
01227 launchMain = true;
01228 }
01229
01230 public void run() {
01231 if (launchMain) {
01232 try {
01233 mainMethod.invoke(null, new Object[] { parameters });
01234 } catch (InvocationTargetException e) {
01235 e.printStackTrace();
01236 } catch (IllegalAccessException e) {
01237 e.printStackTrace();
01238 }
01239 } else {
01240 try {
01241 remoteClass.newInstance();
01242 } catch (IllegalAccessException e) {
01243 e.printStackTrace();
01244 } catch (InstantiationException e) {
01245 e.printStackTrace();
01246 }
01247 }
01248 }
01249 }
01250
01254 public Object setLocalNodeProperty(String nodeName, String key, String value) {
01255 return this.nodeMap.get(nodeName).setProperty(key, value);
01256 }
01257
01261 public String getLocalNodeProperty(String nodeName, String key) {
01262 return this.nodeMap.get(nodeName).getProperty(key);
01263 }
01264 }