KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > group > ProActiveGroup


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.group;
32
33
34 import java.util.Iterator JavaDoc;
35
36 import org.apache.log4j.Logger;
37 import org.objectweb.proactive.ActiveObjectCreationException;
38 import org.objectweb.proactive.ProActive;
39 import org.objectweb.proactive.core.body.future.FutureProxy;
40 import org.objectweb.proactive.core.descriptor.data.VirtualNode;
41 import org.objectweb.proactive.core.mop.ClassNotReifiableException;
42 import org.objectweb.proactive.core.mop.ConstructionOfProxyObjectFailedException;
43 import org.objectweb.proactive.core.mop.ConstructionOfReifiedObjectFailedException;
44 import org.objectweb.proactive.core.mop.InvalidProxyClassException;
45 import org.objectweb.proactive.core.mop.MOP;
46 import org.objectweb.proactive.core.mop.Proxy;
47 import org.objectweb.proactive.core.mop.StubObject;
48 import org.objectweb.proactive.core.node.Node;
49 import org.objectweb.proactive.core.node.NodeException;
50 import org.objectweb.proactive.core.node.NodeFactory;
51
52
53
54 /**
55  * This class provides static methods to manage objects representing a Group (<b>typed group</b>).<br><br>
56  *
57  * The ProActiveGroup class provides a set of static services through static method calls.
58  * It is the main entry point for users of ProActive Group Communication as they will call methods of this class
59  * to create group of object or to synchronize them.<br><br>
60  *
61  * The main role of ProActiveGroup is to provide methods to create typed group. It is possible to create a typed
62  * group (empty or not) through instantiation using one of the version of newActive.
63  * It is also possible to create an active typed group from an existing using using the turnActive methods.<br>
64  * The default behavior is a broadcast call, with a unique serialization of parameters.<br><br>
65  * <b>Warning !!!</b> When a typed group is turned active, it looses the ability to switch to the
66  * <code>Group</code> representation. So an active typed group acquire the abilites of any active object
67  * (remote reference, migration, ...) but is no more able to evolve : no modification of the membership is possible.<br>
68  * (This feature will may appear in a later version of ProActive group communication).
69  *
70  * @author Laurent Baduel
71  *
72  */

73 public class ProActiveGroup {
74
75     /** The logger for the Class */
76     protected static Logger logger = Logger.getLogger(ProActiveGroup.class.getName());
77
78
79     /** The name of the default proxy for group communication */
80     public static final Class JavaDoc DEFAULT_PROXYFORGROUP_CLASS = org.objectweb.proactive.core.group.ProxyForGroup.class;
81
82     /** The name of the default proxy for group communication */
83     public static final String JavaDoc DEFAULT_PROXYFORGROUP_CLASS_NAME = "org.objectweb.proactive.core.group.ProxyForGroup";
84
85
86     /** This constructor with a private acces permits the javadoc to hide the default constructor method in the html file */
87     private ProActiveGroup () {}
88
89
90
91     /**
92      * Returns a Group corresponding to the Object o representing a group. Return null if o does not representing a group.
93      * @param <code>o</code> - the object representing a group (a typed group).
94      * @return the Group corresponding to <code>o</code>.
95      */

96     public static Group getGroup(Object JavaDoc o) {
97         return ProActiveGroup.findProxyForGroup(o);
98     }
99     
100     /**
101      * Returns the name class of the typed group.
102      * If the parameter is not a typed group, returns the name of Class of the parameter.
103      * @param <code>o</code> the typed group for wich we want the name of the type (Class).
104      * @return the name class of the typed group
105      */

106     public static String JavaDoc getType (Object JavaDoc o) {
107         ProxyForGroup tmp = ProActiveGroup.findProxyForGroup(o);
108         if (tmp != null)
109             return tmp.getTypeName();
110         else
111             return o.getClass().getName();
112     }
113
114
115     /**
116      * Creates an object representing an empty group specifying the upper class of member.
117      * @param the name of the (upper) class of the group's member.
118      * @return an empty group of type <code>className</code>.
119      * @throws ClassNotFoundException if the Class corresponding to <code>className</code> can't be found.
120      * @throws ClassNotReifiableException if the Class corresponding to <code>className</code> can't be reify.
121      */

122     public static Object JavaDoc newGroup(String JavaDoc className) throws ClassNotFoundException JavaDoc, ClassNotReifiableException {
123     
124     MOP.checkClassIsReifiable(MOP.forName(className));
125     
126     Object JavaDoc result = null;
127     
128     try {
129         result = MOP.newInstance (className, null, DEFAULT_PROXYFORGROUP_CLASS_NAME, null);
130
131         ProxyForGroup proxy = (org.objectweb.proactive.core.group.ProxyForGroup)((StubObject)result).getProxy();
132         proxy.className = className;
133         proxy.stub = (StubObject)result;
134     }
135     catch (ClassNotReifiableException e) {
136         logger.error("**** ClassNotReifiableException ****"); }
137     catch (InvalidProxyClassException e) {
138         logger.error("**** InvalidProxyClassException ****"); }
139     catch (ConstructionOfProxyObjectFailedException e) {
140         logger.error("**** ConstructionOfProxyObjectFailedException ****"); }
141     catch (ConstructionOfReifiedObjectFailedException e) {
142         logger.error("**** ConstructionOfReifiedObjectFailedException ****"); }
143
144     return result;
145     }
146
147
148
149     /**
150      * Creates an object representing a group (a typed group) and creates members on the default node.
151      * @param <code>className</code> the name of the (upper) class of the group's member.
152      * @param <code>params</code> the array that contain the parameters used to build the group's member.
153      * If <code>params</code> is <code>null</code>, builds an empty group.
154      * @return a typed group with its members.
155      * @throws ActiveObjectCreationException if a problem occur while creating the stub or the body
156      * @throws ClassNotFoundException if the Class corresponding to <code>className</code> can't be found.
157      * @throws ClassNotReifiableException if the Class corresponding to <code>className</code> can't be reify.
158      * @throws NodeException if the node was null and that the DefaultNode cannot be created
159      */

160     public static Object JavaDoc newGroup(String JavaDoc className, Object JavaDoc[][] params)
161     throws ClassNotFoundException JavaDoc, ClassNotReifiableException, ActiveObjectCreationException, NodeException {
162
163     Node[] nodeList = new Node[1];
164     nodeList[0] = NodeFactory.getDefaultNode();
165     
166     return ProActiveGroup.newGroup(className, params, nodeList);
167     }
168
169
170     /**
171      * Creates an object representing a group (a typed group) and creates all members with params on the node.
172      * @param <code>className</code> the name of the (upper) class of the group's member.
173      * @param <code>params</code> the array that contain the parameters used to build the group's member.
174      * @param <code>nodeName</code> the name (String) of the node where the members are created.
175      * @return a typed group with its members.
176      * @throws ActiveObjectCreationException if a problem occur while creating the stub or the body
177      * @throws ClassNotFoundException if the Class corresponding to <code>className</code> can't be found.
178      * @throws ClassNotReifiableException if the Class corresponding to <code>className</code> can't be reify.
179      * @throws NodeException if the node was null and that the DefaultNode cannot be created
180      */

181     public static Object JavaDoc newGroup(String JavaDoc className, Object JavaDoc[][] params, String JavaDoc nodeName)
182     throws ClassNotFoundException JavaDoc, ClassNotReifiableException, ActiveObjectCreationException, NodeException {
183         Node[] nodeList = new Node[1];
184         nodeList[0] = NodeFactory.getNode(nodeName);
185         return ProActiveGroup.newGroup(className, params, nodeList);
186     }
187
188
189
190     /**
191      * Creates an object representing a group (a typed group) and creates members with params cycling on nodeList.
192      * @param <code>className</code> the name of the (upper) class of the group's member.
193      * @param <code>params</code> the array that contain the parameters used to build the group's member.
194      * @param <code>nodeListString</code> the names of the nodes where the members are created.
195      * @return a typed group with its members.
196      * @throws ActiveObjectCreationException if a problem occur while creating the stub or the body
197      * @throws ClassNotFoundException if the Class corresponding to <code>className</code> can't be found.
198      * @throws ClassNotReifiableException if the Class corresponding to <code>className</code> can't be reify.
199      * @throws NodeException if the node was null and that the DefaultNode cannot be created
200      */

201     public static Object JavaDoc newGroup(String JavaDoc className, Object JavaDoc[][] params, String JavaDoc[] nodeListString)
202     throws ClassNotFoundException JavaDoc, ClassNotReifiableException, ActiveObjectCreationException, NodeException {
203         Node[] nodeList = new Node[nodeListString.length];
204         for (int i = 0 ; i < nodeListString.length ; i++)
205             nodeList[i] = NodeFactory.getNode(nodeListString[i]);
206         return ProActiveGroup.newGroup(className, params, nodeList);
207     }
208
209     /**
210      * Creates an object representing a group (a typed group) and creates all members with params on the node.
211      * @param <code>className</code> the name of the (upper) class of the group's member.
212      * @param <code>params</code> the array that contain the parameters used to build the group's member.
213      * @param <code>node</code> the node where the members are created.
214      * @return a typed group with its members.
215      * @throws ActiveObjectCreationException if a problem occur while creating the stub or the body
216      * @throws ClassNotFoundException if the Class corresponding to <code>className</code> can't be found.
217      * @throws ClassNotReifiableException if the Class corresponding to <code>className</code> can't be reify.
218      * @throws NodeException if the node was null and that the DefaultNode cannot be created
219      */

220     public static Object JavaDoc newGroup(String JavaDoc className, Object JavaDoc[][] params, Node node)
221     throws ClassNotFoundException JavaDoc, ClassNotReifiableException, ActiveObjectCreationException, NodeException {
222         Node[] nodeList = new Node[1];
223         nodeList[0] = node;
224         return ProActiveGroup.newGroup(className, params, nodeList);
225     }
226
227
228     /**
229      * Creates an object representing a group (a typed group) and creates members with params cycling on nodeList.
230      * @param <code>className</code> the name of the (upper) class of the group's member.
231      * @param <code>params</code> the array that contain the parameters used to build the group's member.
232      * If <code>params</code> is <code>null</code>, builds an empty group.
233      * @param <code>nodeList</code> the nodes where the members are created.
234      * @return a typed group with its members.
235      * @throws ActiveObjectCreationException if a problem occur while creating the stub or the body
236      * @throws ClassNotFoundException if the Class corresponding to <code>className</code> can't be found.
237      * @throws ClassNotReifiableException if the Class corresponding to <code>className</code> can't be reify.
238      * @throws NodeException if the node was null and that the DefaultNode cannot be created
239      */

240     public static Object JavaDoc newGroup(String JavaDoc className, Object JavaDoc[][] params, Node[] nodeList)
241     throws ClassNotFoundException JavaDoc, ClassNotReifiableException, ActiveObjectCreationException, NodeException {
242
243     Object JavaDoc result = ProActiveGroup.newGroup(className);
244     Group g = ProActiveGroup.getGroup(result);
245
246     if (params != null) {
247         for (int i=0 ; i < params.length ; i++) {
248             g.add(ProActive.newActive(className, params[i], nodeList[i % nodeList.length]));
249         }
250     }
251     
252     return result;
253
254
255     }
256     /**
257      * Creates an object representing a group (a typed group) and creates members with params cycling on the nodes of the virtual node.
258      * @param <code>className</code> the name of the (upper) class of the group's member.
259      * @param <code>params</code> the array that contain the parameters used to build the group's member.
260      * If <code>params</code> is <code>null</code>, builds an empty group.
261      * @param <code>virtualNode</code> the virtual where the members are created.
262      * @return a typed group with its members.
263      * @throws ActiveObjectCreationException if a problem occur while creating the stub or the body
264      * @throws ClassNotFoundException if the Class corresponding to <code>className</code> can't be found.
265      * @throws ClassNotReifiableException if the Class corresponding to <code>className</code> can't be reify.
266      * @throws NodeException if the node was null and that the DefaultNode cannot be created
267      */

268     public static Object JavaDoc newGroup(String JavaDoc className, Object JavaDoc[][] params, VirtualNode virtualNode)
269     throws ClassNotFoundException JavaDoc, ClassNotReifiableException, ActiveObjectCreationException, NodeException {
270         return ProActiveGroup.newGroup(className,params,virtualNode.getNodes());
271     }
272
273
274     /**
275      * Turns the target object (a typed group) into an ActiveObject (an active typed group) attached to a default
276      * node in the local JVM.
277      * @param <code>ogroup</code> the typed group to turn active.
278      * @return a reference on the active object produced.
279      * @throws ActiveObjectCreationException if a problem occur while creating the stub or the body
280      * @throws ClassNotFoundException if the Class corresponding to <code>className</code> can't be found.
281      * @throws ClassNotReifiableException if the Class corresponding to <code>className</code> can't be reify.
282      * @throws NodeException if the node was null and that the DefaultNode cannot be created.
283      */

284     public static Object JavaDoc turnActiveGroup(Object JavaDoc ogroup)
285     throws ClassNotFoundException JavaDoc, ClassNotReifiableException, ActiveObjectCreationException, NodeException {
286         return ProActive.turnActive(ogroup, ProActiveGroup.getType(ogroup), (Node) null, null, null);
287     }
288
289
290     /**
291      * Turns the target object (a typed group) into an ActiveObject (an active typed group) attached to a specified node.
292      * @param <code>ogroup</code> the typed group to turn active.
293      * @param <code>node</code> the node where to create the active object on. If <code>null</code>,
294      * the active object is created localy on a default node
295      * @return a reference (possibly remote) on the active object produced.
296      * @throws ActiveObjectCreationException if a problem occur while creating the stub or the body
297      * @throws ClassNotFoundException if the Class corresponding to <code>className</code> can't be found.
298      * @throws ClassNotReifiableException if the Class corresponding to <code>className</code> can't be reify.
299      * @throws NodeException if the specified node can not be reached.
300      */

301     public static Object JavaDoc turnActiveGroup(Object JavaDoc ogroup, Node node)
302     throws ClassNotFoundException JavaDoc, ClassNotReifiableException, ActiveObjectCreationException, NodeException {
303         return ProActive.turnActive(ogroup, ProActiveGroup.getType(ogroup), node, null, null);
304     }
305
306
307     /**
308      * Turns the target object (a typed group) into an ActiveObject (an active typed group) attached to a specified node.
309      * @param <code>ogroup</code> the typed group to turn active.
310      * @param <code>nodeName</code> the name of the node where to create the active object on.
311      * @return a reference (possibly remote) on the active object produced.
312      * @throws ActiveObjectCreationException if a problem occur while creating the stub or the body
313      * @throws ClassNotFoundException if the Class corresponding to <code>className</code> can't be found.
314      * @throws ClassNotReifiableException if the Class corresponding to <code>className</code> can't be reify.
315      * @throws NodeException if the specified node can not be reached.
316      */

317     public static Object JavaDoc turnActiveGroup(Object JavaDoc ogroup, String JavaDoc nodeName)
318     throws ClassNotFoundException JavaDoc, ClassNotReifiableException, ActiveObjectCreationException, NodeException {
319         return ProActive.turnActive(ogroup, ProActiveGroup.getType(ogroup), NodeFactory.getNode(nodeName), null, null);
320     }
321
322     /**
323      * Creates an object representing a group (a typed group) and creates members on the default node.
324      * @param <code>className</code> the name of the (upper) class of the group's member.
325      * @param <code>params</code> the array that contain the parameters used to build the group's member.
326      * If <code>params</code> is <code>null</code>, builds an empty group.
327      * @return a typed group with its members.
328      * @throws ActiveObjectCreationException if a problem occur while creating the stub or the body
329      * @throws ClassNotFoundException if the Class corresponding to <code>className</code> can't be found.
330      * @throws ClassNotReifiableException if the Class corresponding to <code>className</code> can't be reify.
331      * @throws NodeException if the node was null and that the DefaultNode cannot be created
332      */

333     public static Object JavaDoc newGroupBuildWithMultithreading(String JavaDoc className, Object JavaDoc[][] params)
334     throws ClassNotFoundException JavaDoc, ClassNotReifiableException, ActiveObjectCreationException, NodeException {
335
336     Node[] nodeList = new Node[1];
337     nodeList[0] = NodeFactory.getDefaultNode();
338
339     return ProActiveGroup.newGroupBuildWithMultithreading(className, params, nodeList);
340     }
341
342
343     /**
344      * Creates an object representing a group (a typed group) and creates members with params cycling on nodeList.
345      * Threads are used to build the group's members. This methods returns when all members were created.
346      * @param <code>className</code> the name of the (upper) class of the group's member.
347      * @param <code>params</code> the array that contain the parameters used to build the group's member.
348      * @param <code>nodeList</code> the nodes where the members are created.
349      * @return a typed group with its members.
350      * @throws ActiveObjectCreationException if a problem occur while creating the stub or the body
351      * @throws ClassNotFoundException if the Class corresponding to <code>className</code> can't be found.
352      * @throws ClassNotReifiableException if the Class corresponding to <code>className</code> can't be reify.
353      * @throws NodeException if the node was null and that the DefaultNode cannot be created
354      */

355      public static Object JavaDoc newGroupBuildWithMultithreading(String JavaDoc className, Object JavaDoc[][] params, Node[] nodeList)
356      throws ClassNotFoundException JavaDoc, ClassNotReifiableException, ActiveObjectCreationException, NodeException {
357         String JavaDoc[] nodeListString = new String JavaDoc[nodeList.length];
358         for (int i = 0 ; i < nodeList.length ; i++)
359             nodeListString[i] = nodeList[i].getNodeInformation().getURL();
360         return ProActiveGroup.newGroupBuildWithMultithreading(className, params, nodeListString);
361      }
362
363
364    /**
365     * Creates an object representing a group (a typed group) and creates members with params cycling on nodeList.
366     * Threads are used to build the group's members. This methods returns when all members were created.
367     * @param <code>className</code> the name of the (upper) class of the group's member.
368     * @param <code>params</code> the array that contain the parameters used to build the group's member.
369     * If <code>params</code> is <code>null</code>, builds an empty group.
370     * @param <code>nodeList</code> the names of the nodes where the members are created.
371     * @return a typed group with its members.
372     * @throws ActiveObjectCreationException if a problem occur while creating the stub or the body
373     * @throws ClassNotFoundException if the Class corresponding to <code>className</code> can't be found.
374     * @throws ClassNotReifiableException if the Class corresponding to <code>className</code> can't be reify.
375     * @throws NodeException if the node was null and that the DefaultNode cannot be created
376     */

377     public static Object JavaDoc newGroupBuildWithMultithreading(String JavaDoc className, Object JavaDoc[][] params, String JavaDoc[] nodeList)
378     throws ClassNotFoundException JavaDoc, ClassNotReifiableException, ActiveObjectCreationException, NodeException {
379
380     Object JavaDoc result = ProActiveGroup.newGroup(className);
381     ProxyForGroup proxy = (org.objectweb.proactive.core.group.ProxyForGroup) ProActiveGroup.getGroup(result);
382
383     proxy.createMemberWithMultithread(className, params, nodeList);
384
385     return result;
386
387
388     }
389     /**
390      * Creates an object representing a group (a typed group) and creates members with params cycling on the nodes of the vitual node.
391      * Threads are used to build the group's members. This methods returns when all members were created.
392      * @param <code>className</code> the name of the (upper) class of the group's member.
393      * @param <code>params</code> the array that contain the parameters used to build the group's member.
394      * If <code>params</code> is <code>null</code>, builds an empty group.
395      * @param <code>virtualNode</code> the virtual node where the members are created.
396      * @return a typed group with its members.
397      * @throws ActiveObjectCreationException if a problem occur while creating the stub or the body
398      * @throws ClassNotFoundException if the Class corresponding to <code>className</code> can't be found.
399      * @throws ClassNotReifiableException if the Class corresponding to <code>className</code> can't be reify.
400      * @throws NodeException if the node was null and that the DefaultNode cannot be created
401      */

402      public static Object JavaDoc newGroupBuildWithMultithreading(String JavaDoc className, Object JavaDoc[][] params, VirtualNode virtualNode)
403      throws ClassNotFoundException JavaDoc, ClassNotReifiableException, ActiveObjectCreationException, NodeException {
404          return ProActiveGroup.newGroupBuildWithMultithreading(className, params, virtualNode.getNodes());
405      }
406
407
408     /**
409      * Gives a view of the group
410      * @param ogroup - a typed group
411      * @return a typed group, the view of the group
412      */

413     public static Object JavaDoc captureView (Object JavaDoc ogroup) {
414         Object JavaDoc result = null;
415         
416         try {
417             result = ProActiveGroup.newGroup(ProActiveGroup.getType(ogroup));
418         } catch (ClassNotReifiableException e) {
419             logger.error("**** ClassNotReifiableException ****");
420             e.printStackTrace();
421         } catch (ClassNotFoundException JavaDoc e) {
422             logger.error("**** ClassNotFoundException ****");
423             e.printStackTrace();
424         }
425         
426         Group go = ProActiveGroup.getGroup(ogroup);
427         Group gr = ProActiveGroup.getGroup(result);
428
429         Iterator JavaDoc it = go.iterator();
430         while (it.hasNext()) {
431             gr.add(it.next());
432         }
433
434         return result;
435     }
436    
437     /**
438      * Waits for all the futures are arrived.
439      * @param <code>o</code> a typed group.
440      */

441     public static void waitAll(Object JavaDoc o) {
442         if (MOP.isReifiedObject (o)) {
443             org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o);
444             // If the object represents a group, we use the proxyForGroup's method
445
if (theProxy != null)
446             ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).waitAll();
447             // Else the "standard waitFor" method has been used in the findProxyForGroup method
448
}
449     }
450     
451     
452     
453     /**
454      * Waits for (at least) one future is arrived.
455      * @param <code>o</code> a typed group.
456      */

457     public static void waitOne(Object JavaDoc o) {
458         if (MOP.isReifiedObject (o)) {
459             org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o);
460             // If the object represents a group, we use the proxyForGroup's method
461
if (theProxy != null)
462             ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).waitOne();
463             // Else the "standard waitFor" method has been used in the findProxyForGroup method
464
}
465     }
466
467
468     
469     /**
470      * Waits n futures are arrived.
471      * @param <code>o</code> a typed group.
472      * @param <code>n</code> the number of awaited members.
473      */

474     public static void waitN(Object JavaDoc o, int n) {
475         if (MOP.isReifiedObject (o)) {
476             org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o);
477             // If the object represents a group, we use the proxyForGroup's method
478
if (theProxy != null)
479             ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).waitN(n);
480             // Else the "standard waitFor" method has been used in the findProxyForGroup method
481
}
482     }
483     
484             
485
486     /**
487      * Tests if all the members of the object <code>o</code> representing a group are awaited or not.
488      * Always returns <code>false</code> if <code>o</code> is not a reified object (future or group).
489      * @param <code>o</code> a typed group.
490      * @return <code>true</code> if all the members of <code>o</code> are awaited.
491      */

492     public static boolean allAwaited (Object JavaDoc o) {
493         // If the object is not reified, it cannot be a future (or a group of future)
494
if (!(MOP.isReifiedObject (o)))
495             return false;
496         else {
497             org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o);
498             // If the object represents a group, we use the proxyForGroup's method
499
if (theProxy != null)
500             return ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).allAwaited();
501             // Else the "standard waitFor" method has been used in the findProxyForGroup method so the future is arrived
502
else
503             return false;
504         }
505     }
506         
507
508     /**
509      * Tests if all the member of the object <code>o</code> representing a group are arrived or not.
510      * Always returns <code>true</code> if <code>o</code> is not a reified object (future or group).
511      * @param <code>o</code> a typed group.
512      * @return <code>true</code> if all the members of <code>o</code> are arrived.
513      */

514     public static boolean allArrived (Object JavaDoc o) {
515         // If the object is not reified, it cannot be a future (or a group of future)
516
if (!(MOP.isReifiedObject (o)))
517             return true;
518         else {
519             org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o);
520             // If the object represents a group, we use the proxyForGroup's method
521
if (theProxy != null)
522                 return ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).allArrived();
523             // Else the "standard waitFor" method has been used in the findProxyForGroup method so the future is arrived
524
else
525                 return true;
526         }
527     }
528
529
530     /**
531      * Waits one future is arrived and get it.
532      * @param <code>o</code> a typed group.
533      * @return a member of <code>o</code>.
534      */

535     public static Object JavaDoc waitAndGetOne (Object JavaDoc o) {
536         if (MOP.isReifiedObject (o)) {
537             org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o);
538             // If the object represents a group, we use the proxyForGroup's method
539
if (theProxy != null)
540                 return ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).waitAndGetOne();
541             // Else the "standard waitFor" method has been used in the findProxyForGroup method so the future is arrived, just return it
542
else
543                 return o;
544         }
545         // if o is not a reified object just return it
546
else
547             return o;
548     }
549
550
551     /**
552      * Wait the N-th future in the list is arrived.
553      * @param <code>o</code> a typed group.
554      */

555     public static void waitTheNth (Object JavaDoc o, int n) {
556         if (MOP.isReifiedObject (o)) {
557             org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o);
558             // If the object represents a group, we use the proxyForGroup's method
559
if (theProxy != null)
560                 ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).waitTheNth(n);
561             // Else the "standard waitFor" method has been used in the findProxyForGroup method
562
}
563     }
564
565
566     /**
567      * Wait the N-th future is arrived and get it.
568      * @param <code>o</code> a typed group.
569      * @param <code>n</code> the rank of the awaited member.
570      * @return the <code>n</code>-th member of th typed group <code>o</code>.
571      */

572     public static Object JavaDoc waitAndGetTheNth (Object JavaDoc o, int n) {
573         if (MOP.isReifiedObject (o)) {
574             org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o);
575             // If the object represents a group, we use the proxyForGroup's method
576
if (theProxy != null)
577                 return ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).waitAndGetTheNth(n);
578             // Else the "standard waitFor" method has been used in the findProxyForGroup method so the future is arrived, just return it
579
else
580                 return o;
581         }
582         // if o is not a reified object just return it
583
else
584             return o;
585     }
586
587     /**
588      * Waits that at least one member is arrived and returns its index.
589      * @param <code>o</code> a typed group.
590      * @return the index of a non-awaited member of the Group, -1 if <code>o</code> is not a reified object.
591      */

592     public int waitOneAndGetIndex(Object JavaDoc o) {
593         if (MOP.isReifiedObject (o)) {
594             org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o);
595             // If the object represents a group, we use the proxyForGroup's method
596
if (theProxy != null)
597                 return ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).waitOneAndGetIndex();
598             // Else return 0
599
else
600                 return 0;
601     }
602     // if o is not a reified object, return -1
603
else
604         return -1;
605     }
606
607         
608     /**
609      * Returns the number of members of the object representing a Group.
610      * Throws an IllegalArgumentException if <code>o</code> doesn't represent a Group.
611      * @param <code>o</code> a typed group.
612      * @return the number of member of the typed group <code>o</code>.
613      */

614     public static int size (Object JavaDoc o) {
615         org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o);
616         if (theProxy == null)
617             throw new java.lang.IllegalArgumentException JavaDoc("Parameter doesn't represent a group");
618         else
619             return ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).size();
620     }
621     
622
623     /**
624      * Returns the member at the specified index of the object representing a Group.
625      * Returns <code>null</code> if <code>obj</code> doesn't represent a Group.
626      * @param <code>o</code> a typed group.
627      * @param <code>n</code> the rank of the wanted member.
628      * @return the member of the typed group at the rank <code>n</code>
629      */

630     public static Object JavaDoc get (Object JavaDoc o, int n) {
631         org.objectweb.proactive.core.mop.Proxy theProxy = ProActiveGroup.findProxyForGroup(o);
632         if (theProxy == null) {
633             return null;
634         }
635         else {
636             return ((org.objectweb.proactive.core.group.ProxyForGroup)theProxy).get(n);
637         }
638     }
639
640
641     /**
642      * Checks if the object <code>o</code> is an object representing a Group (future or not).
643      * @param <code>o</code> the Object to check.
644      * @return <code>true</code> if <code>o</code> is a typed group.
645      */

646     public static boolean isGroup (Object JavaDoc o) {
647         return (ProActiveGroup.findProxyForGroup(o) != null);
648     }
649     
650     /**
651      * Allows the typed group to dispatch parameters
652      * @param <code>ogroup</code> the typed group who will change his semantic of communication.
653      */

654     public static void setScatterGroup(Object JavaDoc ogroup) {
655         Proxy proxytmp = ProActiveGroup.findProxyForGroup(ogroup);
656         if (proxytmp != null)
657             ((ProxyForGroup)proxytmp).setDispatchingOn();
658     }
659     
660     /**
661      * Allows the typed group to broadcast parameters
662      * @param <code>ogroup</code> the typed group who will change his semantic of communication.
663      */

664     public static void unsetScatterGroup(Object JavaDoc ogroup) {
665         Proxy proxytmp = ProActiveGroup.findProxyForGroup(ogroup);
666         if (proxytmp != null)
667             ((ProxyForGroup)proxytmp).setDispatchingOff();
668    }
669
670    /**
671     * Allows the typed group to make an unique serialization of parameters when a broadcast call occurs.
672     * @param <code>ogroup</code> the typed group who will change his semantic of communication.
673     */

674    public static void setUniqueSerialization(Object JavaDoc ogroup) {
675        Proxy proxytmp = ProActiveGroup.findProxyForGroup(ogroup);
676        if (proxytmp != null)
677            ((ProxyForGroup)proxytmp).setUniqueSerializationOn();
678    }
679     
680    /**
681     * Removes the ability of a typed group to make an unique serialization
682     * @param <code>ogroup</code> the typed group who will change his semantic of communication.
683     */

684    public static void unsetUniqueSerialization(Object JavaDoc ogroup) {
685        Proxy proxytmp = ProActiveGroup.findProxyForGroup(ogroup);
686        if (proxytmp != null)
687            ((ProxyForGroup)proxytmp).setUniqueSerializationOff();
688   }
689
690    
691     /**
692      * Checks the semantic of communication of the typed group <code>ogroup</code>.
693      * @param <code>ogroup</code> a typed group.
694      * @return <code>true</code> if the "scatter option" is enabled for the typed group <code>ogroup</code>.
695      */

696     public static boolean isScatterGroupOn (Object JavaDoc ogroup) {
697         Proxy proxytmp = ProActiveGroup.findProxyForGroup(ogroup);
698         if (proxytmp != null)
699             return ((ProxyForGroup)proxytmp).isDispatchingOn();
700         else return false;
701    }
702
703     /**
704      * Returns the ProxyForGroup of the typed group <code>ogroup</code>.
705      * @param <code>ogroup</code> the typed group.
706      * @return the <code>ProxyForGroup</code> of the typed group <code>ogroup</code>.
707      * <code>null</code> if <code>ogroup</code> does not represent a Group.
708      */

709     private static ProxyForGroup findProxyForGroup(Object JavaDoc ogroup) {
710         if (!(MOP.isReifiedObject(ogroup)))
711             return null;
712         else {
713             Proxy tmp = ((StubObject)ogroup).getProxy();
714
715             // obj is an object representing a Group (and not a future)
716
if (tmp instanceof org.objectweb.proactive.core.group.ProxyForGroup)
717                 return (org.objectweb.proactive.core.group.ProxyForGroup) tmp;
718         
719             // obj is a future ... but may be a future-Group
720
while (tmp instanceof org.objectweb.proactive.core.body.future.FutureProxy)
721                 // future of future ...
722
if (MOP.isReifiedObject(((FutureProxy)tmp).getResult()))
723                     tmp = ((StubObject)((FutureProxy)tmp).getResult()).getProxy();
724                 // future of standard objet
725
else
726                     return null;
727         
728                 // future-Group
729
if (tmp instanceof org.objectweb.proactive.core.group.ProxyForGroup)
730                 return (org.objectweb.proactive.core.group.ProxyForGroup) tmp;
731             // future of an active object
732
else
733                 return null;
734         }
735     }
736
737
738 }
739
Popular Tags