KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > core > dist > Deployment


1 /*
2   Copyright (C) 2001-2002 Renaud Pawlak, Lionel Seinturier
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.core.dist;
19
20
21 import org.objectweb.jac.core.AspectComponent;
22 import org.objectweb.jac.core.NameRepository;
23 import org.objectweb.jac.core.Wrappee;
24 import org.objectweb.jac.core.Wrapping;
25 import java.io.Serializable JavaDoc;
26
27 /**
28  * This class deploies a set of objects on a set of host given a
29  * deployment mapping style (a function that gives the objects
30  * location in the topology).
31  *
32  * <p>It can be used by an aspect component that would implement a
33  * distribution aspect.
34  *
35  * @author <a HREF="http://cedric.cnam.fr/~pawlak/index-english.html">Renaud Pawlak</a>
36  * @author <a HREF="http://www-src.lip6.fr/homepages/Lionel.Seinturier/index-eng.html">Lionel Seinturier</a> */

37
38 public class Deployment implements Serializable JavaDoc {
39
40    /** Store the topology. */
41    Topology topology;
42
43    transient AspectComponent ac;
44    
45
46    /**
47     * Creates a new deployment. For the moment, only the MS_ONE2ONE is
48     * available. Anyway, it is the most usual strategy.
49     *
50     * @param topology the topology used by the deployment
51     */

52    public Deployment(AspectComponent ac, Topology topology) {
53       this.topology = topology;
54       this.ac = ac;
55    }
56
57    /**
58     * Deploys a set of JAC object that are centralized on the local
59     * host to the Topology.<p>
60     *
61     * Do not copy the state of the objects.
62     *
63     * @param objects a set of object to deploy on the topology
64     * @param forward if true, create a stub wrapper on each local
65     * object that forwards all the calls to the remotly deployed
66     * objects
67     * @return remote references on the deployed objects
68     *
69     * @see #deploy(Object[],boolean) */

70
71    public RemoteRef[] deployStruct(Object JavaDoc[] objects, boolean forward) {
72       
73       RemoteContainer[] rcs = topology.getDistContainers ();
74       RemoteRef[] ret = new RemoteRef[objects.length];
75
76       for (int i = 0; i < objects.length; i++) {
77
78          System.out.println( "Deploying " +
79                              NameRepository.get().getName(objects[i]) +
80                              " on " + rcs[i].getName());
81          RemoteRef rr = RemoteRef.create(
82             NameRepository.get().getName( objects[i] ) );
83
84          // THIS COMMENT MAY CAUSE REGRESSION
85
/*Collaboration.get().setCurApp(
86             ApplicationRepository
87             .getOwningApplication((Wrappee)objects[i]).getName());*/

88          rr.remoteNew( rcs[i].getName(),
89                        objects[i].getClass().getName() );
90          if ( forward ) {
91             StubWrapper w = new StubWrapper(ac,rr);
92             Wrapping.wrapAll((Wrappee)objects[i],null,w);
93          }
94          ret[i] = rr;
95       }
96       return ret;
97    }
98
99    /**
100     * Equals to deployStruct( objects, false ).
101     *
102     * @param objects the object to deploy
103     * @return the array of the remote references pointing on the
104     * deployed objects
105     *
106     * @see #deploy(Object[],boolean) */

107    
108    public RemoteRef[] deployStruct(Object JavaDoc[] objects) {
109       return deployStruct(objects, false);
110    }
111
112    /**
113     * Deploys a set of JAC object that are centralized on the local
114     * host to the Topology. This is a static deployment and the
115     * references between the different local objects must have already
116     * been built (it means that the application must have been
117     * initialized in a centralized way.
118     *
119     * @param objects a set of object to deploy on the topology
120     * @param forward if true, create a stub wrapper on each local
121     * object that forwards all the calls to the remotly deployed
122     * objects
123     * @return remote references on the deployed objects
124     *
125     * @see #deployStruct(Object[],boolean) */

126
127    public RemoteRef[] deploy(Object JavaDoc[] objects, boolean forward) {
128       
129       RemoteRef[] ret = new RemoteRef[objects.length];
130
131       for (int i = 0; i < objects.length; i++) {
132
133          System.out.println( "Deploying " + NameRepository.get().getName(objects[i]) +
134                              " on " + topology.getContainer(i).getName());
135          RemoteRef rr = RemoteRef.create( NameRepository.get().getName( objects[i] ) );
136          
137          // THIS COMMENT MAY CAUSE REGRESSION
138
/*Collaboration.get().setCurApp(
139             ApplicationRepository
140             .getOwningApplication((Wrappee)objects[i]).getName());*/

141          rr.remoteNewWithCopy( topology.getContainer(i).getName(),
142                                objects[i].getClass().getName(),
143                                objects[i] );
144          if ( forward ) {
145             StubWrapper w = new StubWrapper(ac,rr);
146             Wrapping.wrapAll((Wrappee)objects[i],null,w);
147          }
148          ret[i] = rr;
149       }
150       return ret;
151    }
152
153    /**
154     * Equals to deploy( objects, false ).
155     *
156     * @param objects the object to deploy
157     * @return the array of the remote references pointing on the
158     * deployed objects
159     *
160     * @see #deploy(Object[],boolean) */

161    
162    public RemoteRef[] deploy(Object JavaDoc[] objects) {
163       return deploy (objects, false);
164    }
165
166    /**
167     * Replicates a JAC object that is located on the local
168     * host to the hosts of the Topology.
169     *
170     * @param object the local object to replicate
171     * @param forwardTo the index of the topology where the local
172     * object will forward the calls (if -1 or not valid for the
173     * topology then do not forward any call)
174     * @return remote references on the replicated objects
175     *
176     * @see #replicateStruct(Object,int) */

177
178    public RemoteRef[] replicate(Object JavaDoc object, int forwardTo) {
179
180       RemoteContainer[] rcs = topology.getDistContainers ();
181       RemoteRef[] ret = new RemoteRef[rcs.length];
182       RemoteRef rr = null;
183       String JavaDoc name = NameRepository.get().getName(object);
184
185       for (int i = 0; i < rcs.length; i++) {
186
187          System.out.println( "Replicating " + name +
188                              " on " + rcs[i].getName());
189          
190          if( rcs[i].bindTo( name ) != null ) {
191             System.out.println( name + " already replicated on "
192                                 + rcs[i].getName());
193             continue;
194          }
195
196          // THIS COMMENT MAY CAUSE REGRESSION
197

198          /* Collaboration.get().setCurApp(
199             ApplicationRepository.
200             getOwningApplication((Wrappee)object).getName());*/

201
202          rr = RemoteRef.create( name );
203          rr.remoteNewWithCopy( rcs[i].getName(),
204                                object.getClass().getName(),
205                                object );
206          
207          if ( forwardTo == i ) {
208             StubWrapper w = new StubWrapper(ac,rr);
209             Wrapping.wrapAll((Wrappee)object,null,w);
210          }
211          ret[i] = rr;
212       }
213       return ret;
214    }
215
216    /**
217     * Equals to replicate( object, -1 ).
218     *
219     * @param object the object to replicate
220     * @return the array of the remote references pointing on the
221     * replicated objects
222     *
223     * @see #replicate(Object,int) */

224
225    public RemoteRef[] replicate(Object JavaDoc object) {
226       return replicate(object, -1);
227    }
228
229    /**
230     * Replicates a JAC object that is located on the local
231     * host to the hosts of the Topology.
232     *
233     * <p>Do not copy the objects states.
234     *
235     * @param object the local object to replicate
236     * @param forwardTo the index of the topology where the local
237     * object will forward the calls (if -1 or not valid for the
238     * topology then do not forward any call)
239     * @return remote references on the replicated objects
240     *
241     * @see #replicate(Object,int) */

242
243    public RemoteRef[] replicateStruct(Object JavaDoc object, int forwardTo) {
244
245       RemoteContainer[] rcs = topology.getDistContainers ();
246       RemoteRef[] ret = new RemoteRef[rcs.length];
247       RemoteRef rr = null;
248       String JavaDoc name = NameRepository.get().getName(object);
249       
250       for (int i = 0; i < rcs.length; i++) {
251
252          if( rcs[i].bindTo( name ) != null ) {
253             System.out.println( name + " already replicated on "
254                                 + rcs[i].getName());
255             continue;
256          }
257
258          System.out.println( "Replicating (struct) " +
259                              NameRepository.get().getName(object) +
260                              " on " + rcs[i].getName());
261          
262          // THIS COMMENT MAY CAUSE REGRESSION
263

264          /* Collaboration.get().setCurApp(
265             ApplicationRepository
266             .getOwningApplication((Wrappee)object).getName());*/

267
268          rr = RemoteRef.create( NameRepository.get().getName( object ) );
269          rr.remoteNew( rcs[i].getName(), object.getClass().getName() );
270          if ( forwardTo == i ) {
271             StubWrapper w = new StubWrapper(ac,rr);
272             Wrapping.wrapAll((Wrappee)object,null,w);
273          }
274          ret[i] = rr;
275       }
276       return ret;
277    }
278
279    /**
280     * Equals to replicateStruct( object, -1 ).
281     *
282     * @param object the object to replicate
283     * @return the array of the remote references pointing on the
284     * replicated objects
285     *
286     * @see #replicateStruct(Object,int) */

287    
288    public RemoteRef[] replicateStruct(Object JavaDoc object) {
289       return replicateStruct (object, -1);
290    }
291
292
293 }
294
295
296
297
298
299
300
301
Popular Tags