All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "\n";
      StringBuilder ret = new StringBuilder(ret0);
      for (int i = 0; i < counters.length; i++) {
         MessageCounter counter = counters[i];
         String type = counter.isDestinationTopic() ? "Topic" : "Queue";
         String subscription = counter.getDestinationSubscription();
         if (subscription == null) {
            subscription = "-";
         }
         String durableStr = "-"; // makes no sense for a queue
         if (counter.isDestinationTopic()) {
            durableStr = Boolean.toString(counter.isDestinationDurable());
         }
         ret.append("");

         ret.append("");
         ret.append("");
         ret.append("");
         ret.append("");
         ret.append("");
         ret.append("");
         ret.append("");
         ret.append("");
         ret.append("");
         ret.append("");
         ret.append("");

         ret.append("\n");
      }

      ret.append("
TypeNameSubscriptionDurableCountCountDeltaDepthDepthDeltaLast AddLast AckLast Update
" + type + "" + counter.getDestinationName() + "" + subscription + "" + durableStr + "" + counter.getCount() + "" + MessageCounterHelper.prettify(counter.getCountDelta()) + "" + MessageCounterHelper.prettify(counter.getMessageCount()) + "" + MessageCounterHelper.prettify(counter.getMessageCountDelta()) + "" + MessageCounterHelper.asDate(counter.getLastAddedMessageTime()) + "" + MessageCounterHelper.asDate(counter.getLastAckedMessageTime()) + "" + MessageCounterHelper.asDate(counter.getLastUpdate()) + "
\n"); return ret.toString(); } public static String listMessageCounterHistoryAsHTML(final MessageCounter[] counters) { if (counters == null) { return null; } StringBuilder ret = new StringBuilder("
    \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(""); for (int j = 0; j < 24; j++) { ret.append(""); } ret.append("\n"); // get history data as CSV string StringTokenizer tokens = new StringTokenizer(counter.getHistoryAsString(), ",\n"); // get history day count int days = Integer.parseInt(tokens.nextToken()); for (int j = 0; j < days; j++) { // next day counter row ret.append(""); // date ret.append(""); // 24 hour counters int total = 0; for (int k = 0; k < 24; k++) { int value = Integer.parseInt(tokens.nextToken().trim()); if (value == -1) { ret.append(""); } else { ret.append(""); total += value; } } ret.append("\n"); } ret.append("
      Date" + j + "Total
      " + tokens.nextToken() + "" + value + "" + total + "
    • \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 ------------------------------------------------- }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy