1 22 package org.jboss.test.jbossmessaging; 23 24 import javax.management.MBeanServerConnection ; 25 import javax.management.ObjectName ; 26 import javax.naming.InitialContext ; 27 import javax.naming.NamingException ; 28 29 import org.jboss.logging.Logger; 30 import org.jboss.util.NestedRuntimeException; 31 32 import org.objectweb.jtests.jms.admin.Admin; 33 34 41 public class JBossMessagingAdmin implements Admin 42 { 43 private Logger log = Logger.getLogger(JBossMessagingAdmin.class); 44 45 private InitialContext initialContext ; 46 private MBeanServerConnection server ; 47 48 protected static final String name ; 49 protected static final ObjectName serverPeer; 50 protected static final ObjectName namingService; 51 52 static 53 { 54 try 55 { 56 name = JBossMessagingAdmin.class.getName() ; 57 serverPeer = new ObjectName ("jboss.messaging:service=ServerPeer"); 58 namingService = new ObjectName ("jboss:service=Naming"); 59 } 60 catch (Exception e) 61 { 62 throw new NestedRuntimeException(e); 63 } 64 } 65 66 public JBossMessagingAdmin() throws Exception 67 { 68 try { 69 log.info("Initializing...") ; 70 71 initialContext = new InitialContext () ; 73 74 String adaptorName = System.getProperty("jbosstest.server.name","jmx/invoker/RMIAdaptor") ; 76 server = (MBeanServerConnection ) initialContext.lookup(adaptorName) ; 77 78 } catch (Exception e) { 79 throw new NestedRuntimeException(e); 80 } 81 } 82 83 public String getName() { 84 return name ; 85 } 86 87 private MBeanServerConnection getServer() { 88 return server ; 89 } 90 91 public InitialContext createInitialContext() throws NamingException { 92 return initialContext ; 93 } 94 95 public void createQueue(String name) 96 { 97 try 98 { 99 MBeanServerConnection server = getServer(); 100 try 101 { 102 server.invoke(serverPeer, "createQueue", new Object [] { name, name }, new String [] { String .class.getName(), String .class.getName() } ); 103 } 104 catch (Exception ignored) 105 { 106 log.trace("Ignored", ignored); 107 } 108 ObjectName queueName = new ObjectName ("jboss.messaging.destination:service=Queue,name=" + name); 109 server.invoke(queueName, "removeAllMessages", null, null); 110 } 111 catch (Exception e) 112 { 113 throw new NestedRuntimeException(e); 114 } 115 } 116 117 public void deleteQueue(String name) 118 { 119 try 120 { 121 MBeanServerConnection server = getServer(); 122 ObjectName queueName = new ObjectName ("jboss.messaging.destination:service=Queue,name=" + name); 123 server.invoke(queueName, "removeAllMessages", null, null); 124 server.invoke(serverPeer, "destroyQueue", new Object [] { name }, new String [] { String .class.getName() } ); 125 } 126 catch (Exception e) 127 { 128 throw new NestedRuntimeException(e); 129 } 130 } 131 132 public void createTopic(String name) 133 { 134 try 135 { 136 MBeanServerConnection server = getServer(); 137 try 138 { 139 server.invoke(serverPeer, "createTopic", new Object [] { name, name }, new String [] { String .class.getName(), String .class.getName() } ); 140 } 141 catch (Exception ignored) 142 { 143 log.trace("Ignored", ignored); 144 } 145 ObjectName topicName = new ObjectName ("jboss.messaging.destination:service=Topic,name=" + name); 146 server.invoke(topicName, "removeAllMessages", null, null); 147 } 148 catch (Exception e) 149 { 150 throw new NestedRuntimeException(e); 151 } 152 } 153 154 public void deleteTopic(String name) 155 { 156 try 157 { 158 MBeanServerConnection server = getServer(); 159 ObjectName topicName = new ObjectName ("jboss.messaging.destination:service=Topic,name=" + name); 160 server.invoke(topicName, "removeAllMessages", null, null); 161 server.invoke(serverPeer, "destroyTopic", new Object [] { name }, new String [] { String .class.getName() } ); 162 } 163 catch (Exception e) 164 { 165 throw new NestedRuntimeException(e); 166 } 167 } 168 169 public void createConnectionFactory(String name) 170 { 171 try 172 { 173 MBeanServerConnection server = getServer(); 174 server.invoke(namingService, "createAlias", new Object [] { name, "ConnectionFactory" }, new String [] { String .class.getName(), String .class.getName() } ); 175 } 176 catch (Exception e) 177 { 178 throw new NestedRuntimeException(e); 179 } 180 } 181 182 public void deleteConnectionFactory(String name) 183 { 184 try 185 { 186 MBeanServerConnection server = getServer(); 187 server.invoke(namingService, "removeAlias", new Object [] { name }, new String [] { String .class.getName() } ); 188 } 189 catch (Exception e) 190 { 191 throw new NestedRuntimeException(e); 192 } 193 } 194 195 public void createQueueConnectionFactory(String name) 196 { 197 createConnectionFactory(name) ; 198 } 199 200 public void deleteQueueConnectionFactory(String name) 201 { 202 deleteConnectionFactory(name) ; 203 } 204 205 public void createTopicConnectionFactory(String name) 206 { 207 createConnectionFactory(name) ; 208 } 209 210 public void deleteTopicConnectionFactory(String name) 211 { 212 deleteConnectionFactory(name) ; 213 } 214 215 } 216 | Popular Tags |