1 22 package org.jboss.test.jbossmq; 23 24 import javax.management.MBeanServerConnection ; 25 import javax.management.ObjectName ; 26 27 import org.jboss.logging.Logger; 28 import org.jboss.test.jms.JBossASJMSTestAdmin; 29 import org.jboss.util.NestedRuntimeException; 30 31 37 public class JBossMQAdmin extends JBossASJMSTestAdmin 38 { 39 private Logger log = Logger.getLogger(JBossMQAdmin.class); 40 41 protected static final ObjectName destinationManager; 42 protected static final ObjectName namingService; 43 44 static 45 { 46 try 47 { 48 destinationManager = new ObjectName ("jboss.mq:service=DestinationManager"); 49 namingService = new ObjectName ("jboss:service=Naming"); 50 } 51 catch (Exception e) 52 { 53 throw new NestedRuntimeException(e); 54 } 55 } 56 57 public JBossMQAdmin(Class clazz) throws Exception 58 { 59 super(clazz); 60 } 61 62 public void createQueue(String name) 63 { 64 try 65 { 66 MBeanServerConnection server = getServer(); 67 try 68 { 69 server.invoke(destinationManager, "createQueue", new Object [] { name, name }, new String [] { String .class.getName(), String .class.getName() } ); 70 } 71 catch (Exception ignored) 72 { 73 log.trace("Ignored", ignored); 74 } 75 ObjectName queueName = new ObjectName ("jboss.mq.destination:service=Queue,name=" + name); 76 server.invoke(queueName, "removeAllMessages", null, null); 77 } 78 catch (Exception e) 79 { 80 throw new NestedRuntimeException(e); 81 } 82 } 83 84 public void deleteQueue(String name) 85 { 86 try 87 { 88 MBeanServerConnection server = getServer(); 89 ObjectName queueName = new ObjectName ("jboss.mq.destination:service=Queue,name=" + name); 90 server.invoke(queueName, "removeAllMessages", null, null); 91 server.invoke(destinationManager, "destroyQueue", new Object [] { name }, new String [] { String .class.getName() } ); 92 } 93 catch (Exception e) 94 { 95 throw new NestedRuntimeException(e); 96 } 97 } 98 99 public void createTopic(String name) 100 { 101 try 102 { 103 MBeanServerConnection server = getServer(); 104 try 105 { 106 server.invoke(destinationManager, "createTopic", new Object [] { name, name }, new String [] { String .class.getName(), String .class.getName() } ); 107 } 108 catch (Exception ignored) 109 { 110 log.trace("Ignored", ignored); 111 } 112 ObjectName topicName = new ObjectName ("jboss.mq.destination:service=Topic,name=" + name); 113 server.invoke(topicName, "removeAllMessages", null, null); 114 } 115 catch (Exception e) 116 { 117 throw new NestedRuntimeException(e); 118 } 119 } 120 121 public void deleteTopic(String name) 122 { 123 try 124 { 125 MBeanServerConnection server = getServer(); 126 ObjectName topicName = new ObjectName ("jboss.mq.destination:service=Topic,name=" + name); 127 server.invoke(topicName, "removeAllMessages", null, null); 128 server.invoke(destinationManager, "destroyTopic", new Object [] { name }, new String [] { String .class.getName() } ); 129 } 130 catch (Exception e) 131 { 132 throw new NestedRuntimeException(e); 133 } 134 } 135 136 public void createConnectionFactory(String name) 137 { 138 try 139 { 140 MBeanServerConnection server = getServer(); 141 server.invoke(namingService, "createAlias", new Object [] { name, "ConnectionFactory" }, new String [] { String .class.getName(), String .class.getName() } ); 142 } 143 catch (Exception e) 144 { 145 throw new NestedRuntimeException(e); 146 } 147 } 148 149 public void deleteConnectionFactory(String name) 150 { 151 try 152 { 153 MBeanServerConnection server = getServer(); 154 server.invoke(namingService, "removeAlias", new Object [] { name }, new String [] { String .class.getName() } ); 155 } 156 catch (Exception e) 157 { 158 throw new NestedRuntimeException(e); 159 } 160 } 161 } 162 | Popular Tags |