activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbert...@apache.org
Subject [1/2] activemq-6 git commit: Management Methods for first message timestamp
Date Wed, 22 Apr 2015 22:02:45 GMT
Repository: activemq-6
Updated Branches:
  refs/heads/master fe849a4f1 -> 16137eabc


Management Methods for first message timestamp


Project: http://git-wip-us.apache.org/repos/asf/activemq-6/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-6/commit/00837c12
Tree: http://git-wip-us.apache.org/repos/asf/activemq-6/tree/00837c12
Diff: http://git-wip-us.apache.org/repos/asf/activemq-6/diff/00837c12

Branch: refs/heads/master
Commit: 00837c120d131cd6db706aed5f549db06cd7b1e7
Parents: fe849a4
Author: Daniel Pocock <daniel@pocock.pro>
Authored: Thu Feb 12 15:27:54 2015 +0100
Committer: jbertram <jbertram@redhat.com>
Committed: Wed Apr 22 17:01:39 2015 -0500

----------------------------------------------------------------------
 .../api/core/management/QueueControl.java       | 10 ++++++
 .../api/jms/management/JMSQueueControl.java     | 15 ++++++++
 .../management/impl/JMSQueueControlImpl.java    | 15 ++++++++
 .../core/management/impl/QueueControlImpl.java  | 36 ++++++++++++++++++--
 .../management/JMSQueueControlUsingJMSTest.java | 17 ++++++++-
 .../management/QueueControlTest.java            | 10 ++++++
 .../management/QueueControlUsingCoreTest.java   | 15 ++++++++
 7 files changed, 115 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-6/blob/00837c12/activemq-core-client/src/main/java/org/apache/activemq/api/core/management/QueueControl.java
----------------------------------------------------------------------
diff --git a/activemq-core-client/src/main/java/org/apache/activemq/api/core/management/QueueControl.java
b/activemq-core-client/src/main/java/org/apache/activemq/api/core/management/QueueControl.java
index f864860..5caf8ce 100644
--- a/activemq-core-client/src/main/java/org/apache/activemq/api/core/management/QueueControl.java
+++ b/activemq-core-client/src/main/java/org/apache/activemq/api/core/management/QueueControl.java
@@ -93,6 +93,16 @@ public interface QueueControl
    String getFirstMessageAsJSON() throws Exception;
 
    /**
+    * Returns the timestamp of the first message in milliseconds.
+    */
+   Long getFirstMessageTimestamp() throws Exception;
+
+   /**
+    * Returns the age of the first message in milliseconds.
+    */
+   Long getFirstMessageAge() throws Exception;
+
+   /**
     * Returns the expiry address associated to this queue.
     */
    String getExpiryAddress();

http://git-wip-us.apache.org/repos/asf/activemq-6/blob/00837c12/activemq-jms-client/src/main/java/org/apache/activemq/api/jms/management/JMSQueueControl.java
----------------------------------------------------------------------
diff --git a/activemq-jms-client/src/main/java/org/apache/activemq/api/jms/management/JMSQueueControl.java
b/activemq-jms-client/src/main/java/org/apache/activemq/api/jms/management/JMSQueueControl.java
index dab8d99..586f5c2 100644
--- a/activemq-jms-client/src/main/java/org/apache/activemq/api/jms/management/JMSQueueControl.java
+++ b/activemq-jms-client/src/main/java/org/apache/activemq/api/jms/management/JMSQueueControl.java
@@ -55,6 +55,21 @@ public interface JMSQueueControl extends DestinationControl
     */
    String getSelector();
 
+   /**
+    * Returns the first message on the queue as JSON
+    */
+   String getFirstMessageAsJSON() throws Exception;
+
+   /**
+    * Returns the timestamp of the first message in milliseconds.
+    */
+   Long getFirstMessageTimestamp() throws Exception;
+
+   /**
+    * Returns the age of the first message in milliseconds.
+    */
+   Long getFirstMessageAge() throws Exception;
+
    // Operations ----------------------------------------------------
 
    /**

http://git-wip-us.apache.org/repos/asf/activemq-6/blob/00837c12/activemq-jms-server/src/main/java/org/apache/activemq/jms/management/impl/JMSQueueControlImpl.java
----------------------------------------------------------------------
diff --git a/activemq-jms-server/src/main/java/org/apache/activemq/jms/management/impl/JMSQueueControlImpl.java
b/activemq-jms-server/src/main/java/org/apache/activemq/jms/management/impl/JMSQueueControlImpl.java
index 2185dbf..8d8ef66 100644
--- a/activemq-jms-server/src/main/java/org/apache/activemq/jms/management/impl/JMSQueueControlImpl.java
+++ b/activemq-jms-server/src/main/java/org/apache/activemq/jms/management/impl/JMSQueueControlImpl.java
@@ -146,6 +146,21 @@ public class JMSQueueControlImpl extends StandardMBean implements JMSQueueContro
       return coreQueueControl.getExpiryAddress();
    }
 
+   public String getFirstMessageAsJSON() throws Exception
+   {
+      return coreQueueControl.getFirstMessageAsJSON();
+   }
+
+   public Long getFirstMessageTimestamp() throws Exception
+   {
+      return coreQueueControl.getFirstMessageTimestamp();
+   }
+
+   public Long getFirstMessageAge() throws Exception
+   {
+      return coreQueueControl.getFirstMessageAge();
+   }
+
    @Override
    public void addBinding(String binding) throws Exception
    {

http://git-wip-us.apache.org/repos/asf/activemq-6/blob/00837c12/activemq-server/src/main/java/org/apache/activemq/core/management/impl/QueueControlImpl.java
----------------------------------------------------------------------
diff --git a/activemq-server/src/main/java/org/apache/activemq/core/management/impl/QueueControlImpl.java
b/activemq-server/src/main/java/org/apache/activemq/core/management/impl/QueueControlImpl.java
index 6cf5e19..f5e719b 100644
--- a/activemq-server/src/main/java/org/apache/activemq/core/management/impl/QueueControlImpl.java
+++ b/activemq-server/src/main/java/org/apache/activemq/core/management/impl/QueueControlImpl.java
@@ -19,6 +19,7 @@ package org.apache.activemq.core.management.impl;
 import javax.management.MBeanOperationInfo;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -486,7 +487,7 @@ public class QueueControlImpl extends AbstractControl implements QueueControl
       }
    }
 
-   public String getFirstMessageAsJSON() throws Exception
+   protected Map<String, Object>[] getFirstMessage() throws Exception
    {
       checkStarted();
 
@@ -505,7 +506,7 @@ public class QueueControlImpl extends AbstractControl implements QueueControl
                Message message = ref.getMessage();
                messages.add(message.toMap());
             }
-            return toJSON(messages.toArray(new Map[1])).toString();
+            return messages.toArray(new Map[1]);
          }
          finally
          {
@@ -519,6 +520,37 @@ public class QueueControlImpl extends AbstractControl implements QueueControl
 
    }
 
+   public String getFirstMessageAsJSON() throws Exception
+   {
+      return toJSON(getFirstMessage()).toString();
+   }
+
+   public Long getFirstMessageTimestamp() throws Exception
+   {
+      Map<String, Object>[] _message = getFirstMessage();
+      if (_message == null || _message.length == 0 || _message[0] == null)
+      {
+         return null;
+      }
+      Map<String, Object> message = _message[0];
+      if (!message.containsKey("timestamp"))
+      {
+         return null;
+      }
+      return (Long)message.get("timestamp");
+   }
+
+   public Long getFirstMessageAge() throws Exception
+   {
+      Long firstMessageTimestamp = getFirstMessageTimestamp();
+      if (firstMessageTimestamp == null)
+      {
+         return null;
+      }
+      long now = new Date().getTime();
+      return now - firstMessageTimestamp.longValue();
+   }
+
    public long countMessages(final String filterStr) throws Exception
    {
       checkStarted();

http://git-wip-us.apache.org/repos/asf/activemq-6/blob/00837c12/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/server/management/JMSQueueControlUsingJMSTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/server/management/JMSQueueControlUsingJMSTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/server/management/JMSQueueControlUsingJMSTest.java
index 99ad881..bea7755 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/server/management/JMSQueueControlUsingJMSTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/jms/server/management/JMSQueueControlUsingJMSTest.java
@@ -159,6 +159,21 @@ public class JMSQueueControlUsingJMSTest extends JMSQueueControlTest
             return (String)proxy.retrieveAttributeValue("expiryAddress");
          }
 
+         public String getFirstMessageAsJSON() throws Exception
+         {
+            return (String)proxy.retrieveAttributeValue("firstMessageAsJSON");
+         }
+
+         public Long getFirstMessageTimestamp() throws Exception
+         {
+            return (Long)proxy.retrieveAttributeValue("firstMessageTimestamp");
+         }
+
+         public Long getFirstMessageAge() throws Exception
+         {
+            return (Long)proxy.retrieveAttributeValue("firstMessageAge");
+         }
+
          public long getMessageCount()
          {
             return ((Number)proxy.retrieveAttributeValue("messageCount")).longValue();
@@ -351,4 +366,4 @@ public class JMSQueueControlUsingJMSTest extends JMSQueueControlTest
 
    // Inner classes -------------------------------------------------
 
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/activemq-6/blob/00837c12/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/QueueControlTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/QueueControlTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/QueueControlTest.java
index bc1c75d..fa142ee 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/QueueControlTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/QueueControlTest.java
@@ -285,11 +285,21 @@ public class QueueControlTest extends ManagementTestBase
       // It's empty, so it's supposed to be like this
       assertEquals("[{}]", queueControl.getFirstMessageAsJSON());
 
+      long beforeSend = System.currentTimeMillis();
       ClientProducer producer = session.createProducer(address);
       producer.send(session.createMessage(false).putStringProperty("x", "valueX").putStringProperty("y",
"valueY"));
 
       System.out.println("first:" + queueControl.getFirstMessageAsJSON());
 
+      long firstMessageTimestamp = queueControl.getFirstMessageTimestamp();
+      System.out.println("first message timestamp: " + firstMessageTimestamp);
+      assertTrue(beforeSend <= firstMessageTimestamp);
+      assertTrue(firstMessageTimestamp <= System.currentTimeMillis());
+
+      long firstMessageAge = queueControl.getFirstMessageAge();
+      System.out.println("first message age: " + firstMessageAge);
+      assertTrue(firstMessageAge <= (System.currentTimeMillis() - firstMessageTimestamp));
+
       session.deleteQueue(queue);
    }
 

http://git-wip-us.apache.org/repos/asf/activemq-6/blob/00837c12/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/QueueControlUsingCoreTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/QueueControlUsingCoreTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/QueueControlUsingCoreTest.java
index 28907b0..5632d47 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/QueueControlUsingCoreTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/tests/integration/management/QueueControlUsingCoreTest.java
@@ -182,6 +182,21 @@ public class QueueControlUsingCoreTest extends QueueControlTest
             return (String) proxy.invokeOperation("getFirstMessageAsJSON");
          }
 
+         /**
+          * Returns the timestamp of the first message in milliseconds.
+          */
+         public Long getFirstMessageTimestamp() throws Exception
+         {
+            return (Long) proxy.invokeOperation("getFirstMessageTimestamp");
+         }
+
+         /**
+          * Returns the age of the first message in milliseconds.
+          */
+         public Long getFirstMessageAge() throws Exception
+         {
+            return (Long) proxy.invokeOperation("getFirstMessageAge");
+         }
 
          public String listMessageCounterHistoryAsHTML() throws Exception
          {


Mime
View raw message