org/objectweb/proactive/core/body/BodyAdapterImpl.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.body;
00032 
00033 import java.io.IOException;
00034 import java.io.ObjectStreamException;
00035 import java.io.Serializable;
00036 import java.security.PublicKey;
00037 import java.security.cert.X509Certificate;
00038 import java.util.ArrayList;
00039 
00040 import org.objectweb.proactive.Body;
00041 import org.objectweb.proactive.core.ProActiveException;
00042 import org.objectweb.proactive.core.ProActiveRuntimeException;
00043 import org.objectweb.proactive.core.UniqueID;
00044 import org.objectweb.proactive.core.body.ft.internalmsg.FTMessage;
00045 import org.objectweb.proactive.core.body.reply.Reply;
00046 import org.objectweb.proactive.core.body.request.Request;
00047 import org.objectweb.proactive.core.component.request.Shortcut;
00048 import org.objectweb.proactive.core.config.ProActiveConfiguration;
00049 import org.objectweb.proactive.core.exceptions.NonFunctionalException;
00050 import org.objectweb.proactive.core.exceptions.manager.NFEListener;
00051 import org.objectweb.proactive.core.runtime.ProActiveRuntimeForwarderImpl;
00052 import org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl;
00053 import org.objectweb.proactive.ext.security.Communication;
00054 import org.objectweb.proactive.ext.security.SecurityContext;
00055 import org.objectweb.proactive.ext.security.crypto.KeyExchangeException;
00056 import org.objectweb.proactive.ext.security.exceptions.RenegotiateSessionException;
00057 import org.objectweb.proactive.ext.security.exceptions.SecurityNotAvailableException;
00058 import org.objectweb.proactive.ext.security.securityentity.Entity;
00059 
00060 
00069 public abstract class BodyAdapterImpl extends BodyAdapter implements Cloneable,
00070     Serializable {
00071 
00073     protected RemoteBody proxiedRemoteBody;
00074 
00075     //------------------------------------------
00076     // Adpater Methods
00077     //------------------------------------------
00078 
00084     public void changeProxiedBody(Body newBody) throws IOException {
00085         this.proxiedRemoteBody.changeProxiedBody(newBody);
00086     }
00087 
00097     public abstract UniversalBody lookup(String url) throws java.io.IOException;
00098 
00106     public abstract void register(String url) throws java.io.IOException;
00107 
00113     public abstract void unregister(String url) throws java.io.IOException;
00114 
00115     public boolean equals(Object o) {
00116         if (!(o instanceof BodyAdapter)) {
00117             return false;
00118         }
00119 
00120         BodyAdapterImpl rba = (BodyAdapterImpl) o;
00121 
00122         return proxiedRemoteBody.equals(rba.proxiedRemoteBody);
00123     }
00124 
00125     public int hashCode() {
00126         return proxiedRemoteBody.hashCode();
00127     }
00128 
00129     protected void construct(RemoteBody remoteBody) throws ProActiveException {
00130         this.proxiedRemoteBody = remoteBody;
00131 
00132         if (bodyLogger.isDebugEnabled()) {
00133             bodyLogger.debug(proxiedRemoteBody.getClass());
00134         }
00135 
00136         try {
00137             this.bodyID = remoteBody.getID();
00138             this.jobID = remoteBody.getJobID();
00139         } catch (IOException e) {
00140             throw new ProActiveException(e);
00141         }
00142     }
00143 
00144     //--------------------------------------------
00145     // implements Job
00146     //--------------------------------------------
00147 
00151     public String getJobID() {
00152         return jobID;
00153     }
00154 
00155     //--------------------------------------------
00156     // implements UniversalBody
00157     //--------------------------------------------
00158 
00162     public int receiveRequest(Request request)
00163         throws IOException, RenegotiateSessionException {
00164         return proxiedRemoteBody.receiveRequest(request);
00165     }
00166 
00170     public int receiveReply(Reply r) throws IOException {
00171         return proxiedRemoteBody.receiveReply(r);
00172     }
00173 
00177     public String getNodeURL() {
00178         try {
00179             return proxiedRemoteBody.getNodeURL();
00180         } catch (IOException e) {
00181             return "cannot contact the body to get the nodeURL";
00182         }
00183     }
00184 
00188     public UniqueID getID() {
00189         return bodyID;
00190     }
00191 
00195     public void updateLocation(UniqueID id, UniversalBody body)
00196         throws IOException {
00197         proxiedRemoteBody.updateLocation(id, body);
00198     }
00199 
00203     public void createShortcut(Shortcut shortcut) throws IOException {
00204         //      TODO implement
00205         throw new ProActiveRuntimeException(
00206             "create shortcut method not implemented yet");
00207     }
00208 
00212     public BodyAdapter getRemoteAdapter() {
00213         return this;
00214     }
00215 
00219     public void terminate() throws IOException {
00220         proxiedRemoteBody.terminate();
00221     }
00222 
00226     public void enableAC() throws IOException {
00227         proxiedRemoteBody.enableAC();
00228     }
00229 
00233     public void disableAC() throws IOException {
00234         proxiedRemoteBody.disableAC();
00235     }
00236 
00240     public void setImmediateService(String methodName)
00241         throws IOException {
00242         proxiedRemoteBody.setImmediateService(methodName);
00243     }
00244 
00248     public void setImmediateService(String methodName, Class[] parametersTypes)
00249         throws IOException {
00250         proxiedRemoteBody.setImmediateService(methodName, parametersTypes);
00251     }
00252 
00256     public void removeImmediateService(String methodName,
00257         Class[] parametersTypes) throws IOException {
00258         proxiedRemoteBody.removeImmediateService(methodName, parametersTypes);
00259     }
00260 
00261     //--------------------------------------------
00262     // implements SecurityEntity
00263     //--------------------------------------------
00264 
00271     public X509Certificate getCertificate()
00272         throws SecurityNotAvailableException, IOException {
00273         return proxiedRemoteBody.getCertificate();
00274     }
00275 
00283     public long startNewSession(Communication policy)
00284         throws SecurityNotAvailableException, RenegotiateSessionException,
00285             IOException {
00286         return proxiedRemoteBody.startNewSession(policy);
00287     }
00288 
00294     public PublicKey getPublicKey()
00295         throws SecurityNotAvailableException, IOException {
00296         return proxiedRemoteBody.getPublicKey();
00297     }
00298 
00307     public byte[] randomValue(long sessionID, byte[] clientRandomValue)
00308         throws SecurityNotAvailableException, RenegotiateSessionException,
00309             IOException {
00310         return proxiedRemoteBody.randomValue(sessionID, clientRandomValue);
00311     }
00312 
00326     public byte[][] publicKeyExchange(long sessionID, byte[] myPublicKey,
00327         byte[] myCertificate, byte[] signature)
00328         throws SecurityNotAvailableException, RenegotiateSessionException,
00329             KeyExchangeException, IOException {
00330         return proxiedRemoteBody.publicKeyExchange(sessionID, myPublicKey,
00331             myCertificate, signature);
00332     }
00333 
00352     public byte[][] secretKeyExchange(long sessionID, byte[] encodedAESKey,
00353         byte[] encodedIVParameters, byte[] encodedClientMacKey,
00354         byte[] encodedLockData, byte[] parametersSignature)
00355         throws SecurityNotAvailableException, RenegotiateSessionException,
00356             IOException {
00357         return proxiedRemoteBody.secretKeyExchange(sessionID, encodedAESKey,
00358             encodedIVParameters, encodedClientMacKey, encodedLockData,
00359             parametersSignature);
00360     }
00361 
00370     public SecurityContext getPolicy(SecurityContext securityContext)
00371         throws SecurityNotAvailableException, IOException {
00372         return proxiedRemoteBody.getPolicy(securityContext);
00373     }
00374 
00379     public byte[] getCertificateEncoded()
00380         throws SecurityNotAvailableException, IOException {
00381         return proxiedRemoteBody.getCertificateEncoded();
00382     }
00383 
00389     public ArrayList<Entity> getEntities()
00390         throws SecurityNotAvailableException, IOException {
00391         return proxiedRemoteBody.getEntities();
00392     }
00393 
00399     public void terminateSession(long sessionID)
00400         throws SecurityNotAvailableException, IOException {
00401         proxiedRemoteBody.terminateSession(sessionID);
00402     }
00403 
00404     /* (non-Javadoc)
00405       * @see org.objectweb.proactive.core.body.UniversalBody#receiveFTMessage(org.objectweb.proactive.core.body.ft.internalmsg.FTMessage)
00406       */
00407     public Object receiveFTMessage(FTMessage ev) throws IOException {
00408         return this.proxiedRemoteBody.receiveFTMessage(ev);
00409     }
00410 
00411     //--------------------------------
00412     //  NFEProducer implementation
00413     //--------------------------------
00414     public void addNFEListener(NFEListener listener) {
00415         try {
00416             proxiedRemoteBody.addNFEListener(listener);
00417         } catch (IOException e) {
00418             // TODO Auto-generated catch block
00419             e.printStackTrace();
00420         }
00421     }
00422 
00423     public void removeNFEListener(NFEListener listener) {
00424         try {
00425             proxiedRemoteBody.removeNFEListener(listener);
00426         } catch (IOException e) {
00427             // TODO Auto-generated catch block
00428             e.printStackTrace();
00429         }
00430     }
00431 
00432     public int fireNFE(NonFunctionalException e) {
00433         try {
00434             return proxiedRemoteBody.fireNFE(e);
00435         } catch (IOException e1) {
00436             // TODO Auto-generated catch block
00437             e1.printStackTrace();
00438 
00439             return 0;
00440         }
00441     }
00442 
00443     protected Object readResolve() throws ObjectStreamException {
00444         if (ProActiveConfiguration.isForwarder()) {
00445             ProActiveRuntimeForwarderImpl partf = (ProActiveRuntimeForwarderImpl) ProActiveRuntimeImpl.getProActiveRuntime();
00446 
00447             try {
00448                 partf.getBodyForwarder().add((BodyAdapterImpl) this.clone());
00449 
00450                 return new BodyAdapterForwarder(partf.getBodyAdapterForwarder(),
00451                     this);
00452             } catch (CloneNotSupportedException e) {
00453                 e.printStackTrace();
00454             }
00455         }
00456 
00457         return this;
00458     }
00459     
00460 
00461     public String[] list(String url) throws IOException {
00462         throw new IOException ("Lookup is not implemented yet for this Adapter");
00463     }
00464 
00465 }

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