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.io.ObjectStreamException;
00035 import java.io.Serializable;
00036 import java.lang.reflect.InvocationTargetException;
00037 import java.rmi.AlreadyBoundException;
00038 import java.rmi.UnmarshalException;
00039 import java.security.PublicKey;
00040 import java.security.cert.X509Certificate;
00041 import java.util.ArrayList;
00042 
00043 import org.objectweb.proactive.Body;
00044 import org.objectweb.proactive.core.ProActiveException;
00045 import org.objectweb.proactive.core.UniqueRuntimeID;
00046 import org.objectweb.proactive.core.body.UniversalBody;
00047 import org.objectweb.proactive.core.body.ft.checkpointing.Checkpoint;
00048 import org.objectweb.proactive.core.config.ProActiveConfiguration;
00049 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
00050 import org.objectweb.proactive.core.descriptor.data.VirtualNode;
00051 import org.objectweb.proactive.core.mop.ConstructorCall;
00052 import org.objectweb.proactive.core.mop.ConstructorCallExecutionFailedException;
00053 import org.objectweb.proactive.core.node.NodeException;
00054 import org.objectweb.proactive.core.process.ExternalProcess;
00055 import org.objectweb.proactive.core.process.UniversalProcess;
00056 import org.objectweb.proactive.ext.security.Communication;
00057 import org.objectweb.proactive.ext.security.ProActiveSecurityManager;
00058 import org.objectweb.proactive.ext.security.SecurityContext;
00059 import org.objectweb.proactive.ext.security.crypto.KeyExchangeException;
00060 import org.objectweb.proactive.ext.security.exceptions.RenegotiateSessionException;
00061 import org.objectweb.proactive.ext.security.exceptions.SecurityNotAvailableException;
00062 import org.objectweb.proactive.ext.security.securityentity.Entity;
00063 
00064 
00075 public class ProActiveRuntimeAdapterImpl extends ProActiveRuntimeAdapter
00076     implements Serializable {
00077     protected RemoteProActiveRuntime proActiveRuntime;
00078     protected String proActiveRuntimeURL;
00079     private UniqueRuntimeID urid; 
00080 
00081     
00082     
00083     protected boolean alreadykilled = false;
00084 
00085     
00086     
00087     
00088     public ProActiveRuntimeAdapterImpl() {
00089     }
00090 
00091     public ProActiveRuntimeAdapterImpl(RemoteProActiveRuntime proActiveRuntime)
00092         throws ProActiveException {
00093         this.proActiveRuntime = proActiveRuntime;
00094 
00095         try {
00096             this.vmInformation = proActiveRuntime.getVMInformation();
00097             this.proActiveRuntimeURL = proActiveRuntime.getURL();
00098             this.urid = new UniqueRuntimeID(proActiveRuntime.getVMInformation()
00099                                                             .getName(),
00100                     proActiveRuntime.getVMInformation().getVMID());
00101         } catch (IOException e) {
00102             throw new ProActiveException(e);
00103         }
00104     }
00105 
00106     protected Object readResolve() throws ObjectStreamException {
00107         if (ProActiveConfiguration.isForwarder()) {
00108             ProActiveRuntimeForwarderImpl partf = (ProActiveRuntimeForwarderImpl) ProActiveRuntimeImpl.getProActiveRuntime();
00109 
00110             if (!partf.registeredRuntimes.containsKey(urid)) {
00111                 partf.registeredRuntimes.put(urid, this);
00112             }
00113 
00114             try {
00115                 ProActiveRuntime part = RuntimeFactory.getDefaultRuntime();
00116                 ProActiveRuntimeAdapterForwarderImpl partAdapter = (ProActiveRuntimeAdapterForwarderImpl) part;
00117 
00118                 return new ProActiveRuntimeAdapterForwarderImpl(partAdapter,
00119                     this);
00120             } catch (ProActiveException e) {
00121                 runtimeLogger.warn(e.getMessage());
00122 
00123                 return this;
00124             }
00125         }
00126 
00127         return this;
00128     }
00129 
00130     
00131     
00132     
00133     public boolean equals(Object o) {
00134         if (!(o instanceof ProActiveRuntimeAdapterImpl)) {
00135             return false;
00136         }
00137 
00138         ProActiveRuntimeAdapterImpl runtime = (ProActiveRuntimeAdapterImpl) o;
00139 
00140         return proActiveRuntime.equals(runtime.proActiveRuntime);
00141     }
00142 
00143     public int hashCode() {
00144         return proActiveRuntime.hashCode();
00145     }
00146 
00147     
00148     
00149     
00150 
00155     public String createLocalNode(String nodeName,
00156         boolean replacePreviousBinding, ProActiveSecurityManager policyServer,
00157         String vnName, String jobId)
00158         throws NodeException, AlreadyBoundException {
00159         try {
00160             return proActiveRuntime.createLocalNode(nodeName,
00161                 replacePreviousBinding, policyServer, vnName, jobId);
00162         } catch (IOException e) {
00163             throw new NodeException(e);
00164         }
00165     }
00166 
00171     public void killAllNodes() throws ProActiveException {
00172         try {
00173             proActiveRuntime.killAllNodes();
00174         } catch (IOException e) {
00175             throw new ProActiveException(e);
00176         }
00177     }
00178 
00183     public void killNode(String nodeName) throws ProActiveException {
00184         try {
00185             proActiveRuntime.killNode(nodeName);
00186         } catch (IOException e) {
00187             throw new ProActiveException(e);
00188         }
00189     }
00190 
00196     public void createVM(UniversalProcess remoteProcess)
00197         throws IOException, ProActiveException {
00198         proActiveRuntime.createVM(remoteProcess);
00199     }
00200 
00205     public String[] getLocalNodeNames() throws ProActiveException {
00206         try {
00207             return proActiveRuntime.getLocalNodeNames();
00208         } catch (IOException e) {
00209             throw new ProActiveException(e);
00210         }
00211     }
00212 
00216     public VMInformation getVMInformation() {
00217         return vmInformation;
00218     }
00219 
00224     public void register(ProActiveRuntime proActiveRuntimeDist,
00225         String proActiveRuntimeUrl, String creatorID, String creationProtocol,
00226         String vmName) throws ProActiveException {
00227         try {
00228             proActiveRuntime.register(proActiveRuntimeDist,
00229                 proActiveRuntimeUrl, creatorID, creationProtocol, vmName);
00230         } catch (IOException e) {
00231             throw new ProActiveException(e);
00232         }
00233     }
00234 
00239     public void unregister(ProActiveRuntime proActiveRuntimeDist,
00240         String proActiveRuntimeUrl, String creatorID, String creationProtocol,
00241         String vmName) throws ProActiveException {
00242         try {
00243             this.proActiveRuntime.unregister(proActiveRuntimeDist,
00244                 proActiveRuntimeUrl, creatorID, creationProtocol, vmName);
00245         } catch (IOException e) {
00246             throw new ProActiveException(e);
00247         }
00248     }
00249 
00254     public ProActiveRuntime[] getProActiveRuntimes() throws ProActiveException {
00255         try {
00256             return proActiveRuntime.getProActiveRuntimes();
00257         } catch (IOException e) {
00258             throw new ProActiveException(e);
00259         }
00260     }
00261 
00266     public ProActiveRuntime getProActiveRuntime(String proActiveRuntimeName)
00267         throws ProActiveException {
00268         try {
00269             return proActiveRuntime.getProActiveRuntime(proActiveRuntimeName);
00270         } catch (IOException e) {
00271             throw new ProActiveException(e);
00272         }
00273     }
00274 
00279     public void addAcquaintance(String proActiveRuntimeName)
00280         throws ProActiveException {
00281         try {
00282             proActiveRuntime.addAcquaintance(proActiveRuntimeName);
00283         } catch (IOException e) {
00284             throw new ProActiveException(e);
00285         }
00286     }
00287 
00292     public String[] getAcquaintances() throws ProActiveException {
00293         try {
00294             return proActiveRuntime.getAcquaintances();
00295         } catch (IOException e) {
00296             throw new ProActiveException(e);
00297         }
00298     }
00299 
00304     public void rmAcquaintance(String proActiveRuntimeName)
00305         throws ProActiveException {
00306         try {
00307             proActiveRuntime.rmAcquaintance(proActiveRuntimeName);
00308         } catch (IOException e) {
00309             throw new ProActiveException(e);
00310         }
00311     }
00312 
00316     public void killRT(boolean softly) throws Exception {
00317         try {
00318             if (!alreadykilled) {
00319                 proActiveRuntime.killRT(softly);
00320             }
00321 
00322             alreadykilled = true;
00323         } catch (UnmarshalException e) {
00324             
00325             alreadykilled = true;
00326             throw e;
00327         }
00328     }
00329 
00333     public String getURL() {
00334         return proActiveRuntimeURL;
00335     }
00336 
00341     public ArrayList getActiveObjects(String nodeName)
00342         throws ProActiveException {
00343         try {
00344             return proActiveRuntime.getActiveObjects(nodeName);
00345         } catch (IOException e) {
00346             throw new ProActiveException(e);
00347         }
00348     }
00349 
00354     public ArrayList getActiveObjects(String nodeName, String className)
00355         throws ProActiveException {
00356         try {
00357             return proActiveRuntime.getActiveObjects(nodeName, className);
00358         } catch (IOException e) {
00359             throw new ProActiveException(e);
00360         }
00361     }
00362 
00367     public VirtualNode getVirtualNode(String virtualNodeName)
00368         throws ProActiveException {
00369         try {
00370             return proActiveRuntime.getVirtualNode(virtualNodeName);
00371         } catch (IOException e) {
00372             throw new ProActiveException(e);
00373         }
00374     }
00375 
00380     public void registerVirtualNode(String virtualNodeName,
00381         boolean replacePreviousBinding)
00382         throws ProActiveException, AlreadyBoundException {
00383         try {
00384             proActiveRuntime.registerVirtualNode(virtualNodeName,
00385                 replacePreviousBinding);
00386         } catch (IOException e) {
00387             throw new ProActiveException(e);
00388         }
00389     }
00390 
00395     public void unregisterVirtualNode(String virtualNodeName)
00396         throws ProActiveException {
00397         try {
00398             proActiveRuntime.unregisterVirtualNode(virtualNodeName);
00399         } catch (IOException e) {
00400             throw new ProActiveException(e);
00401         }
00402     }
00403 
00408     public void unregisterAllVirtualNodes() throws ProActiveException {
00409         try {
00410             proActiveRuntime.unregisterAllVirtualNodes();
00411         } catch (IOException e) {
00412             throw new ProActiveException(e);
00413         }
00414     }
00415 
00420     public String getJobID(String nodeUrl) throws ProActiveException {
00421         try {
00422             return proActiveRuntime.getJobID(nodeUrl);
00423         } catch (IOException e) {
00424             throw new ProActiveException(e);
00425         }
00426     }
00427 
00432     public UniversalBody createBody(String nodeName,
00433         ConstructorCall bodyConstructorCall, boolean isNodeLocal)
00434         throws ConstructorCallExecutionFailedException,
00435             InvocationTargetException, ProActiveException {
00436         try {
00437             return proActiveRuntime.createBody(nodeName, bodyConstructorCall,
00438                 isNodeLocal);
00439         } catch (IOException e) {
00440             throw new ProActiveException(e);
00441         }
00442     }
00443 
00448     public UniversalBody receiveBody(String nodeName, Body body)
00449         throws ProActiveException {
00450         try {
00451             return proActiveRuntime.receiveBody(nodeName, body);
00452         } catch (IOException e) {
00453             throw new ProActiveException(e);
00454         }
00455     }
00456 
00461     public UniversalBody receiveCheckpoint(String nodeName, Checkpoint ckpt,
00462         int inc) throws ProActiveException {
00463         try {
00464             return proActiveRuntime.receiveCheckpoint(nodeName, ckpt, inc);
00465         } catch (IOException e) {
00466             throw new ProActiveException(e);
00467         }
00468     }
00469 
00474     public String getVNName(String Nodename) throws ProActiveException {
00475         try {
00476             return proActiveRuntime.getVNName(Nodename);
00477         } catch (IOException e) {
00478             throw new ProActiveException(e);
00479         }
00480     }
00481 
00486     public byte[] getClassDataFromThisRuntime(String className)
00487         throws ProActiveException {
00488         try {
00489             return proActiveRuntime.getClassDataFromThisRuntime(className);
00490         } catch (IOException e) {
00491             throw new ProActiveException(e);
00492         }
00493     }
00494 
00499     public byte[] getClassDataFromParentRuntime(String className)
00500         throws ProActiveException {
00501         try {
00502             return proActiveRuntime.getClassDataFromParentRuntime(className);
00503         } catch (IOException e) {
00504             throw new ProActiveException(e);
00505         }
00506     }
00507 
00508     public ExternalProcess getProcessToDeploy(
00509         ProActiveRuntime proActiveRuntimeDist, String creatorID, String vmName,
00510         String padURL) throws ProActiveException {
00511         try {
00512             return proActiveRuntime.getProcessToDeploy(proActiveRuntimeDist,
00513                 creatorID, vmName, padURL);
00514         } catch (IOException e) {
00515             throw new ProActiveException(e);
00516         }
00517     }
00518 
00519     
00520     
00521     
00522 
00526     public String getJobID() {
00527         return vmInformation.getJobID();
00528     }
00529 
00530     
00531     
00532     
00533     public X509Certificate getCertificate()
00534         throws SecurityNotAvailableException {
00535         try {
00536             return proActiveRuntime.getCertificate();
00537         } catch (IOException e) {
00538             e.printStackTrace();
00539 
00540             return null;
00541         }
00542     }
00543 
00544     public long startNewSession(Communication policy)
00545         throws SecurityNotAvailableException, RenegotiateSessionException {
00546         try {
00547             return proActiveRuntime.startNewSession(policy);
00548         } catch (IOException e) {
00549             e.printStackTrace();
00550 
00551             return 0;
00552         }
00553     }
00554 
00555     public PublicKey getPublicKey() throws SecurityNotAvailableException {
00556         try {
00557             return proActiveRuntime.getPublicKey();
00558         } catch (IOException e) {
00559             e.printStackTrace();
00560 
00561             return null;
00562         }
00563     }
00564 
00565     public byte[] randomValue(long sessionID, byte[] clientRandomValue)
00566         throws SecurityNotAvailableException, RenegotiateSessionException {
00567         try {
00568             return proActiveRuntime.randomValue(sessionID, clientRandomValue);
00569         } catch (IOException e) {
00570             e.printStackTrace();
00571 
00572             return null;
00573         }
00574     }
00575 
00576     public byte[][] publicKeyExchange(long sessionID, byte[] myPublicKey,
00577         byte[] myCertificate, byte[] signature)
00578         throws SecurityNotAvailableException, RenegotiateSessionException,
00579             KeyExchangeException {
00580         try {
00581             return proActiveRuntime.publicKeyExchange(sessionID, myPublicKey,
00582                 myCertificate, signature);
00583         } catch (IOException e) {
00584             e.printStackTrace();
00585 
00586             return null;
00587         }
00588     }
00589 
00590     public byte[][] secretKeyExchange(long sessionID, byte[] encodedAESKey,
00591         byte[] encodedIVParameters, byte[] encodedClientMacKey,
00592         byte[] encodedLockData, byte[] parametersSignature)
00593         throws SecurityNotAvailableException, RenegotiateSessionException {
00594         try {
00595             return proActiveRuntime.secretKeyExchange(sessionID, encodedAESKey,
00596                 encodedIVParameters, encodedClientMacKey, encodedLockData,
00597                 parametersSignature);
00598         } catch (IOException e) {
00599             e.printStackTrace();
00600 
00601             return null;
00602         }
00603     }
00604 
00605     public SecurityContext getPolicy(SecurityContext securityContext)
00606         throws SecurityNotAvailableException {
00607         try {
00608             return proActiveRuntime.getPolicy(securityContext);
00609         } catch (IOException e) {
00610             e.printStackTrace();
00611 
00612             return null;
00613         }
00614     }
00615 
00616     public byte[] getCertificateEncoded() throws SecurityNotAvailableException {
00617         try {
00618             return proActiveRuntime.getCertificateEncoded();
00619         } catch (IOException e) {
00620             e.printStackTrace();
00621 
00622             return null;
00623         }
00624     }
00625 
00626     public ArrayList<Entity> getEntities() throws SecurityNotAvailableException {
00627         try {
00628             return proActiveRuntime.getEntities();
00629         } catch (IOException e) {
00630             e.printStackTrace();
00631 
00632             return null;
00633         }
00634     }
00635 
00636     public void terminateSession(long sessionID)
00637         throws SecurityNotAvailableException {
00638         try {
00639             proActiveRuntime.terminateSession(sessionID);
00640         } catch (IOException e) {
00641             e.printStackTrace();
00642         }
00643     }
00644 
00645     public void launchMain(String className, String[] parameters)
00646         throws ClassNotFoundException, NoSuchMethodException, ProActiveException {
00647         try {
00648             proActiveRuntime.launchMain(className, parameters);
00649         } catch (IOException e) {
00650             throw new ProActiveException(e);
00651         }
00652     }
00653 
00654     public void newRemote(String className)
00655         throws ClassNotFoundException, ProActiveException {
00656         try {
00657             proActiveRuntime.newRemote(className);
00658         } catch (IOException e) {
00659             throw new ProActiveException(e);
00660         }
00661     }
00662 
00663     public ProActiveDescriptor getDescriptor(String url,
00664         boolean isHierarchicalSearch) throws IOException, ProActiveException {
00665         return proActiveRuntime.getDescriptor(url, isHierarchicalSearch);
00666     }
00667 
00668     public Object setLocalNodeProperty(String nodeName, String key, String value)
00669         throws ProActiveException {
00670         try {
00671             return this.proActiveRuntime.setLocalNodeProperty(nodeName, key,
00672                 value);
00673         } catch (IOException e) {
00674             throw new ProActiveException(e);
00675         }
00676     }
00677 
00678     public String getLocalNodeProperty(String nodeName, String key)
00679         throws ProActiveException {
00680         try {
00681             return this.proActiveRuntime.getLocalNodeProperty(nodeName, key);
00682         } catch (IOException e) {
00683             throw new ProActiveException(e);
00684         }
00685     }
00686 }