Search in sources :

Example 1 with DayCounterInfo

use of org.apache.activemq.artemis.api.core.management.DayCounterInfo in project activemq-artemis by apache.

the class MessageCounterHelper method listMessageCounterHistory.

// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
public static String listMessageCounterHistory(final MessageCounter counter) throws Exception {
    List<DayCounter> history = counter.getHistory();
    DayCounterInfo[] infos = new DayCounterInfo[history.size()];
    for (int i = 0; i < infos.length; i++) {
        DayCounter dayCounter = history.get(i);
        long[] counters = dayCounter.getCounters();
        GregorianCalendar date = dayCounter.getDate();
        DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);
        String strData = dateFormat.format(date.getTime());
        infos[i] = new DayCounterInfo(strData, counters);
    }
    return DayCounterInfo.toJSON(infos);
}
Also used : DateFormat(java.text.DateFormat) DayCounterInfo(org.apache.activemq.artemis.api.core.management.DayCounterInfo) GregorianCalendar(java.util.GregorianCalendar) DayCounter(org.apache.activemq.artemis.core.messagecounter.MessageCounter.DayCounter)

Example 2 with DayCounterInfo

use of org.apache.activemq.artemis.api.core.management.DayCounterInfo in project activemq-artemis by apache.

the class QueueControlTest method testListMessageCounterHistory.

@Test
public void testListMessageCounterHistory() throws Exception {
    long counterPeriod = 1000;
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    QueueControl queueControl = createManagementControl(address, queue);
    ActiveMQServerControl serverControl = ManagementControlHelper.createActiveMQServerControl(mbeanServer);
    serverControl.enableMessageCounters();
    serverControl.setMessageCounterSamplePeriod(counterPeriod);
    String jsonString = queueControl.listMessageCounterHistory();
    DayCounterInfo[] infos = DayCounterInfo.fromJSON(jsonString);
    Assert.assertEquals(1, infos.length);
    session.deleteQueue(queue);
}
Also used : ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) DayCounterInfo(org.apache.activemq.artemis.api.core.management.DayCounterInfo) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Aggregations

DayCounterInfo (org.apache.activemq.artemis.api.core.management.DayCounterInfo)2 DateFormat (java.text.DateFormat)1 GregorianCalendar (java.util.GregorianCalendar)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 ActiveMQServerControl (org.apache.activemq.artemis.api.core.management.ActiveMQServerControl)1 QueueControl (org.apache.activemq.artemis.api.core.management.QueueControl)1 DayCounter (org.apache.activemq.artemis.core.messagecounter.MessageCounter.DayCounter)1 Test (org.junit.Test)1