KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > group > spmd > ProSPMD


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.spmd;
32
33 import org.objectweb.proactive.ActiveObjectCreationException;
34 import org.objectweb.proactive.ProActive;
35 import org.objectweb.proactive.core.body.AbstractBody;
36 import org.objectweb.proactive.core.group.Group;
37 import org.objectweb.proactive.core.group.ProActiveGroup;
38 import org.objectweb.proactive.core.group.ProxyForGroup;
39 import org.objectweb.proactive.core.mop.ClassNotReifiableException;
40 import org.objectweb.proactive.core.node.Node;
41 import org.objectweb.proactive.core.node.NodeException;
42
43
44 /**
45  * <p>
46  * This class provides a static method to build (an deploy) an 'SPMD' group of active objects
47  * with all references between them to communicate.
48  * </p><p>
49  * For instance, the following code builds objects of type <code>A</code> on nodes
50  * <code>node1,node2,...</code>, with parameters <code>param1,param2,...</code>
51  * and build for each object created its diffusion group to communicate with the others.
52  * </p>
53  * <pre>
54  * Object[] params = {param1,param2,...};
55  * Node[] nodes = {node1,node2,...};
56  *
57  * A group = (A) ProSPMD.newSPMDGroup("A", params, nodes);
58  * </pre>
59  *
60  * @version 1.0, 2003/10/09
61  * @since ProActive 1.0.3
62  * @author Laurent Baduel
63  */

64 public class ProSPMD {
65
66     /**
67      * Creates an object representing a group (a typed group) and creates members with params cycling on nodeList.
68      * This object represents the set of activities.
69      * @param <code>className</code> the name of the (upper) class of the group's member.
70      * @param <code>params</code> the array that contain the parameters used to build the group's member.
71      * @param <code>nodeList</code> the nodes where the members are created.
72      * @return a typed group with its members.
73      * @throws ActiveObjectCreationException if a problem occur while creating the stub or the body
74      * @throws ClassNotFoundException if the Class corresponding to <code>className</code> can't be found.
75      * @throws ClassNotReifiableException if the Class corresponding to <code>className</code> can't be reify.
76      * @throws NodeException if the node was null and that the DefaultNode cannot be created
77      */

78     public static Object JavaDoc newSPMDGroup(String JavaDoc className, Object JavaDoc[][] params,
79         Node[] nodeList)
80         throws ClassNotFoundException JavaDoc, ClassNotReifiableException,
81             ActiveObjectCreationException, NodeException {
82         // if (!((MOP.forName(className)).isAssignableFrom(org.objectweb.proactive.core.group.spmd.SPMDMember.class))) {
83
// System.out.println("Impossible to build a Group with this class : " + className);
84
// return null;
85
// }
86
Object JavaDoc result = ProActiveGroup.newGroup(className);
87         Group g = ProActiveGroup.getGroup(result);
88
89         for (int i = 0; i < params.length; i++)
90             g.add(ProActive.newActive(className, params[i],
91                     nodeList[i % nodeList.length]));
92
93         ((ProxyForGroup) g).setSPMDGroup(result);
94
95         return result;
96     }
97
98     public static Object JavaDoc newSPMDGroup(String JavaDoc className, Object JavaDoc[][] params,
99         String JavaDoc[] nodeList)
100         throws ClassNotFoundException JavaDoc, ClassNotReifiableException,
101             ActiveObjectCreationException, NodeException {
102         // if (!((MOP.forName(className)).isAssignableFrom(org.objectweb.proactive.core.group.spmd.SPMDMember.class))) {
103
// System.out.println("Impossible to build a Group with this class : " + className);
104
// return null;
105
// }
106
Object JavaDoc result = ProActiveGroup.newGroup(className);
107         Group g = ProActiveGroup.getGroup(result);
108
109         for (int i = 0; i < params.length; i++)
110             g.add(ProActive.newActive(className, params[i],
111                     nodeList[i % nodeList.length]));
112
113         ((ProxyForGroup) g).setSPMDGroup(result);
114
115         return result;
116     }
117
118     /**
119      * Set the SPMD group for this
120      * @param o - the new SPMD group
121      */

122     public static void setSPMDGroupOnThis(Object JavaDoc o) {
123         AbstractBody body = (AbstractBody) ProActive.getBodyOnThis();
124         body.setSPMDGroup(o);
125     }
126
127     /**
128      * Returns the SPMD group of this
129      * @return the SPMD group of this
130      */

131     public static Object JavaDoc getSPMDGroup() {
132         AbstractBody body = (AbstractBody) ProActive.getBodyOnThis();
133         return body.getSPMDGroup();
134     }
135
136     /**
137      * Returns the size of the SPMD group of this
138      * @return a size (int)
139      */

140     public int getMySPMDGroupSize() {
141         return ProActiveGroup.getGroup(ProSPMD.getSPMDGroup()).size();
142     }
143     
144     /**
145      * Returns the rank (position) of the object in the Group
146      * @return the index of the object
147      */

148     public int getMyRank() {
149         return ProActiveGroup.getGroup(ProSPMD.getSPMDGroup()).indexOf(ProActive.getStubOnThis());
150     }
151
152 }
153
Popular Tags