KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > management > service > AdminService


1 /**
2  * PETALS: PETALS Services Platform
3  * Copyright (C) 2005 EBM WebSourcing
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 any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): EBM WebSourcing
21  * --------------------------------------------------------------------------
22  * $Id: AdminService.java,v 1.2 2005/07/22 10:24:27 alouis Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.petals.jbi.management.service;
27
28 import java.util.Iterator JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import javax.jbi.JBIException;
32 import javax.jbi.messaging.MessageExchange;
33 import javax.jbi.servicedesc.ServiceEndpoint;
34 import javax.management.ObjectName JavaDoc;
35
36 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
37 import org.objectweb.fractal.fraclet.annotation.FractalComponent;
38 import org.objectweb.fractal.fraclet.annotation.Interface;
39 import org.objectweb.fractal.fraclet.annotation.LifeCycle;
40 import org.objectweb.fractal.fraclet.annotation.LifeCycleType;
41 import org.objectweb.fractal.fraclet.annotation.Monolog;
42 import org.objectweb.fractal.fraclet.annotation.Provides;
43 import org.objectweb.fractal.fraclet.annotation.Requires;
44 import org.objectweb.petals.PetalsException;
45 import org.objectweb.petals.jbi.component.lifecycle.ComponentLifeCycle;
46 import org.objectweb.petals.jbi.component.lifecycle.LifeCycleAbstract;
47 import org.objectweb.petals.util.LoggingUtil;
48 import org.objectweb.petals.util.ParameterCheckHelper;
49 import org.objectweb.util.monolog.api.Logger;
50 import org.w3c.dom.Document JavaDoc;
51
52 /**
53  * TODO AdminService : check the exceptions catch
54  *
55  * @author Adrien LOUIS - EBM WebSourcing
56  * @author wjoseph - eBM WebSourcing
57  */

58 @FractalComponent
59 @Provides(interfaces=@Interface(name="service",signature=org.objectweb.petals.jbi.management.service.AdminServiceMBean.class))
60 public class AdminService implements AdminServiceMBean {
61
62     /**
63      * Logger wrapper
64      */

65     protected LoggingUtil log;
66
67     /**
68      * Monolog
69      */

70     @Monolog(name="logger")
71     protected Logger logger;
72
73     /**
74      * JBI :: JMX Agent Admin
75      */

76     @Requires(name="lifecyclemanager",signature=org.objectweb.petals.jbi.management.service.LifeCycleManagerService.class)
77     protected LifeCycleManagerService manager;
78
79     /**
80      * Default constructor
81      */

82     public AdminService() {
83         super();
84     }
85
86     /**
87      * @see javax.jbi.management.AdminServiceMBean#getBindingComponents()
88      */

89     public ObjectName JavaDoc[] getBindingComponents() {
90         log.start();
91
92         ObjectName JavaDoc[] names = new ObjectName JavaDoc[0];
93
94         Map JavaDoc<ObjectName JavaDoc, ComponentLifeCycle> bindings = manager
95             .getBindingCompoLifeCycles();
96
97         names = (ObjectName JavaDoc[]) bindings.keySet().toArray(names);
98
99         return names;
100     }
101
102     /**
103      * @see javax.jbi.management.AdminServiceMBean#getComponentByName(java.lang.String)
104      */

105     public ObjectName JavaDoc getComponentByName(String JavaDoc name) {
106         log.call();
107         ParameterCheckHelper.isNullParameterWithLog(name,
108             "name must not be null", log);
109         ParameterCheckHelper.isEmptyParameterWithLog(name,
110             "name must not be empty", log);
111         ObjectName JavaDoc on = null;
112
113         // search in bindings
114

115         on = getBindingComponentByName(name);
116
117         if (on == null) {
118             // search in engines
119

120             on = getEngineComponentByName(name);
121         }
122         return on;
123     }
124
125     /**
126      * @see javax.jbi.management.AdminServiceMBean#getEngineComponents()
127      */

128     public ObjectName JavaDoc[] getEngineComponents() {
129         log.call();
130
131         ObjectName JavaDoc[] names = new ObjectName JavaDoc[0];
132
133         Map JavaDoc<ObjectName JavaDoc, ComponentLifeCycle> engines = manager
134             .getEngineCompoLifeCycles();
135
136         names = (ObjectName JavaDoc[]) engines.keySet().toArray(names);
137
138         return names;
139     }
140
141     /**
142      * @see org.objectweb.petals.jbi.management.service.AdminServiceMBean#getServiceDescription(String,
143      * ServiceEndpoint)
144      */

145     public Document JavaDoc getServiceDescription(String JavaDoc componentName,
146         ServiceEndpoint endpoint) throws PetalsException {
147         log.call();
148         Document JavaDoc doc = null;
149         ComponentLifeCycle componentLifeCycle = manager
150             .getComponentByName(componentName);
151         if (componentLifeCycle == null) {
152             log.error("No such component " + componentName
153                 + " in the container");
154             throw new PetalsException("No such component " + componentName
155                 + " in the container");
156         }
157         doc = componentLifeCycle.getComponent().getServiceDescription(endpoint);
158         return doc;
159     }
160
161     /**
162      * @see javax.jbi.management.AdminServiceMBean#getSystemInfo()
163      */

164     public String JavaDoc getSystemInfo() {
165         return "Petals JBI Container - version: "
166             + Package.getPackage("org.objectweb.petals")
167                 .getImplementationVersion();
168     }
169
170     /**
171      * @see javax.jbi.management.AdminServiceMBean#getSystemService(java.lang.String)
172      */

173     public ObjectName JavaDoc getSystemService(String JavaDoc serviceName) {
174         log.call();
175         ParameterCheckHelper.isNullParameterWithLog(serviceName,
176             "serviceName must not be null", log);
177         ParameterCheckHelper.isEmptyParameterWithLog(serviceName,
178             "serviceName must not be empty", log);
179         ObjectName JavaDoc result = null;
180         Map JavaDoc systemServices = manager.getSystemServices();
181
182         synchronized (systemServices) {
183             for (Iterator JavaDoc iter = systemServices.values().iterator(); iter
184                 .hasNext()
185                 && result == null;) {
186                 ComponentLifeCycle lifeCycle = (ComponentLifeCycle) iter.next();
187
188                 if (lifeCycle.getName().equals(serviceName)) {
189                     result = lifeCycle.getMBeanName();
190                 }
191             }
192         }
193         return result;
194     }
195
196     /**
197      * @see javax.jbi.management.AdminServiceMBean#getSystemServices()
198      */

199     public ObjectName JavaDoc[] getSystemServices() {
200         log.call();
201
202         ObjectName JavaDoc[] names = new ObjectName JavaDoc[0];
203
204         Map JavaDoc<ObjectName JavaDoc, LifeCycleAbstract> services = manager
205             .getSystemServices();
206
207         names = (ObjectName JavaDoc[]) services.keySet().toArray(names);
208
209         return names;
210     }
211
212     /**
213      * @see javax.jbi.management.AdminServiceMBean#isBinding(java.lang.String)
214      */

215     public boolean isBinding(String JavaDoc componentName) {
216         ParameterCheckHelper.isNullParameterWithLog(componentName,
217             "componentName must not be null", log);
218         ParameterCheckHelper.isEmptyParameterWithLog(componentName,
219             "componentName must not be empty", log);
220         boolean result = false;
221         result = manager.getBindingCompoLifeCycles().containsKey(componentName);
222         return result;
223     }
224
225     // ----------------------------------------------------------------------
226
// Fractal BindingController implementation
227
// ----------------------------------------------------------------------
228

229     /**
230      * @see javax.jbi.management.AdminServiceMBean#isEngine(java.lang.String)
231      */

232     public boolean isEngine(String JavaDoc componentName) {
233         ParameterCheckHelper.isNullParameterWithLog(componentName,
234             "componentName must not be null", log);
235         ParameterCheckHelper.isEmptyParameterWithLog(componentName,
236             "componentName must not be empty", log);
237         boolean result = false;
238         result = manager.getEngineCompoLifeCycles().containsKey(componentName);
239         return result;
240     }
241
242     /**
243      * (non-Javadoc)
244      *
245      * @see org.objectweb.petals.jbi.management.service.AdminServiceMBean#isExchangeWithConsumerOkayForComponent(java.lang.String,
246      * javax.jbi.servicedesc.ServiceEndpoint,
247      * javax.jbi.messaging.MessageExchange)
248      */

249     public boolean isExchangeWithConsumerOkayForComponent(String JavaDoc componentName,
250         ServiceEndpoint internalEndpoint, MessageExchange exchange)
251         throws JBIException {
252         log.call();
253         ComponentLifeCycle componentLifeCycle = manager
254             .getComponentByName(componentName);
255         if (componentLifeCycle == null) {
256             log.error("No such component " + componentName
257                 + " in the container");
258             throw new JBIException("No such component " + componentName
259                 + " in the container");
260         }
261         return componentLifeCycle.getComponent().isExchangeWithConsumerOkay(
262             internalEndpoint, exchange);
263     }
264
265     /**
266      * (non-Javadoc)
267      *
268      * @see org.objectweb.petals.jbi.management.service.AdminServiceMBean#isExchangeWithProviderOkayForComponent(java.lang.String,
269      * javax.jbi.servicedesc.ServiceEndpoint,
270      * javax.jbi.messaging.MessageExchange)
271      */

272     public boolean isExchangeWithProviderOkayForComponent(String JavaDoc componentName,
273         ServiceEndpoint internalEndpoint, MessageExchange exchange)
274         throws JBIException {
275         log.call();
276         ComponentLifeCycle componentLifeCycle = manager
277             .getComponentByName(componentName);
278         if (componentLifeCycle == null) {
279             log.error("No such component " + componentName
280                 + " in the container");
281             throw new JBIException("No such component " + componentName
282                 + " in the container");
283         }
284         return componentLifeCycle.getComponent().isExchangeWithProviderOkay(
285             internalEndpoint, exchange);
286     }
287
288     // ----------------------------------------------------------------------
289
// Fractal LifecycleController implementation
290
// ----------------------------------------------------------------------
291

292     /**
293      * @see org.objectweb.fractal.api.control.LifeCycleController#startFc()
294      */

295     @LifeCycle(on=LifeCycleType.START)
296     public void start() throws IllegalLifeCycleException {
297         log = new LoggingUtil(logger);
298     }
299
300     /**
301      * Return the binding component associated with this name.
302      *
303      * @param name
304      * @return The related objectName, or null
305      */

306     protected ObjectName JavaDoc getBindingComponentByName(String JavaDoc name) {
307         log.call();
308
309         ObjectName JavaDoc result = null;
310
311         Map JavaDoc bindings = manager.getBindingCompoLifeCycles();
312
313         synchronized (bindings) {
314             for (Iterator JavaDoc iter = bindings.values().iterator(); iter.hasNext()
315                 && result == null;) {
316                 ComponentLifeCycle lifeCycle = (ComponentLifeCycle) iter.next();
317
318                 if (lifeCycle.getName().equals(name)) {
319                     result = lifeCycle.getMBeanName();
320                 }
321             }
322         }
323         return result;
324     }
325
326     /**
327      * Return the engine component associated with this name.
328      *
329      * @param name
330      * @return The related objectName, or null
331      */

332     protected ObjectName JavaDoc getEngineComponentByName(String JavaDoc name) {
333         log.call();
334
335         ObjectName JavaDoc result = null;
336
337         Map JavaDoc engines = manager.getEngineCompoLifeCycles();
338
339         synchronized (engines) {
340             for (Iterator JavaDoc iter = engines.values().iterator(); iter.hasNext()
341                 && result == null;) {
342                 ComponentLifeCycle lifeCycle = (ComponentLifeCycle) iter.next();
343
344                 if (lifeCycle.getName().equals(name)) {
345                     result = lifeCycle.getMBeanName();
346                 }
347             }
348         }
349         return result;
350     }
351
352 }
353
Popular Tags