KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossmq > JBossMQAdmin


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.jbossmq;
23
24 import javax.management.MBeanServerConnection JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26
27 import org.jboss.logging.Logger;
28 import org.jboss.test.jms.JBossASJMSTestAdmin;
29 import org.jboss.util.NestedRuntimeException;
30
31 /**
32  * JBossMQAdmin.
33  *
34  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
35  * @version $Revision: 38213 $
36  */

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