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