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.mq.server.jmx;
023:
024: import java.util.Arrays;
025: import java.util.Collection;
026: import java.util.List;
027:
028: import javax.jms.IllegalStateException;
029:
030: import org.jboss.mq.MessageStatistics;
031: import org.jboss.mq.SpyQueue;
032: import org.jboss.mq.server.JMSDestinationManager;
033: import org.jboss.mq.server.JMSQueue;
034: import org.jboss.mq.server.MessageCounter;
035:
036: /**
037: * This class is a message queue which is stored (hashed by Destination)
038: * on the JMS provider
039: *
040: * @author Norbert Lataille (Norbert.Lataille@m4x.org)
041: * @author <a href="hiram.chirino@jboss.org">Hiram Chirino</a>
042: * @author <a href="pra@tim.se">Peter Antman</a>
043: * @version $Revision: 57198 $
044: */
045: public class Queue extends DestinationMBeanSupport implements
046: QueueMBean {
047: /** The destination */
048: protected JMSQueue destination;
049:
050: public String getQueueName() {
051: return destinationName;
052: }
053:
054: public int getQueueDepth() throws Exception {
055: if (destination == null)
056: return 0;
057: return destination.queue.getQueueDepth();
058: }
059:
060: public int getScheduledMessageCount() throws Exception {
061: if (destination == null)
062: return 0;
063: return destination.queue.getScheduledMessageCount();
064: }
065:
066: public int getInProcessMessageCount() throws Exception {
067: if (destination == null)
068: return 0;
069: return destination.queue.getInProcessMessageCount();
070: }
071:
072: public void startService() throws Exception {
073: if (destinationName == null || destinationName.length() == 0)
074: throw new IllegalStateException("QueueName was not set");
075:
076: JMSDestinationManager jmsServer = (JMSDestinationManager) server
077: .getAttribute(jbossMQService, "Interceptor");
078:
079: spyDest = new SpyQueue(destinationName);
080: destination = new JMSQueue(spyDest, null, jmsServer, parameters);
081:
082: jmsServer.addDestination(destination);
083:
084: if (jndiName == null) {
085: setJNDIName("queue/" + destinationName);
086: } else {
087: // in config phase, all we did was store the name, and not actually bind
088: setJNDIName(jndiName);
089: }
090: super .startService();
091: }
092:
093: public void stopService() throws Exception {
094: super .stopService();
095: destination = null;
096: }
097:
098: public void removeAllMessages() throws Exception {
099: if (destination == null)
100: return;
101: destination.removeAllMessages();
102: }
103:
104: public int getReceiversCount() {
105: if (destination == null)
106: return 0;
107: return destination.queue.getReceiversCount();
108: }
109:
110: public List listReceivers() {
111: if (destination == null)
112: return null;
113: return destination.queue.getReceivers();
114: }
115:
116: public List listMessages() throws Exception {
117: if (destination == null)
118: return null;
119: return Arrays.asList(destination.queue.browse(null));
120: }
121:
122: public List listMessages(String selector) throws Exception {
123: if (destination == null)
124: return null;
125: return Arrays.asList(destination.queue.browse(selector));
126: }
127:
128: public List listScheduledMessages() throws Exception {
129: if (destination == null)
130: return null;
131: return destination.queue.browseScheduled(null);
132: }
133:
134: public List listScheduledMessages(String selector) throws Exception {
135: if (destination == null)
136: return null;
137: return destination.queue.browseScheduled(selector);
138: }
139:
140: public List listInProcessMessages() throws Exception {
141: if (destination == null)
142: return null;
143: return destination.queue.browseInProcess(null);
144: }
145:
146: public List listInProcessMessages(String selector) throws Exception {
147: if (destination == null)
148: return null;
149: return destination.queue.browseInProcess(selector);
150: }
151:
152: public MessageCounter[] getMessageCounter() {
153: if (destination == null)
154: return null;
155: return destination.getMessageCounter();
156: }
157:
158: public MessageStatistics[] getMessageStatistics() throws Exception {
159: if (destination == null)
160: return null;
161: return MessageCounter.getMessageStatistics(destination
162: .getMessageCounter());
163: }
164:
165: public int getSubscribersCount() {
166: if (destination == null)
167: return 0;
168: return destination.queue.getSubscribers().size();
169: }
170:
171: public Collection listSubscribers() {
172: if (destination == null)
173: return null;
174: return destination.queue.getSubscribers();
175: }
176: }
|