KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * ################################################################
3  *
4  * ProActive: The Java(TM) library for Parallel, Distributed,
5  * Concurrent computing with Security and Mobility
6  *
7  * Copyright (C) 1997-2004 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 import org.apache.log4j.Logger;
34
35 import org.objectweb.fractal.api.Interface;
36 import org.objectweb.fractal.api.NoSuchInterfaceException;
37 import org.objectweb.fractal.api.factory.InstantiationException;
38 import org.objectweb.fractal.api.type.InterfaceType;
39
40 import org.objectweb.proactive.core.component.ComponentParameters;
41 import org.objectweb.proactive.core.component.ControllerDescription;
42 import org.objectweb.proactive.core.component.ProActiveInterface;
43 import org.objectweb.proactive.core.component.representative.ProActiveComponentRepresentativeFactory;
44 import org.objectweb.proactive.core.component.type.ProActiveTypeFactory;
45 import org.objectweb.proactive.core.mop.ClassNotReifiableException;
46 import org.objectweb.proactive.core.mop.ConstructionOfProxyObjectFailedException;
47 import org.objectweb.proactive.core.mop.ConstructionOfReifiedObjectFailedException;
48 import org.objectweb.proactive.core.mop.InvalidProxyClassException;
49 import org.objectweb.proactive.core.mop.MOP;
50 import org.objectweb.proactive.core.mop.StubObject;
51
52
53 /**
54  *
55  * // TODO : change class name (interfaces only are grouped)
56  *
57  * A class for creating groups of interfaces
58  * Indeed, the standard mechanism cannot be used here, as we are referencing components
59  * through interfaces of component representatives.
60  *
61  * It was moved to this package so it can see className attribute in ProxyForGroup
62  *
63  * @author Matthieu Morel
64  */

65 public class ProActiveComponentGroup {
66     protected static Logger logger = Logger.getLogger(ProActiveComponentGroup.class.getName());
67
68     /** Create an object representing an empty group of components specifying the java class of the components. */
69     public static Object JavaDoc newActiveComponentGroup(
70         ComponentParameters componentParameters)
71         throws ClassNotFoundException JavaDoc, ClassNotReifiableException {
72         Object JavaDoc result = null;
73
74         try {
75             result = MOP.newInstance(ProActiveInterface.class.getName(), null,
76                     ProActiveGroup.DEFAULT_PROXYFORGROUP_CLASS_NAME,
77                     new Object JavaDoc[] { null, null, null });
78         } catch (ClassNotReifiableException e) {
79             System.err.println("**** ClassNotReifiableException ****");
80         } catch (InvalidProxyClassException e) {
81             System.err.println("**** InvalidProxyClassException ****");
82         } catch (ConstructionOfProxyObjectFailedException e) {
83             System.err.println(
84                 "**** ConstructionOfProxyObjectFailedException ****");
85         } catch (ConstructionOfReifiedObjectFailedException e) {
86             System.err.println(
87                 "**** ConstructionOfReifiedObjectFailedException ****");
88         }
89
90         ((org.objectweb.proactive.core.group.ProxyForGroup) (((StubObject) result).getProxy())).className = Interface.class.getName();
91
92         return ProActiveComponentRepresentativeFactory.instance()
93                                                       .createComponentRepresentative(componentParameters,
94             ((StubObject) result).getProxy());
95     }
96
97     /**
98      * creates a group proxy on a set of generated Interface objects.
99      * These objects are generated according to the InterfaceType they get as a parameter
100      * @param interfaceType the type of interface we need a group of Interface objects on
101      * @return a group of ProActiveInterface elements
102      * @throws ClassNotFoundException
103      * @throws ClassNotReifiableException
104      */

105     public static ProActiveInterface newActiveComponentInterfaceGroup(
106         InterfaceType interfaceType)
107         throws ClassNotFoundException JavaDoc, ClassNotReifiableException {
108         try {
109             ComponentParameters component_parameters = new ComponentParameters(ProActiveTypeFactory.instance()
110                                                                                                    .createFcType(new InterfaceType[] {
111                             interfaceType
112                         }), new ControllerDescription(null, null));
113
114             Object JavaDoc result = null;
115
116             result = MOP.newInstance(ProActiveInterface.class.getName(), null,
117                     ProActiveGroup.DEFAULT_PROXYFORGROUP_CLASS_NAME, null);
118
119             ProxyForGroup proxy = (org.objectweb.proactive.core.group.ProxyForGroup) ((StubObject) result).getProxy();
120             proxy.className = ProActiveInterface.class.getName();
121
122             //return a reference on the generated interface reference corresponding to the interface type
123
return (ProActiveInterface) (ProActiveComponentRepresentativeFactory.instance()
124                                                                                 .createComponentRepresentative(component_parameters,
125                 proxy)).getFcInterface(interfaceType.getFcItfName());
126         } catch (InvalidProxyClassException e) {
127             logger.error("**** InvalidProxyClassException ****");
128         } catch (ConstructionOfProxyObjectFailedException e) {
129             logger.error("**** ConstructionOfProxyObjectFailedException ****");
130         } catch (ConstructionOfReifiedObjectFailedException e) {
131             logger.error("**** ConstructionOfReifiedObjectFailedException ****");
132         } catch (NoSuchInterfaceException e) {
133             logger.error("**** Interface not found **** " + e.getMessage());
134         } catch (InstantiationException JavaDoc e) {
135             logger.error("**** Cannot create component type **** " +
136                 e.getMessage());
137         }
138         return null;
139     }
140
141     ///** Create an object representing a group and create members with params cycling on nodeList. */
142

143     // ComponentBody Parameters is unique for all the group members (notably the name is the same)...
144
// /**
145
// jem3D stuff - to be committed later.
146
// * creates a group
147
// * @param className
148
// * @param constructorsParameters
149
// * @param nodeList
150
// * @param componentParameters
151
// * @return
152
// * @throws ClassNotFoundException
153
// * @throws ClassNotReifiableException
154
// * @throws ActiveObjectCreationException
155
// * @throws NodeException
156
// */
157
// public static Object newActiveComponentGroupBuildWithMultithreading(
158
// String className, Object[][] constructorsParameters, String[] nodeList,
159
// ComponentParameters componentParameters)
160
// throws ClassNotFoundException, ClassNotReifiableException,
161
// ActiveObjectCreationException, NodeException {
162
// Object result = ProActiveGroup.newGroup(Component.class.getName());
163
// ProxyForGroup proxy = (org.objectweb.proactive.core.group.ProxyForGroup) ProActiveGroup.getGroup(result);
164
//
165
// proxy.createComponentMemberWithMultithread(className,
166
// constructorsParameters, nodeList, componentParameters);
167
//
168
// return result;
169
// }
170
}
171
Popular Tags