KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > system > launch > FractalHelper


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: FractalHelper.java 16:40:52 alouis $
20  * -------------------------------------------------------------------------
21  */

22
23 package org.objectweb.petals.system.launch;
24
25 import org.objectweb.fractal.api.Component;
26 import org.objectweb.fractal.api.NoSuchInterfaceException;
27 import org.objectweb.fractal.api.control.ContentController;
28 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
29 import org.objectweb.fractal.api.control.LifeCycleController;
30 import org.objectweb.fractal.util.Fractal;
31
32 import org.objectweb.petals.jbi.transport.Transporter;
33
34 /**
35  * This class helps the PetalsAdmin Service to work with Fractal
36  *
37  * @author alouis
38  *
39  */

40 public class FractalHelper {
41
42     /**
43      * Stop the Petals fractal composites
44      *
45      * FIXME only jndi-server isstopped,petals will be closed without stopping
46      * fractal
47      *
48      * @param rootContentController
49      * @throws NoSuchInterfaceException
50      * @throws IllegalLifeCycleException
51      */

52     public static void stopPetalsComponents(ContentController rootContentController)
53         throws NoSuchInterfaceException, IllegalLifeCycleException {
54
55         // stopComponent(rootContentController, "jbi");
56

57         // stopComponent(rootContentController, "platform");
58

59         stopComponent(rootContentController, "jndi-server");
60
61     }
62
63     /**
64      * Stop the fractal component Transporter
65      * FIXME problem with the monitoring mode where the transporter is in fact a Composite
66      * @param rootContentController
67      * @return true if the transported was found and stopped, false otherwise
68      */

69     public static boolean stopTransporter(ContentController rootContentController) {
70
71         boolean result = false;
72
73         try {
74             // find the jbi composite
75
Component jbi = getComponentByName(rootContentController, "jbi");
76             
77             // Problem when stopping the transporter Composite in monitoring mode
78
//ContentController jbiController = Fractal.getContentController(jbi);
79
// stop the component
80
//stopComponent(jbiController, "transporter-impl");
81
((Transporter) jbi.getFcInterface("transporter")).stop();
82
83             result = true;
84         } catch (Exception JavaDoc e) {
85             // nothing to do, return false
86
}
87         return result;
88     }
89
90     /**
91      * Stop the fractal component InstallationService
92      *
93      * @param rootContentController
94      * @return true if the InstallationService was found and stopped, false
95      * otherwise
96      */

97     public static boolean stopInstallationService(
98         ContentController rootContentController) {
99
100         boolean result = false;
101
102         try {
103             // find the jbi composite
104
Component jbi = getComponentByName(rootContentController, "jbi");
105             ContentController jbiController = Fractal.getContentController(jbi);
106
107             // stop the component
108
stopComponent(jbiController, "installation-impl");
109             result = true;
110         } catch (NoSuchInterfaceException e) {
111             // nothing to do, return false
112
}
113         return result;
114     }
115
116     /**
117      * A utility function allowing to get a component from a content controller
118      *
119      * @param cc
120      * parentContentController
121      * @param name
122      * component name
123      * @return the component, null if not found
124      */

125     protected static Component getComponentByName(
126         ContentController parentContentController, String JavaDoc name) {
127
128         // The component to be returned
129
Component c = null;
130
131         // List content controller subcomponents
132
for (Component component : parentContentController.getFcSubComponents()) {
133
134             try {
135                 String JavaDoc componentName = Fractal.getNameController(component)
136                     .getFcName();
137                 if (componentName.equals(name)) {
138                     c = component;
139                     break;
140                 }
141             } catch (NoSuchInterfaceException e) {
142                 // Do nothing, return null
143
}
144         }
145         return c;
146     }
147
148     /**
149      * A utility function allowing to get a component LifeCycleController from a
150      * content controller
151      *
152      * @param parentContentController
153      * @param name
154      * @return the LifeCycleController of the component, null if not found
155      */

156     protected static LifeCycleController getLifeCycleControllerByName(
157         ContentController parentContentController, String JavaDoc name) {
158
159         LifeCycleController lifeCycleController = null;
160
161         Component comp = getComponentByName(parentContentController, name);
162
163         if (comp != null) {
164             try {
165                 lifeCycleController = Fractal.getLifeCycleController(comp);
166             } catch (NoSuchInterfaceException e) {
167                 // Do nothing, return null
168
}
169         }
170         return lifeCycleController;
171     }
172
173     /**
174      * A utility function allowing to get a component LifeCycleController from a
175      * content controller
176      *
177      * @param parentContentController
178      * @param name
179      * @return true if the component was found et stopped, false otherwise
180      */

181     protected static boolean stopComponent(
182         ContentController parentContentController, String JavaDoc name) {
183
184         boolean result = false;
185
186         LifeCycleController lifeCycleController = getLifeCycleControllerByName(
187             parentContentController, name);
188
189         if (lifeCycleController != null) {
190             try {
191                 lifeCycleController.stopFc();
192                 result = true;
193             } catch (IllegalLifeCycleException e) {
194                 // Do nothing, return false
195
}
196         }
197         return result;
198     }
199
200 }
201
Popular Tags