ARTEMIS-1956 move MessageCounterInfo to core-client

This commit is contained in:
Justin Bertram 2018-06-27 14:34:00 -05:00 committed by Clebert Suconic
parent c3375b9d54
commit 9ad9051165
3 changed files with 29 additions and 22 deletions

View File

@ -17,14 +17,8 @@
package org.apache.activemq.artemis.api.core.management;
import javax.json.JsonObject;
import java.text.DateFormat;
import java.util.Date;
import org.apache.activemq.artemis.api.core.JsonUtil;
import org.apache.activemq.artemis.core.messagecounter.MessageCounter;
import org.apache.activemq.artemis.utils.JsonLoader;
import static org.apache.activemq.artemis.api.core.JsonUtil.nullSafe;
/**
* Helper class to create Java Objects from the
@ -50,20 +44,6 @@ public final class MessageCounterInfo {
private final String udpateTimestamp;
/**
* Returns a JSON String serialization of a {@link MessageCounter} object.
*
* @param counter
* @return
* @throws Exception
*/
public static String toJSon(final MessageCounter counter) throws Exception {
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
String lastAddTimestamp = dateFormat.format(new Date(counter.getLastAddedMessageTime()));
String updateTimestamp = dateFormat.format(new Date(counter.getLastUpdate()));
return JsonLoader.createObjectBuilder().add("destinationName", nullSafe(counter.getDestinationName())).add("destinationSubscription", nullSafe(counter.getDestinationSubscription())).add("destinationDurable", counter.isDestinationDurable()).add("count", counter.getCount()).add("countDelta", counter.getCountDelta()).add("messageCount", counter.getMessageCount()).add("messageCountDelta", counter.getMessageCountDelta()).add("lastAddTimestamp", lastAddTimestamp).add("updateTimestamp", updateTimestamp).build().toString();
}
/**
* Returns a MessageCounterInfo corresponding to the JSON serialization returned
* by {@link QueueControl#listMessageCounter()}.

View File

@ -35,7 +35,6 @@ import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.api.core.JsonUtil;
import org.apache.activemq.artemis.api.core.Message;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.management.MessageCounterInfo;
import org.apache.activemq.artemis.api.core.management.QueueControl;
import org.apache.activemq.artemis.core.filter.Filter;
import org.apache.activemq.artemis.core.filter.impl.FilterImpl;
@ -993,7 +992,7 @@ public class QueueControlImpl extends AbstractControl implements QueueControl {
clearIO();
try {
return MessageCounterInfo.toJSon(counter);
return counter.toJSon();
} catch (Exception e) {
throw new IllegalStateException(e);
} finally {

View File

@ -19,10 +19,14 @@ package org.apache.activemq.artemis.core.messagecounter;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import org.apache.activemq.artemis.core.server.Queue;
import org.apache.activemq.artemis.utils.JsonLoader;
import static org.apache.activemq.artemis.api.core.JsonUtil.nullSafe;
/**
* This class stores message count informations for a given queue
@ -308,6 +312,30 @@ public class MessageCounter {
"]";
}
/**
* Returns a JSON String serialization of a {@link MessageCounter} object.
*
* @return
*/
public String toJSon() {
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
String lastAddTimestamp = dateFormat.format(new Date(this.getLastAddedMessageTime()));
String updateTimestamp = dateFormat.format(new Date(this.getLastUpdate()));
return JsonLoader
.createObjectBuilder()
.add("destinationName", nullSafe(this.getDestinationName()))
.add("destinationSubscription", nullSafe(this.getDestinationSubscription()))
.add("destinationDurable", this.isDestinationDurable())
.add("count", this.getCount())
.add("countDelta", this.getCountDelta())
.add("messageCount", this.getMessageCount())
.add("messageCountDelta", this.getMessageCountDelta())
.add("lastAddTimestamp", lastAddTimestamp)
.add("updateTimestamp", updateTimestamp)
.build()
.toString();
}
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------