[AMQ-7246] Add scheduledMessageCount attribute on the JobSchedulerView MBean

(cherry picked from commit f01e35f7d9)
This commit is contained in:
jbonofre 2021-01-12 18:43:46 +01:00
parent 4cc287fcd7
commit 34bc37d68d
2 changed files with 42 additions and 0 deletions

View File

@ -24,10 +24,14 @@ import javax.management.openmbean.TabularData;
import javax.management.openmbean.TabularDataSupport; import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.TabularType; 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.jmx.OpenTypeSupport.OpenTypeFactory;
import org.apache.activemq.broker.scheduler.Job; import org.apache.activemq.broker.scheduler.Job;
import org.apache.activemq.broker.scheduler.JobScheduler; import org.apache.activemq.broker.scheduler.JobScheduler;
import org.apache.activemq.broker.scheduler.JobSupport; 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 * 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; 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 @Override
public TabularData getNextScheduleJobs() throws Exception { public TabularData getNextScheduleJobs() throws Exception {
OpenTypeFactory factory = OpenTypeSupport.getFactory(Job.class); OpenTypeFactory factory = OpenTypeSupport.getFactory(Job.class);

View File

@ -122,4 +122,24 @@ public interface JobSchedulerViewMBean {
@MBeanInfo("get the scheduled Jobs in the Store within the time range. Not HTML friendly ") @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; 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;
} }