KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > component > controller > ProActiveContentController


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.component.controller;
32
33 import org.apache.log4j.Logger;
34
35 import org.objectweb.fractal.api.Component;
36 import org.objectweb.fractal.api.NoSuchInterfaceException;
37 import org.objectweb.fractal.api.control.ContentController;
38 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
39
40 import org.objectweb.proactive.core.ProActiveRuntimeException;
41 import org.objectweb.proactive.core.component.Constants;
42 import org.objectweb.proactive.core.component.Fractive;
43 import org.objectweb.proactive.core.component.identity.ProActiveComponent;
44
45 import java.io.Serializable JavaDoc;
46
47 import java.util.Vector JavaDoc;
48
49
50 /**
51  * Implementation of ContentController (@see org.objectweb.fractal.api.control.ContentController).
52  *
53  * @author Matthieu Morel
54  *
55  */

56 public class ProActiveContentController extends ProActiveController
57     implements ContentController, Serializable JavaDoc {
58     protected static Logger logger = Logger.getLogger(ProActiveContentController.class.getName());
59     Vector JavaDoc fcSubComponents;
60
61     /**
62      * Constructor for ProActiveContentController.
63      */

64     public ProActiveContentController(Component owner) {
65         super(owner, Constants.CONTENT_CONTROLLER);
66         fcSubComponents = new Vector JavaDoc();
67     }
68
69     /**
70      * @see org.objectweb.fractal.api.control.ContentController#getFcInternalInterfaces()
71      *
72      * in this implementation, the external interfaces are also internal interfaces
73      */

74     public Object JavaDoc[] getFcInternalInterfaces() {
75         logger.error(
76             "Internal interfaces are only accessible from the stub, i.e. from outside of this component");
77         return null;
78     }
79
80     /**
81      * @see org.objectweb.fractal.api.control.ContentController#getFcInternalInterface(String)
82     *
83     * in this implementation, the external interfaces are also internal interfaces
84      * */

85     public Object JavaDoc getFcInternalInterface(String JavaDoc interfaceName)
86         throws NoSuchInterfaceException {
87         throw new NoSuchInterfaceException(
88             "Internal interfaces are only accessible from the stub, i.e. from outside of this component");
89     }
90
91     /**
92      * @see org.objectweb.fractal.api.control.ContentController#getFcSubComponents()
93      */

94     public Component[] getFcSubComponents() {
95         if (fcSubComponents.size() > 0) {
96             return (Component[]) fcSubComponents.toArray(new Component[fcSubComponents.size()]);
97         } else {
98             return null;
99         }
100     }
101
102     public boolean isSubComponent(Component component) {
103         return fcSubComponents.contains(component);
104     }
105
106     /**
107      * @see org.objectweb.fractal.api.control.ContentController#addFcSubComponent(Component)
108      */

109     public void addFcSubComponent(Component subComponent)
110         throws IllegalLifeCycleException {
111         checkLifeCycleIsStopped();
112
113         // check whether the subComponent is the component itself
114
if (getFcItfOwner().equals((ProActiveComponent) subComponent)) {
115             try {
116                 throw new IllegalArgumentException JavaDoc("cannot add " +
117                     Fractive.getComponentParametersController(getFcItfOwner())
118                             .getComponentParameters().getName() +
119                     " component into itself ");
120             } catch (NoSuchInterfaceException e) {
121                 logger.error(e.getMessage());
122             }
123         }
124
125         // check whether already a sub component
126
// TODO check in the case of multiple references to the same component
127
if (fcSubComponents.contains(subComponent)) {
128             String JavaDoc name;
129             try {
130                 name = ((ComponentParametersController) subComponent
131                         .getFcInterface(Constants.COMPONENT_PARAMETERS_CONTROLLER)).getComponentParameters()
132                         .getName();
133             } catch (NoSuchInterfaceException nsie) {
134                 throw new ProActiveRuntimeException(
135                     "cannot access the component parameters controller");
136             }
137             throw new IllegalArgumentException JavaDoc("already a sub component : " +
138                 name);
139         } else {
140             fcSubComponents.addElement(subComponent);
141         }
142
143         // FIXME : component cycle checking
144
// this should raise an exception if the subcomponent is primitive,
145
// but proactive remote calls don't relay exception ; they stay in the body and lead to its termination
146
// // check whether current component is contained in subComponent
147
// Component[] subComponent_sub_components =
148
// ((ContentController) subComponent.getFcInterface(ContentController.CONTENT_CONTROLLER))
149
// .getFcSubComponents();
150
// for (int i = 0; i < subComponent_sub_components.length; i++) {
151
// if (getFcItfOwner().equals(subComponent_sub_components[i])) {
152
// throw new IllegalArgumentException(
153
// "cannot add "
154
// + ((ProActiveComponent) subComponent).getComponentParameters().getName()
155
// + " ; \nthis operation would create a cycle in the component hierarchy");
156
// }
157
// }
158
// int length =
159
// (fcSubComponents == null) ? 0 : fcSubComponents.length;
160
// Component[] oldSubComponents = fcSubComponents;
161
// Component[] subComponents = new Component[length + 1];
162
// if (fcSubComponents != null) {
163
// System.arraycopy(fcSubComponents, 0, subComponents, 0, length); }
164
// subComponents[length] = subComponent;
165
// fcSubComponents = subComponents;
166
}
167
168     /**
169      * @see org.objectweb.fractal.api.control.ContentController#removeFcSubComponent(Component)
170      */

171     public void removeFcSubComponent(Component subComponent)
172         throws IllegalLifeCycleException {
173         checkLifeCycleIsStopped();
174         if (!fcSubComponents.removeElement(subComponent)) {
175             throw new IllegalArgumentException JavaDoc("not a sub component : " +
176                 subComponent);
177         }
178
179         if (logger.isDebugEnabled()) {
180             logger.debug("TODO : check the bindings");
181         }
182     }
183 }
184
Popular Tags