001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.jbossmq;
023:
024: import javax.management.MBeanServerConnection;
025: import javax.management.ObjectName;
026:
027: import org.jboss.logging.Logger;
028: import org.jboss.test.jms.JBossASJMSTestAdmin;
029: import org.jboss.util.NestedRuntimeException;
030:
031: /**
032: * JBossMQAdmin.
033: *
034: * @author <a href="adrian@jboss.com">Adrian Brock</a>
035: * @version $Revision: 57211 $
036: */
037: public class JBossMQAdmin extends JBossASJMSTestAdmin {
038: private Logger log = Logger.getLogger(JBossMQAdmin.class);
039:
040: protected static final ObjectName destinationManager;
041: protected static final ObjectName namingService;
042:
043: static {
044: try {
045: destinationManager = new ObjectName(
046: "jboss.mq:service=DestinationManager");
047: namingService = new ObjectName("jboss:service=Naming");
048: } catch (Exception e) {
049: throw new NestedRuntimeException(e);
050: }
051: }
052:
053: public JBossMQAdmin(Class clazz) throws Exception {
054: super (clazz);
055: }
056:
057: public void createQueue(String name) {
058: try {
059: MBeanServerConnection server = getServer();
060: try {
061: server.invoke(destinationManager, "createQueue",
062: new Object[] { name, name }, new String[] {
063: String.class.getName(),
064: String.class.getName() });
065: } catch (Exception ignored) {
066: log.trace("Ignored", ignored);
067: }
068: ObjectName queueName = new ObjectName(
069: "jboss.mq.destination:service=Queue,name=" + name);
070: server.invoke(queueName, "removeAllMessages", null, null);
071: } catch (Exception e) {
072: throw new NestedRuntimeException(e);
073: }
074: }
075:
076: public void deleteQueue(String name) {
077: try {
078: MBeanServerConnection server = getServer();
079: ObjectName queueName = new ObjectName(
080: "jboss.mq.destination:service=Queue,name=" + name);
081: server.invoke(queueName, "removeAllMessages", null, null);
082: server.invoke(destinationManager, "destroyQueue",
083: new Object[] { name }, new String[] { String.class
084: .getName() });
085: } catch (Exception e) {
086: throw new NestedRuntimeException(e);
087: }
088: }
089:
090: public void createTopic(String name) {
091: try {
092: MBeanServerConnection server = getServer();
093: try {
094: server.invoke(destinationManager, "createTopic",
095: new Object[] { name, name }, new String[] {
096: String.class.getName(),
097: String.class.getName() });
098: } catch (Exception ignored) {
099: log.trace("Ignored", ignored);
100: }
101: ObjectName topicName = new ObjectName(
102: "jboss.mq.destination:service=Topic,name=" + name);
103: server.invoke(topicName, "removeAllMessages", null, null);
104: } catch (Exception e) {
105: throw new NestedRuntimeException(e);
106: }
107: }
108:
109: public void deleteTopic(String name) {
110: try {
111: MBeanServerConnection server = getServer();
112: ObjectName topicName = new ObjectName(
113: "jboss.mq.destination:service=Topic,name=" + name);
114: server.invoke(topicName, "removeAllMessages", null, null);
115: server.invoke(destinationManager, "destroyTopic",
116: new Object[] { name }, new String[] { String.class
117: .getName() });
118: } catch (Exception e) {
119: throw new NestedRuntimeException(e);
120: }
121: }
122:
123: public void createConnectionFactory(String name) {
124: try {
125: MBeanServerConnection server = getServer();
126: server.invoke(namingService, "createAlias", new Object[] {
127: name, "ConnectionFactory" }, new String[] {
128: String.class.getName(), String.class.getName() });
129: } catch (Exception e) {
130: throw new NestedRuntimeException(e);
131: }
132: }
133:
134: public void deleteConnectionFactory(String name) {
135: try {
136: MBeanServerConnection server = getServer();
137: server.invoke(namingService, "removeAlias",
138: new Object[] { name }, new String[] { String.class
139: .getName() });
140: } catch (Exception e) {
141: throw new NestedRuntimeException(e);
142: }
143: }
144: }
|