KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.objectweb.fractal.api.control.LifeCycleController;
40
41 import org.objectweb.proactive.core.component.Constants;
42 import org.objectweb.proactive.core.component.identity.ProActiveComponent;
43 import org.objectweb.proactive.core.component.request.ComponentRequestQueue;
44
45 import java.io.Serializable JavaDoc;
46
47
48 /**
49  * Implementation of the LifeCycleController ({@link org.objectweb.fractal.api.control.LifeCycleController}).<br>
50  * It uses the request queue of the active objects.
51  *
52  * @author Matthieu Morel
53  *
54  */

55 public class ProActiveLifeCycleController extends ProActiveController
56     implements LifeCycleController, Serializable JavaDoc {
57     protected static Logger logger = Logger.getLogger(ProActiveLifeCycleController.class.getName());
58
59     public ProActiveLifeCycleController(Component owner) {
60         super(owner, Constants.LIFECYCLE_CONTROLLER);
61     }
62
63     /**
64      * {@link org.objectweb.fractal.api.control.LifeCycleController#getFcState()}
65      */

66     public String JavaDoc getFcState() {
67         return getRequestQueue().isStarted() ? LifeCycleController.STARTED
68                                              : LifeCycleController.STOPPED;
69     }
70
71     /**
72      * {@link org.objectweb.fractal.api.control.LifeCycleController#startFc()}
73      * recursive if composite
74      * ( recursivity is allowed here as we do not implement sharing )
75      */

76     public void startFc() {
77         try {
78             String JavaDoc hierarchical_type = ((ComponentParametersController) getFcItfOwner()
79                                         .getFcInterface(Constants.COMPONENT_PARAMETERS_CONTROLLER)).getComponentParameters()
80                                         .getHierarchicalType();
81             if (hierarchical_type.equals(Constants.COMPOSITE) ||
82                     hierarchical_type.equals(Constants.PARALLEL)) {
83                 // start all inner components
84
Component[] inner_components = ((ContentController) getFcItfOwner()
85                                                                         .getFcInterface(Constants.CONTENT_CONTROLLER)).getFcSubComponents();
86                 if (inner_components != null) {
87                     for (int i = 0; i < inner_components.length; i++) {
88                         ((LifeCycleController) inner_components[i].getFcInterface(Constants.LIFECYCLE_CONTROLLER)).startFc();
89                     }
90                 }
91             }
92             getRequestQueue().start();
93             if (logger.isDebugEnabled()) {
94                 logger.debug("started " +
95                     ((ComponentParametersController) getFcItfOwner()
96                      .getFcInterface(Constants.COMPONENT_PARAMETERS_CONTROLLER)).getComponentParameters()
97                      .getName());
98             }
99         } catch (NoSuchInterfaceException nsie) {
100             logger.error("interface not found : " + nsie.getMessage());
101             nsie.printStackTrace();
102         } catch (IllegalLifeCycleException ilce) {
103             logger.error("illegal life cycle operation : " + ilce.getMessage());
104             ilce.printStackTrace();
105         }
106     }
107
108     /**
109      * {@link org.objectweb.fractal.api.control.LifeCycleController#stopFc()}
110      * recursive if composite
111      */

112     public void stopFc() {
113         try {
114             String JavaDoc hierarchical_type = ((ComponentParametersController) getFcItfOwner()
115                                         .getFcInterface(Constants.COMPONENT_PARAMETERS_CONTROLLER)).getComponentParameters()
116                                         .getHierarchicalType();
117             if (hierarchical_type.equals(Constants.COMPOSITE) ||
118                     hierarchical_type.equals(Constants.PARALLEL)) {
119                 // stop all inner components
120
Component[] inner_components = ((ContentController) getFcItfOwner()
121                                                                         .getFcInterface(Constants.CONTENT_CONTROLLER)).getFcSubComponents();
122                 if (inner_components != null) {
123                     for (int i = 0; i < inner_components.length; i++) {
124                         ((LifeCycleController) inner_components[i].getFcInterface(Constants.LIFECYCLE_CONTROLLER)).stopFc();
125                     }
126                 }
127             }
128             getRequestQueue().stop();
129             if (logger.isDebugEnabled()) {
130                 logger.debug("stopped" +
131                     ((ComponentParametersController) getFcItfOwner()
132                      .getFcInterface(Constants.COMPONENT_PARAMETERS_CONTROLLER)).getComponentParameters()
133                      .getName());
134             }
135         } catch (NoSuchInterfaceException nsie) {
136             logger.error("interface not found : " + nsie.getMessage());
137             nsie.printStackTrace();
138         } catch (IllegalLifeCycleException ilce) {
139             logger.error("illegal life cycle operation : " + ilce.getMessage());
140             ilce.printStackTrace();
141         }
142     }
143
144     private ComponentRequestQueue getRequestQueue() {
145         return ((ProActiveComponent) getFcItfOwner()).getRequestQueue();
146     }
147 }
148
Popular Tags