org.apache.activemq.artemis.core.messagecounter.impl.MessageCounterHelper Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.core.messagecounter.impl;
import java.text.DateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.StringTokenizer;
import org.apache.activemq.artemis.api.core.management.DayCounterInfo;
import org.apache.activemq.artemis.core.messagecounter.MessageCounter;
import org.apache.activemq.artemis.core.messagecounter.MessageCounter.DayCounter;
public class MessageCounterHelper {
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
public static String listMessageCounterHistory(final MessageCounter counter) throws Exception {
List 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);
}
public static String listMessageCounterAsHTML(final MessageCounter[] counters) {
if (counters == null) {
return null;
}
String ret0 = "\n");
for (MessageCounter counter : counters) {
ret.append("- \n");
ret.append("
\n");
ret.append(" - ");
// destination name
ret.append((counter.isDestinationTopic() ? "Topic '" : "Queue '") + counter.getDestinationName() + "'");
ret.append("
\n");
if (counter.getDestinationSubscription() != null) {
ret.append(" - ");
ret.append("Subscription '" + counter.getDestinationSubscription() + "'");
ret.append("
\n");
}
ret.append(" - ");
// table header
ret.append("
\n");
ret.append("
\n");
ret.append(" \n");
}
ret.append("
\n");
return ret.toString();
}
private static String prettify(final long value) {
if (value == 0) {
return "-";
}
return Long.toString(value);
}
private static String asDate(final long time) {
if (time > 0) {
return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(time));
} else {
return "-";
}
}
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
}
\n");
return ret.toString();
}
public static String listMessageCounterHistoryAsHTML(final MessageCounter[] counters) {
if (counters == null) {
return null;
}
StringBuilder ret = new StringBuilder("