1 7 package org.objectweb.jtests.providers.admin; 8 9 import javax.management.Attribute ; 10 import javax.management.AttributeList ; 11 import javax.management.ObjectName ; 12 import javax.naming.*; 13 14 import org.jboss.jmx.adaptor.rmi.RMIAdaptor; 15 import org.jboss.mx.util.MBeanProxy; 16 import org.objectweb.jtests.jms.admin.Admin; 17 18 import javax.jms.Queue ; 19 import javax.jms.Topic ; 20 import java.util.*; 21 import java.io.*; 22 import java.net.InetAddress ; 23 24 public class JBossMQAdmin implements Admin { 25 26 private String name = "JBossMQ"; 27 InitialContext ictx = null; 28 RMIAdaptor server; 29 30 public JBossMQAdmin() { 31 try { 32 Properties props = new Properties(); 33 props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); 34 props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); 35 props.setProperty("java.naming.provider.url", "localhost"); 36 ictx = new InitialContext (props); 37 38 String serverName = System.getProperty("jbosstest.server.name"); 39 if (serverName == null) { 40 serverName = InetAddress.getLocalHost().getHostName(); 41 } 42 server = (RMIAdaptor)ictx.lookup("jmx/invoker/RMIAdaptor"); 43 44 } catch (Exception e) { 45 e.printStackTrace(); 46 } 47 } 48 49 50 public String getName() { 51 return name; 52 } 53 54 public InitialContext createInitialContext() throws NamingException { 55 return ictx; 56 } 57 58 public void createQueueConnectionFactory(String name) { 59 try { 60 61 String mbeanClass = "org.jboss.naming.NamingAlias"; 62 ObjectName objn = new ObjectName ("testsuite:service=NamingAlias,fromName="+name); 63 server.createMBean(mbeanClass, objn); 64 server.setAttribute(objn, new Attribute ("ToName", "ConnectionFactory")); 65 server.setAttribute(objn, new Attribute ("FromName", name)); 66 server.invoke(objn, "create", new Object []{}, new String []{}); 67 server.invoke(objn, "start", new Object []{},new String []{}); 68 } catch (Exception e ) { 69 e.printStackTrace(); 70 } 71 } 72 73 74 public void deleteQueueConnectionFactory(String name) { 75 try { 76 ObjectName objn = new ObjectName ("testsuite:service=NamingAlias,fromName="+name); 77 if( server.isRegistered(objn) ) { 78 server.invoke(objn, "stop", new Object []{}, new String []{}); 79 server.invoke(objn, "destroy", new Object []{}, new String []{}); 80 server.unregisterMBean(objn); 81 } 82 } catch (Exception e ) { 83 e.printStackTrace(); 84 } 85 } 86 87 public void createTopicConnectionFactory(String name) { 88 createQueueConnectionFactory(name); 89 } 90 91 public void deleteTopicConnectionFactory(String name) { 92 deleteQueueConnectionFactory(name); 93 } 94 95 public void createQueue(String name) { 96 97 try { 98 ObjectName objn = new ObjectName ("jboss.mq:service=DestinationManager"); 99 server.invoke(objn, "createQueue", new Object []{"testsuite-"+name,name}, new String [] {String .class.getName(), String .class.getName()}); 100 } catch (Exception e ) { 101 e.printStackTrace(); 102 } 103 } 104 105 public void createTopic(String name) { 106 try { 107 ObjectName objn = new ObjectName ("jboss.mq:service=DestinationManager"); 108 server.invoke(objn, "createTopic", new Object []{"testsuite-"+name,name}, new String [] {String .class.getName(), String .class.getName()}); 109 } catch (Exception e ) { 110 e.printStackTrace(); 111 } 112 } 113 114 public void deleteQueue(String name) { 115 try { 116 ObjectName objn = new ObjectName ("jboss.mq:service=DestinationManager"); 117 server.invoke(objn, "destroyQueue", new Object []{"testsuite-"+name}, new String [] {String .class.getName()}); 118 } catch (Exception e ) { 119 e.printStackTrace(); 120 } 121 } 122 123 public void deleteTopic(String name) { 124 try { 125 ObjectName objn = new ObjectName ("jboss.mq:service=DestinationManager"); 126 server.invoke(objn, "destroyTopic", new Object []{"testsuite-"+name}, new String [] {String .class.getName()}); 127 } catch (Exception e ) { 128 e.printStackTrace(); 129 } 130 } 131 132 } 133 | Popular Tags |