KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > util > ServiceControllerUtil


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.util;
23
24 import javax.management.MBeanServerConnection JavaDoc;
25 import javax.management.MBeanServerInvocationHandler JavaDoc;
26 import javax.management.ObjectName JavaDoc;
27
28 import org.jboss.system.ServiceContext;
29 import org.jboss.system.ServiceControllerMBean;
30
31 /**
32  * Utility class that can deal with the ServiceController to
33  * start/stop/create/destroy a service
34  * @author <a HREF="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
35  * @version $Revision:$
36  * @since Aug 23, 2006
37  */

38 public class ServiceControllerUtil
39 {
40    private ServiceControllerMBean scmb = null;
41    
42    public ServiceControllerUtil(MBeanServerConnection JavaDoc server)
43    {
44       ObjectName JavaDoc so = ServiceControllerMBean.OBJECT_NAME;
45       scmb = (ServiceControllerMBean)
46       MBeanServerInvocationHandler.newProxyInstance(server, so,
47                ServiceControllerMBean.class, false);
48    }
49
50    public String JavaDoc getStateString(ObjectName JavaDoc serviceName)
51    {
52       ServiceContext ctx = scmb.getServiceContext(serviceName);
53       return ctx.getStateString();
54    }
55    public void createAService(ObjectName JavaDoc serviceName) throws Exception JavaDoc
56    {
57       scmb.create(serviceName);
58    }
59    
60    public void startAService(ObjectName JavaDoc serviceName) throws Exception JavaDoc
61    {
62       scmb.start(serviceName);
63    }
64    
65    public void stopAService(ObjectName JavaDoc serviceName) throws Exception JavaDoc
66    {
67       scmb.stop(serviceName);
68    }
69    
70    public void destroyAService(ObjectName JavaDoc serviceName) throws Exception JavaDoc
71    {
72       scmb.destroy(serviceName);
73    }
74    
75    public void removeAService(ObjectName JavaDoc serviceName) throws Exception JavaDoc
76    {
77       scmb.remove(serviceName);
78    }
79
80    public boolean isStarted(ObjectName JavaDoc serviceName)
81    {
82       ServiceContext sc = scmb.getServiceContext(serviceName);
83       return sc.state == ServiceContext.RUNNING;
84    }
85    
86    public boolean isCreated(ObjectName JavaDoc serviceName)
87    {
88       ServiceContext sc = scmb.getServiceContext(serviceName);
89       return sc.state == ServiceContext.CREATED;
90    }
91    
92    public boolean isStopped(ObjectName JavaDoc serviceName)
93    {
94       ServiceContext sc = scmb.getServiceContext(serviceName);
95       return sc.state == ServiceContext.STOPPED;
96    }
97    
98    public boolean isDestroyed(ObjectName JavaDoc serviceName)
99    {
100       ServiceContext sc = scmb.getServiceContext(serviceName);
101       return sc.state == ServiceContext.DESTROYED;
102    }
103    
104    public boolean isFailed(ObjectName JavaDoc serviceName)
105    {
106       ServiceContext sc = scmb.getServiceContext(serviceName);
107       return sc.state == ServiceContext.FAILED;
108    }
109 }
110
Popular Tags