KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jtests > providers > admin > JBossMQAdmin


1 /*
2 * JBoss, the OpenSource J2EE webOS
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */

7 package org.objectweb.jtests.providers.admin;
8
9 import javax.management.Attribute JavaDoc;
10 import javax.management.AttributeList JavaDoc;
11 import javax.management.ObjectName JavaDoc;
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 JavaDoc;
19 import javax.jms.Topic JavaDoc;
20 import java.util.*;
21 import java.io.*;
22 import java.net.InetAddress JavaDoc;
23
24 public class JBossMQAdmin implements Admin {
25   
26     private String JavaDoc 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 JavaDoc 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 JavaDoc e) {
45         e.printStackTrace();
46     }
47     }
48
49
50     public String JavaDoc getName() {
51     return name;
52     }
53
54     public InitialContext createInitialContext() throws NamingException {
55     return ictx;
56     }
57   
58     public void createQueueConnectionFactory(String JavaDoc name) {
59        try {
60           
61           String JavaDoc mbeanClass = "org.jboss.naming.NamingAlias";
62           ObjectName JavaDoc objn = new ObjectName JavaDoc("testsuite:service=NamingAlias,fromName="+name);
63           server.createMBean(mbeanClass, objn);
64           server.setAttribute(objn, new Attribute JavaDoc("ToName", "ConnectionFactory"));
65           server.setAttribute(objn, new Attribute JavaDoc("FromName", name));
66           server.invoke(objn, "create", new Object JavaDoc[]{}, new String JavaDoc[]{});
67           server.invoke(objn, "start", new Object JavaDoc[]{},new String JavaDoc[]{});
68        } catch (Exception JavaDoc e ) {
69           e.printStackTrace();
70        }
71     }
72
73
74     public void deleteQueueConnectionFactory(String JavaDoc name) {
75        try {
76           ObjectName JavaDoc objn = new ObjectName JavaDoc("testsuite:service=NamingAlias,fromName="+name);
77           if( server.isRegistered(objn) ) {
78              server.invoke(objn, "stop", new Object JavaDoc[]{}, new String JavaDoc[]{});
79              server.invoke(objn, "destroy", new Object JavaDoc[]{}, new String JavaDoc[]{});
80              server.unregisterMBean(objn);
81           }
82        } catch (Exception JavaDoc e ) {
83           e.printStackTrace();
84        }
85     }
86     
87     public void createTopicConnectionFactory(String JavaDoc name) {
88        createQueueConnectionFactory(name);
89     }
90     
91     public void deleteTopicConnectionFactory(String JavaDoc name) {
92        deleteQueueConnectionFactory(name);
93     }
94  
95     public void createQueue(String JavaDoc name) {
96        
97        try {
98         ObjectName JavaDoc objn = new ObjectName JavaDoc("jboss.mq:service=DestinationManager");
99         server.invoke(objn, "createQueue", new Object JavaDoc[]{"testsuite-"+name,name}, new String JavaDoc[] {String JavaDoc.class.getName(), String JavaDoc.class.getName()});
100        } catch (Exception JavaDoc e ) {
101           e.printStackTrace();
102        }
103     }
104   
105     public void createTopic(String JavaDoc name) {
106        try {
107         ObjectName JavaDoc objn = new ObjectName JavaDoc("jboss.mq:service=DestinationManager");
108         server.invoke(objn, "createTopic", new Object JavaDoc[]{"testsuite-"+name,name}, new String JavaDoc[] {String JavaDoc.class.getName(), String JavaDoc.class.getName()});
109        } catch (Exception JavaDoc e ) {
110           e.printStackTrace();
111        }
112     }
113
114     public void deleteQueue(String JavaDoc name) {
115        try {
116         ObjectName JavaDoc objn = new ObjectName JavaDoc("jboss.mq:service=DestinationManager");
117         server.invoke(objn, "destroyQueue", new Object JavaDoc[]{"testsuite-"+name}, new String JavaDoc[] {String JavaDoc.class.getName()});
118        } catch (Exception JavaDoc e ) {
119           e.printStackTrace();
120        }
121     }
122  
123     public void deleteTopic(String JavaDoc name) {
124        try {
125         ObjectName JavaDoc objn = new ObjectName JavaDoc("jboss.mq:service=DestinationManager");
126         server.invoke(objn, "destroyTopic", new Object JavaDoc[]{"testsuite-"+name}, new String JavaDoc[] {String JavaDoc.class.getName()});
127        } catch (Exception JavaDoc e ) {
128           e.printStackTrace();
129        }
130     }
131
132 }
133
Popular Tags