1 22 package org.jboss.test.system.controller.support; 23 24 import java.lang.reflect.UndeclaredThrowableException ; 25 import java.util.Hashtable ; 26 27 import javax.management.ObjectName ; 28 29 import org.jboss.system.ServiceMBeanSupport; 30 31 37 public class ContainedMBeanService extends ServiceMBeanSupport 38 implements ContainedMBeanServiceMBean 39 { 40 private String aString; 41 private ObjectName simpleName; 42 private Simple simpleMBean; 43 44 45 public String getAString() 46 { 47 return this.aString; 48 } 49 50 public void setAString(String string) 51 { 52 this.aString = string; 53 } 54 55 58 @Override 59 protected void createService() throws Exception 60 { 61 simpleMBean = new Simple(); 62 simpleMBean.setAString(aString); 63 Hashtable props = serviceName.getKeyPropertyList(); 64 props.put("contained", "SimpleMBean"); 65 simpleName = new ObjectName (serviceName.getDomain(), props); 66 server.registerMBean(simpleMBean, simpleName); 67 boolean expectError = "ERRORINCREATE".equals(aString); 68 Object [] params = {}; 70 String [] signature = {}; 71 server.invoke(simpleName, "create", params, signature); 72 if( expectError ) 73 throw new Error ("Did not see expected ERRORINCREATE from: "+simpleName); 74 } 75 76 @Override 77 protected void startService() throws Exception 78 { 79 if( simpleName != null ) 80 { 81 boolean expectError = "ERRORINSTART".equals(aString); 83 Object [] params = {}; 84 String [] signature = {}; 85 server.invoke(simpleName, "start", params, signature); 86 if( expectError ) 87 throw new Error ("Did not see expected ERRORINSTART from: "+simpleName); 88 } 89 } 90 91 @Override 92 protected void stopService() throws Exception 93 { 94 if( simpleName != null ) 95 { 96 boolean expectError = "ERRORINSTOP".equals(aString); 97 Object [] params = {}; 98 String [] signature = {}; 99 server.invoke(simpleName, "stop", params, signature); 100 if( expectError ) 101 throw new Error ("Did not see expected ERRORINSTOP from: "+simpleName); 102 } 103 } 104 105 @Override 106 protected void destroyService() throws Exception 107 { 108 if( simpleName != null ) 109 { 110 boolean expectError = "ERRORINDESTROY".equals(aString); 111 Object [] params = {}; 112 String [] signature = {}; 113 try 114 { 115 server.invoke(simpleName, "destroy", params, signature); 116 if( expectError ) 117 throw new Error ("Did not see expected ERRORINDESTROY from: "+simpleName); 118 } 119 catch(Throwable e) 120 { 121 if( expectError == false ) 122 throw new UndeclaredThrowableException (e); 123 } 124 server.unregisterMBean(simpleName); 125 } 126 simpleName = null; 127 } 128 129 } 130 | Popular Tags |