ManagedQueue.java
001 /*
002  *
003  * Licensed to the Apache Software Foundation (ASF) under one
004  * or more contributor license agreements.  See the NOTICE file
005  * distributed with this work for additional information
006  * regarding copyright ownership.  The ASF licenses this file
007  * to you under the Apache License, Version 2.0 (the
008  * "License"); you may not use this file except in compliance
009  * with the License.  You may obtain a copy of the License at
010  *
011  *   http://www.apache.org/licenses/LICENSE-2.0
012  *
013  * Unless required by applicable law or agreed to in writing,
014  * software distributed under the License is distributed on an
015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016  * KIND, either express or implied.  See the License for the
017  * specific language governing permissions and limitations
018  * under the License.
019  *
020  */
021 package org.apache.qpid.server.queue;
022 
023 import java.io.IOException;
024 
025 import javax.management.JMException;
026 import javax.management.MBeanOperationInfo;
027 import javax.management.openmbean.CompositeData;
028 import javax.management.openmbean.TabularData;
029 
030 import org.apache.qpid.AMQException;
031 import org.apache.qpid.server.management.MBeanAttribute;
032 import org.apache.qpid.server.management.MBeanOperation;
033 import org.apache.qpid.server.management.MBeanOperationParameter;
034 
035 /**
036  * The management interface exposed to allow management of a queue.
037  @author  Robert J. Greig
038  @author  Bhupendra Bhardwaj
039  @version 0.1
040  */
041 public interface ManagedQueue
042 {
043     static final String TYPE = "Queue";
044 
045     /**
046      * Returns the Name of the ManagedQueue.
047      @return the name of the managedQueue.
048      @throws IOException
049      */
050     @MBeanAttribute(name="Name", description = TYPE + " Name")
051     String getName() throws IOException;
052 
053     /**
054      * Total number of messages on the queue, which are yet to be delivered to the consumer(s).
055      @return number of undelivered message in the Queue.
056      @throws IOException
057      */
058     @MBeanAttribute(name="MessageCount", description = "Total number of undelivered messages on the queue")
059     Integer getMessageCount() throws IOException;
060 
061     /**
062      * Tells the total number of messages receieved by the queue since startup.
063      @return total number of messages received.
064      @throws IOException
065      */
066     @MBeanAttribute(name="ReceivedMessageCount", description="The total number of messages receieved by the queue since startup")
067     Long getReceivedMessageCount() throws IOException;
068 
069     /**
070      * Size of messages in the queue
071      @return
072      @throws IOException
073      */
074     @MBeanAttribute(name="QueueDepth", description="Size of messages(KB) in the queue")
075     Long getQueueDepth() throws IOException, JMException;
076 
077     /**
078      *  Returns the total number of active subscribers to the queue.
079      @return the number of active subscribers
080      @throws IOException
081      */
082     @MBeanAttribute(name="ActiveConsumerCount", description="The total number of active subscribers to the queue")
083     Integer getActiveConsumerCount() throws IOException;
084 
085     /**
086      * Returns the total number of subscribers to the queue.
087      @return the number of subscribers.
088      @throws IOException
089      */
090     @MBeanAttribute(name="ConsumerCount", description="The total number of subscribers to the queue")
091     Integer getConsumerCount() throws IOException;
092 
093     /**
094      * Tells the Owner of the ManagedQueue.
095      @return the owner's name.
096      @throws IOException
097      */
098     @MBeanAttribute(name="Owner", description = "Owner")
099     String getOwner() throws IOException;
100 
101     /**
102      * Tells whether this ManagedQueue is durable or not.
103      @return true if this ManagedQueue is a durable queue.
104      @throws IOException
105      */
106     @MBeanAttribute(name="Durable", description = "true if the AMQQueue is durable")
107     boolean isDurable() throws IOException;
108 
109     /**
110      * Tells if the ManagedQueue is set to AutoDelete.
111      @return  true if the ManagedQueue is set to AutoDelete.
112      @throws IOException
113      */
114     @MBeanAttribute(name="AutoDelete", description = "true if the AMQQueue is AutoDelete")
115     boolean isAutoDelete() throws IOException;
116 
117     /**
118      * Returns the maximum age of a message (expiration time)
119      @return the maximum age
120      @throws IOException
121      */
122     Long getMaximumMessageAge() throws IOException;
123 
124     /**
125      * Sets the maximum age of a message
126      @param age  maximum age of message.
127      @throws IOException
128      */
129     @MBeanAttribute(name="MaximumMessageAge", description="Threshold high value for message age on the broker")
130     void setMaximumMessageAge(Long agethrows IOException;
131 
132     /**
133      * Returns the maximum size of a message (in kbytes) allowed to be accepted by the
134      * ManagedQueue. This is useful in setting notifications or taking
135      * appropriate action, if the size of the message received is more than
136      * the allowed size.
137      @return the maximum size of a message allowed to be aceepted by the
138      *         ManagedQueue.
139      @throws IOException
140      */
141     Long getMaximumMessageSize() throws IOException;
142 
143     /**
144      * Sets the maximum size of the message (in kbytes) that is allowed to be
145      * accepted by the Queue.
146      @param size  maximum size of message.
147      @throws IOException
148      */
149     @MBeanAttribute(name="MaximumMessageSize", description="Threshold high value(KB) for a message size")
150     void setMaximumMessageSize(Long sizethrows IOException;
151 
152     /**
153      * Tells the maximum number of messages that can be stored in the queue.
154      * This is useful in setting the notifications or taking required
155      * action is the number of message increase this limit.
156      @return maximum muber of message allowed to be stored in the queue.
157      @throws IOException
158      */
159     Long getMaximumMessageCount() throws IOException;
160 
161     /**
162      * Sets the maximum number of messages allowed to be stored in the queue.
163      @param value  the maximum number of messages allowed to be stored in the queue.
164      @throws IOException
165      */
166     @MBeanAttribute(name="MaximumMessageCount", description="Threshold high value for number of undelivered messages in the queue")
167     void setMaximumMessageCount(Long valuethrows IOException;
168 
169     /**
170      * This is useful for setting notifications or taking required action if the size of messages
171      * stored in the queue increases over this limit.
172      @return threshold high value for Queue Depth
173      @throws IOException
174      */
175     Long getMaximumQueueDepth() throws IOException;
176 
177     /**
178      * Sets the maximum size of all the messages together, that can be stored
179      * in the queue.
180      @param value
181      @throws IOException
182      */
183     @MBeanAttribute(name="MaximumQueueDepth", description="The threshold high value(KB) for Queue Depth")
184     void setMaximumQueueDepth(Long valuethrows IOException;
185 
186 
187 
188     //********** Operations *****************//
189 
190 
191     /**
192      * Returns a subset of all the messages stored in the queue. The messages
193      * are returned based on the given index numbers.
194      @param fromIndex
195      @param toIndex
196      @return
197      @throws IOException
198      @throws JMException
199      */
200     @MBeanOperation(name="viewMessages",
201                     description="Message headers for messages in this queue within given index range. eg. from index 1 - 100")
202     TabularData viewMessages(@MBeanOperationParameter(name="from index", description="from index")int fromIndex,
203                              @MBeanOperationParameter(name="to index", description="to index")int toIndex)
204             throws IOException, JMException, AMQException;
205 
206     @MBeanOperation(name="viewMessageContent", description="The message content for given Message Id")
207     CompositeData viewMessageContent(@MBeanOperationParameter(name="Message Id", description="Message Id")long messageId)
208         throws IOException, JMException;
209 
210     /**
211      * Deletes the first message from top.
212      @throws IOException
213      @throws JMException
214      */
215     @MBeanOperation(name="deleteMessageFromTop", description="Deletes the first message from top",
216                     impact= MBeanOperationInfo.ACTION)
217     void deleteMessageFromTop() throws IOException, JMException;
218 
219     /**
220      * Clears the queue by deleting all the undelivered messages from the queue.
221      @throws IOException
222      @throws JMException
223      */
224     @MBeanOperation(name="clearQueue",
225                     description="Clears the queue by deleting all the undelivered messages from the queue",
226                     impact= MBeanOperationInfo.ACTION)
227     void clearQueue() throws IOException, JMException;
228 
229     /**
230      * Moves the messages in given range of message Ids to given Queue. QPID-170
231      @param fromMessageId  first in the range of message ids
232      @param toMessageId    last in the range of message ids
233      @param toQueue        where the messages are to be moved
234      @throws IOException
235      @throws JMException
236      @throws AMQException
237      */
238     @MBeanOperation(name="moveMessages",
239                     description="You can move messages to another queue from this queue ",
240                     impact= MBeanOperationInfo.ACTION)
241     void moveMessages(@MBeanOperationParameter(name="from MessageId", description="from MessageId")long fromMessageId,
242                       @MBeanOperationParameter(name="to MessageId", description="to MessageId")long toMessageId,
243                       @MBeanOperationParameter(name= ManagedQueue.TYPE, description="to Queue Name")String toQueue)
244             throws IOException, JMException, AMQException;
245 }