diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/JobSchedulerView.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/JobSchedulerView.java index def4218c69..92dfe9277b 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/JobSchedulerView.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/JobSchedulerView.java @@ -24,10 +24,14 @@ import javax.management.openmbean.TabularData; import javax.management.openmbean.TabularDataSupport; import javax.management.openmbean.TabularType; +import org.apache.activemq.Message; +import org.apache.activemq.ScheduledMessage; import org.apache.activemq.broker.jmx.OpenTypeSupport.OpenTypeFactory; import org.apache.activemq.broker.scheduler.Job; import org.apache.activemq.broker.scheduler.JobScheduler; import org.apache.activemq.broker.scheduler.JobSupport; +import org.apache.activemq.openwire.OpenWireFormat; +import org.apache.activemq.util.ByteSequence; /** * MBean object that can be used to manage a single instance of a JobScheduler. The object @@ -76,6 +80,24 @@ public class JobSchedulerView implements JobSchedulerViewMBean { return rc; } + @Override + public int getDelayedMessageCount() throws Exception { + int counter = 0; + OpenWireFormat wireFormat = new OpenWireFormat(); + for (Job job : jobScheduler.getAllJobs()) { + Message msg = (Message) wireFormat.unmarshal(new ByteSequence(job.getPayload())); + if (msg.getLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY) > 0) { + counter++; + } + } + return counter; + } + + @Override + public int getScheduledMessageCount() throws Exception { + return this.jobScheduler.getAllJobs().size(); + } + @Override public TabularData getNextScheduleJobs() throws Exception { OpenTypeFactory factory = OpenTypeSupport.getFactory(Job.class); diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/JobSchedulerViewMBean.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/JobSchedulerViewMBean.java index 82a48ae770..9aedbefc72 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/JobSchedulerViewMBean.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/JobSchedulerViewMBean.java @@ -122,4 +122,24 @@ public interface JobSchedulerViewMBean { @MBeanInfo("get the scheduled Jobs in the Store within the time range. Not HTML friendly ") public abstract TabularData getAllJobs(@MBeanInfo("start: yyyy-MM-dd hh:mm:ss")String start,@MBeanInfo("finish: yyyy-MM-dd hh:mm:ss")String finish)throws Exception; + /** + * Get the number of messages in the scheduler. + * + * @return the number of messages in the scheduler. + * + * @throws Exception if an error occurs while querying the scheduler store. + */ + @MBeanInfo("get the number of scheduled message (basically message in the scheduler") + public abstract int getScheduledMessageCount() throws Exception; + + /** + * Get the number of delayed messages. + * + * @return the number of delayed messages. + * + * @throws Exception if an error occurs while querying the scheduler store. + */ + @MBeanInfo("get the number of delayed message") + public abstract int getDelayedMessageCount() throws Exception; + }