jbonofre commented on code in PR #1662:
URL: https://github.com/apache/activemq/pull/1662#discussion_r2999165154


##########
activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java:
##########
@@ -1313,9 +1313,15 @@ public QueueMessageReference getMessage(String id) {
     }
 
     public void purge() throws Exception {
+        purge(this.destinationStatistics.getMessages().getCount());
+    }
+
+    public void purge(long numberOfMessages) throws Exception {
         ConnectionContext c = createConnectionContext();
         List<MessageReference> list = null;
         sendLock.lock();
+
+        long purgeCount = 0L;
         try {
             long originalMessageCount = 
this.destinationStatistics.getMessages().getCount();

Review Comment:
   With the change, `originalMessageCount` is not used anymore, it can be 
removed.



##########
activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java:
##########
@@ -1313,9 +1313,15 @@ public QueueMessageReference getMessage(String id) {
     }
 
     public void purge() throws Exception {
+        purge(this.destinationStatistics.getMessages().getCount());
+    }
+
+    public void purge(long numberOfMessages) throws Exception {
         ConnectionContext c = createConnectionContext();

Review Comment:
   We should add `numberOfMessages` validation here:
   
   
   ```suggestion
           if (numberOfMessages <= 0) {
               return;
           }
           ConnectionContext c = createConnectionContext();
   ```
   
   Else, it means that this method will acquire `sendLock`, create 
`ConnectionContext` and go in the loop even if the number of messages to purge 
is invalid.



##########
activemq-broker/src/main/java/org/apache/activemq/broker/jmx/QueueViewMBean.java:
##########
@@ -70,6 +70,14 @@ public interface QueueViewMBean extends DestinationViewMBean 
{
     @MBeanInfo("Removes all of the messages in the queue.")
     void purge() throws Exception;
 
+    /**
+     * Removes the first number of messages in the queue.
+     *
+     * @throws Exception
+     */
+    @MBeanInfo("Removes the first number of messages in the queue.")
+    void purge(long number) throws Exception;

Review Comment:
   nit: for the reader, we could have use `numberOfMessages` here (to be 
consistent with `QueueView` interface).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to