01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * 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;
25: import javax.management.MBeanServerInvocationHandler;
26: import javax.management.ObjectName;
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: private ServiceControllerMBean scmb = null;
40:
41: public ServiceControllerUtil(MBeanServerConnection server) {
42: ObjectName so = ServiceControllerMBean.OBJECT_NAME;
43: scmb = (ServiceControllerMBean) MBeanServerInvocationHandler
44: .newProxyInstance(server, so,
45: ServiceControllerMBean.class, false);
46: }
47:
48: public void createAService(ObjectName serviceOName)
49: throws Exception {
50: scmb.create(serviceOName);
51: }
52:
53: public void startAService(ObjectName serviceName) throws Exception {
54: scmb.start(serviceName);
55: }
56:
57: public void stopAService(ObjectName serviceName) throws Exception {
58: scmb.stop(serviceName);
59: }
60:
61: public void destroyAService(ObjectName serviceName)
62: throws Exception {
63: scmb.destroy(serviceName);
64: }
65:
66: public boolean isStarted(ObjectName serviceName) {
67: ServiceContext sc = scmb.getServiceContext(serviceName);
68: return sc.state == ServiceContext.RUNNING;
69: }
70:
71: public boolean isCreated(ObjectName serviceName) {
72: ServiceContext sc = scmb.getServiceContext(serviceName);
73: return sc.state == ServiceContext.CREATED;
74: }
75:
76: public boolean isStopped(ObjectName serviceName) {
77: ServiceContext sc = scmb.getServiceContext(serviceName);
78: return sc.state == ServiceContext.STOPPED;
79: }
80:
81: public boolean isDestroyed(ObjectName serviceName) {
82: ServiceContext sc = scmb.getServiceContext(serviceName);
83: return sc.state == ServiceContext.DESTROYED;
84: }
85:
86: public boolean isFailed(ObjectName serviceName) {
87: ServiceContext sc = scmb.getServiceContext(serviceName);
88: return sc.state == ServiceContext.FAILED;
89: }
90: }
|