org/objectweb/proactive/core/body/AbstractUniversalBody.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.util.HashMap;
00035 import java.util.Map;
00036 
00037 import org.objectweb.proactive.core.UniqueID;
00038 import org.objectweb.proactive.core.component.request.Shortcut;
00039 import org.objectweb.proactive.core.exceptions.NonFunctionalException;
00040 import org.objectweb.proactive.core.exceptions.manager.NFEListener;
00041 import org.objectweb.proactive.core.exceptions.manager.NFEListenerList;
00042 
00043 
00058 public abstract class AbstractUniversalBody implements UniversalBody,
00059     java.io.Serializable {
00060     //
00061     // -- PROTECTED MEMBERS -----------------------------------------------
00062     //
00063 
00065     protected UniqueID bodyID;
00066 
00069     protected BodyMap location;
00070 
00072     protected String nodeURL;
00073 
00075     protected transient UniversalBody remoteBody;
00076     protected RemoteBodyFactory remoteBodyFactory;
00077     protected String jobID;
00078     protected Map shortcuts = null; // key = functionalItfID, value=shortcut
00079 
00080     //
00081     // -- PRIVATE MEMBERS -----------------------------------------------
00082     //
00083     //
00084     // -- CONSTRUCTORS -----------------------------------------------
00085     //
00086 
00091     public AbstractUniversalBody() {
00092     }
00093 
00100     public AbstractUniversalBody(String nodeURL,
00101         RemoteBodyFactory remoteBodyFactory, String jobID) {
00102         this.nodeURL = nodeURL;
00103         this.bodyID = new UniqueID();
00104         this.location = new BodyMap();
00105         this.jobID = jobID;
00106         this.remoteBodyFactory = remoteBodyFactory;
00107         this.remoteBody = remoteBodyFactory.newRemoteBody(this);
00108     }
00109 
00110     //
00111     // -- PUBLIC METHODS -----------------------------------------------
00112     //
00113     //
00114     // -- implements UniversalBody -----------------------------------------------
00115     //
00116     public String getJobID() {
00117         return jobID;
00118     }
00119 
00120     public String getNodeURL() {
00121         return nodeURL;
00122     }
00123 
00124     public BodyAdapter getRemoteAdapter() {
00125         return (BodyAdapter) remoteBody;
00126     }
00127 
00128     public UniqueID getID() {
00129         return bodyID;
00130     }
00131 
00132     public void updateLocation(UniqueID bodyID, UniversalBody body) {
00133         location.updateBody(bodyID, body);
00134     }
00135 
00136     //
00137     // -- PROTECTED METHODS -----------------------------------------------
00138     //
00139     //
00140     // -- PRIVATE METHODS -----------------------------------------------
00141     //
00142     private void writeObject(java.io.ObjectOutputStream out)
00143         throws java.io.IOException {
00144         out.defaultWriteObject();
00145     }
00146 
00147     private void readObject(java.io.ObjectInputStream in)
00148         throws java.io.IOException, ClassNotFoundException {
00149         in.defaultReadObject();
00150         //System.out.println("@@@@@@@@@@@@@@@@@@" + this.jobID);
00151         if (bodyID == null) {
00152             // it may happen that the bodyID is set to null before serialization if we want to
00153             // create a copy of the Body that is distinct from the original
00154             bodyID = new UniqueID();
00155         }
00156 
00157         // remoteBody is transient so we recreate it here
00158         this.remoteBody = remoteBodyFactory.newRemoteBody(this);
00159     }
00160 
00161     /*
00162      *
00163      * @see org.objectweb.proactive.core.body.UniversalBody#createShortcut(org.objectweb.proactive.core.component.request.Shortcut)
00164      */
00165     public void createShortcut(Shortcut shortcut) throws IOException {
00166         if (shortcuts == null) {
00167             shortcuts = new HashMap();
00168         }
00169         shortcuts.put(shortcut.getLinkedInterfaceID(), shortcut);
00170     }
00171 
00172     // NFEProducer implementation
00173     private NFEListenerList nfeListeners = null;
00174 
00175     public void addNFEListener(NFEListener listener) {
00176         if (nfeListeners == null) {
00177             nfeListeners = new NFEListenerList();
00178         }
00179         nfeListeners.addNFEListener(listener);
00180     }
00181 
00182     public void removeNFEListener(NFEListener listener) {
00183         if (nfeListeners != null) {
00184             nfeListeners.removeNFEListener(listener);
00185         }
00186     }
00187 
00188     public int fireNFE(NonFunctionalException e) {
00189         if (nfeListeners != null) {
00190             return nfeListeners.fireNFE(e);
00191         }
00192         return 0;
00193     }
00194 }

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