KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > body > AbstractUniversalBody


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

31 package org.objectweb.proactive.core.body;
32
33 import org.objectweb.proactive.core.UniqueID;
34
35
36 /**
37  * <i><font size="-1" color="#FF0000">**For internal use only** </font></i><br>
38  * <p>
39  * This class gives a common implementation of the UniversalBody interface. It provides all
40  * the non specific behavior allowing sub-class to write the detail implementation.
41  * </p><p>
42  * Each body is identify by an unique identifier.
43  * </p>
44  *
45  * @author ProActive Team
46  * @version 1.0, 2002/06
47  * @since ProActive 0.9.3
48  *
49  */

50 public abstract class AbstractUniversalBody implements UniversalBody, java.io.Serializable JavaDoc {
51
52   //
53
// -- PROTECTED MEMBERS -----------------------------------------------
54
//
55

56   /** Unique ID of the body. */
57   protected UniqueID bodyID;
58
59   /** A table containing a mapping from a UniqueID toward a Body. The location table
60    caches the location of all known bodies to whom this body communicated */

61   protected BodyMap location;
62
63   /** The URL of the node this body is attached to */
64   protected String JavaDoc nodeURL;
65
66   /** A remote version of this body that is used to send to remote peer */
67   protected transient UniversalBody remoteBody;
68
69   protected RemoteBodyFactory remoteBodyFactory;
70
71   //
72
// -- PRIVATE MEMBERS -----------------------------------------------
73
//
74

75   //
76
// -- CONSTRUCTORS -----------------------------------------------
77
//
78

79   /**
80    * Creates a new AbstractBody.
81    * Used for serialization.
82    */

83   public AbstractUniversalBody() {}
84
85   /**
86    * Creates a new AbstractBody for an active object attached to a given node.
87    * @param reifiedObject the active object that body is for
88    * @param nodeURL the URL of the node that body is attached to
89    * @param factory the factory able to construct new factories for each type of meta objects
90    * needed by this body
91    */

92   public AbstractUniversalBody(String JavaDoc nodeURL, RemoteBodyFactory remoteBodyFactory) {
93     this.nodeURL = nodeURL;
94     this.bodyID = new UniqueID();
95     this.location = new BodyMap();
96     this.remoteBodyFactory = remoteBodyFactory;
97     this.remoteBody = remoteBodyFactory.newRemoteBody(this);
98   }
99
100
101   //
102
// -- PUBLIC METHODS -----------------------------------------------
103
//
104

105   //
106
// -- implements UniversalBody -----------------------------------------------
107
//
108

109   public String JavaDoc getNodeURL() {
110     return nodeURL;
111   }
112
113   public UniversalBody getRemoteAdapter() {
114     return remoteBody;
115   }
116
117   public UniqueID getID() {
118     return bodyID;
119   }
120
121   public void updateLocation(UniqueID bodyID, UniversalBody body) {
122     location.updateBody(bodyID, body);
123   }
124
125
126   //
127
// -- PROTECTED METHODS -----------------------------------------------
128
//
129

130   
131   //
132
// -- PRIVATE METHODS -----------------------------------------------
133
//
134

135   private void writeObject(java.io.ObjectOutputStream JavaDoc out) throws java.io.IOException JavaDoc {
136     out.defaultWriteObject();
137   }
138
139   private void readObject(java.io.ObjectInputStream JavaDoc in) throws java.io.IOException JavaDoc, ClassNotFoundException JavaDoc {
140     in.defaultReadObject();
141     if (bodyID == null) {
142       // it may happen that the bodyID is set to null before serialization if we want to
143
// create a copy of the Body that is distinct from the original
144
bodyID = new UniqueID();
145     }
146     // remoteBody is transient so we recreate it here
147
this.remoteBody = remoteBodyFactory.newRemoteBody(this);
148   }
149
150 }
Popular Tags