geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ecr...@apache.org
Subject svn commit: r598415 - in /geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client: GraphsBuilder.java MRCConnector.java
Date Mon, 26 Nov 2007 20:36:21 GMT
Author: ecraig
Date: Mon Nov 26 12:36:21 2007
New Revision: 598415

URL: http://svn.apache.org/viewvc?rev=598415&view=rev
Log:
Monitoring client
-Improved efficiency by changing the graphbuilder so that it calls for 
only the data it needs for a given graph from the mrc-server, as well as 
making the necessary changes to the MRCConnector.


Modified:
    geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/GraphsBuilder.java
    geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MRCConnector.java

Modified: geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/GraphsBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/GraphsBuilder.java?rev=598415&r1=598414&r2=598415&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/GraphsBuilder.java
(original)
+++ geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/GraphsBuilder.java
Mon Nov 26 12:36:21 2007
@@ -20,11 +20,9 @@
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.text.DecimalFormat;
-import java.text.Format;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
 import java.util.HashMap;
+import java.util.Iterator;
+import java.util.TreeMap;
 import java.util.Vector;
 
 public class GraphsBuilder
@@ -128,35 +126,16 @@
                     int skipCount = (int) ((timeFrame / (MRCConnector
                             .getSnapshotDuration() / 60000)))
                             / (snapCount - 2);
-                    ArrayList<HashMap<String, HashMap<String, Object>>>
snapshotList = MRCConnection
-                            .getSnapshots(snapCount, skipCount);
+                    TreeMap<Long, Long> snapshotList = MRCConnection
+                            .getSpecificStatistics(mBeanName, dataName1,
+                                    snapCount, skipCount);
                     // Check if snapshotList is empty
 
                     if (snapshotList.size() == 0)
                     {
-                        HashMap<String, HashMap<String, Object>> tempMap = new
HashMap<String, HashMap<String, Object>>();
-                        HashMap<String, Object> subMap = new HashMap<String, Object>();
-                        subMap.put(dataName1, new Long(0));
-                        if (!dataName2.equals("time") && (dataName2 != null)
-                                && !dataName2.equals("null")
-                                && !dataName2.equals(""))
-                        {
-                            subMap.put(dataName2, new Long(0));
-                        }
-                        tempMap.put(mBeanName, new HashMap<String, Object>(
-                                subMap));
-                        subMap.clear();
-                        subMap.put("snapshot_time", System.currentTimeMillis());
-                        Format formatter = null;
-                        formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-                        Date date = new Date((Long) subMap.get("snapshot_time"));
-                        subMap.put("snapshot_date", formatter.format(date));
-                        tempMap.put("times",
-                                new HashMap<String, Object>(subMap));
-
-                        snapshotList
-                                .add(new HashMap<String, HashMap<String, Object>>(
-                                        tempMap));
+                        snapshotList.put(System.currentTimeMillis(),
+                                new Long(0));
+
                         /*
                          * If there are not enough snapshots available to fill the requested
                          * number, insert some with values of 0 and the proper times.
@@ -164,165 +143,25 @@
                         while (snapshotList.size() < snapCount)
                         {
                             // Temporary, always is first element (oldest)
-                            HashMap<String, HashMap<String, Object>> mapTimeFix
= snapshotList
-                                    .get(0);
-
-                            // Temporary map, used to generate blank data to be
-                            // added to
-                            // the
-                            // list at position 0
-                            HashMap<String, HashMap<String, Object>> tempMap2
= new HashMap<String, HashMap<String, Object>>();
-
-                            // Temporary submap, used to store 0 elements to be
-                            // added to
-                            // the
-                            // tempmap
-                            HashMap<String, Object> subMap2 = new HashMap<String,
Object>();
+                            Long timeFix = snapshotList.firstKey();
 
                             // Calculate appropriate time, add it to the submap,
                             // then
                             // add
                             // that to the tempMap
-                            subMap2
-                                    .put(
-                                            "snapshot_time",
-                                            ((Long) mapTimeFix.get("times")
-                                                    .get("snapshot_time") - (MRCConnector
-                                                    .getSnapshotDuration() * skipCount)));
-                            Format formatter2 = null;
-                            formatter2 = new SimpleDateFormat(
-                                    "yyyy-MM-dd HH:mm:ss");
-                            Date date2 = new Date((Long) subMap2
-                                    .get("snapshot_time"));
-                            subMap2.put("snapshot_date", formatter2
-                                    .format(date2));
-
-                            // Add the submap back to the tempmap
-                            tempMap2.put("times", new HashMap<String, Object>(
-                                    subMap2));
-
-                            // Clear out the subMap for use again
-                            subMap2.clear();
-
-                            // Run through the mbeans
-                            // Verify that it's not times
-                            // Run through the stats elements for the particular
-                            // mbean
-
-                            // Place faux data into the submap
-                            subMap2.put(dataName1, new Long(0));
-                            if (!dataName2.equals("time")
-                                    && (dataName2 != null)
-                                    && !dataName2.equals("null")
-                                    && !dataName2.equals(""))
-                            {
-                                subMap2.put(dataName2, new Long(0));
-                            }
-                            // Add the submap to the tempmap, and clear it
-                            tempMap2.put(mBeanName,
-                                    new HashMap<String, Object>(subMap2));
-
-                            snapshotList
-                                    .add(
-                                            0,
-                                            new HashMap<String, HashMap<String, Object>>(
-                                                    tempMap2));
-                        }
-
-                        /*
-                         * This is where we will be inserting data to fill 'gaps' in the
-                         * snapshots The initial for-loop will travel from the most recent
-                         * snapshot to the oldest, checking that the snapshot_time along
the
-                         * way all align with what they should be
-                         */
-                        for (int i = snapshotList.size() - 1; i > 0; i--)
-                        {
-                            if (i > 0)
-                            {
-                                HashMap<String, HashMap<String, Object>> mapTimeFix
= snapshotList
-                                        .get(i);
-                                HashMap<String, HashMap<String, Object>> mapTimeFix2
= snapshotList
-                                        .get(i - 1);
-                                // here is where we will in missing data
-                                while (((((Long) mapTimeFix.get("times").get(
-                                        "snapshot_time") / 1000) / 60)
-                                        - (((Long) mapTimeFix2.get("times")
-                                                .get("snapshot_time") / 1000) / 60) >
(((MRCConnector
-                                        .getSnapshotDuration() / 1000) / 60) * skipCount)))
-                                {
-                                    HashMap<String, HashMap<String, Object>>
tempMap2 = new HashMap<String, HashMap<String, Object>>();
-                                    HashMap<String, Object> subMap2 = new HashMap<String,
Object>();
-
-                                    // Verify that it's not times
-                                    // Run through the stats elements for the
-                                    // particular
-
-                                    // Place faux data into the submap
-                                    subMap2.put(dataName1, new Long(0));
-                                    if (!dataName2.equals("time")
-                                            && (dataName2 != null)
-                                            && !dataName2.equals("null")
-                                            && !dataName2.equals(""))
-                                    {
-                                        subMap2.put(dataName2, new Long(0));
-                                    }
-
-                                    // Add the submap to the tempmap, and clear
-                                    // it
-                                    tempMap2
-                                            .put(
-                                                    mBeanName,
-                                                    new HashMap<String, Object>(
-                                                            subMap2));
-                                    subMap2.clear();
-
-                                    subMap2
-                                            .put(
-                                                    "snapshot_time",
-                                                    new Long(
-                                                            (Long) mapTimeFix
-                                                                    .get(
-                                                                            "times")
-                                                                    .get(
-                                                                            "snapshot_time")
-                                                                    - (MRCConnector
-                                                                            .getSnapshotDuration()
* skipCount)));
-                                    Format formatter2 = null;
-                                    formatter2 = new SimpleDateFormat(
-                                            "yyyy-MM-dd HH:mm:ss");
-                                    Date date2 = new Date((Long) subMap2
-                                            .get("snapshot_time"));
-                                    subMap2.put("snapshot_date", formatter2
-                                            .format(date2));
-                                    tempMap2
-                                            .put(
-                                                    "times",
-                                                    new HashMap<String, Object>(
-                                                            subMap2));
-                                    subMap2.clear();
-                                    snapshotList
-                                            .add(
-                                                    i,
-                                                    new HashMap<String, HashMap<String,
Object>>(
-                                                            tempMap2));
-                                    snapshotList.remove(0);
-                                    mapTimeFix = tempMap2;
-                                    mapTimeFix2 = snapshotList.get(i - 1);
-                                }
-                            }
+                            snapshotList.put((timeFix - (MRCConnector
+                                    .getSnapshotDuration() * skipCount)),
+                                    new Long(0));
                         }
                     }
 
-                    for (int i = 0; i < snapshotList.size(); i++)
+                    for (Iterator<Long> it = snapshotList.keySet().iterator(); it
+                            .hasNext();)
                     {
-                        HashMap<String, HashMap<String, Object>> map = snapshotList
-                                .get(i);
-                        snapshot_date
-                                .add(map.get("times").get("snapshot_date"));
-                        snapshot_time
-                                .add(map.get("times").get("snapshot_time"));
+                        Long current = it.next();
+                        snapshot_time.add(current);
                         Vector<Object> vectorTemp = DataList.get(graphName1);
-                        vectorTemp.add(map.get(mBeanName).get(dataName1));
+                        vectorTemp.add(snapshotList.get(current));
                         DataList.put(graphName1, vectorTemp);
                         if (!dataName2.equals("time") && (dataName2 != null)
                                 && !dataName2.equals("null")
@@ -330,12 +169,11 @@
                         {
                             Vector<Object> vectorTemp2 = DataList
                                     .get(graphName2);
-                            vectorTemp2.add(map.get(mBeanName).get(dataName2));
+                            vectorTemp2.add(snapshotList.get(current));
                             DataList.put(graphName2, vectorTemp2);
                         }
 
-                        PrettyTime.add((Long) map.get("times").get(
-                                "snapshot_time") / 1000);
+                        PrettyTime.add(current / 1000);
                     }
 
                 }

Modified: geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MRCConnector.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MRCConnector.java?rev=598415&r1=598414&r2=598415&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MRCConnector.java
(original)
+++ geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MRCConnector.java
Mon Nov 26 12:36:21 2007
@@ -287,6 +287,65 @@
     }
 
     @SuppressWarnings("unchecked")
+    public TreeMap<Long, Long> getSpecificStatistics(String mbeanName,
+            String statsName, int snapCount, int skipCount) throws Exception
+    {
+        TreeMap<Long, Long> snapshotList = mrc.getSpecificStatistics(mbeanName,
+                statsName, snapCount, skipCount);
+        // Check if snapshotList is empty
+        if (snapshotList.size() == 0)
+        {
+            return snapshotList;
+        }
+        /*
+         * If there are not enough snapshots available to fill the requested
+         * number, insert some with values of 0 and the proper times.
+         */
+        while (snapshotList.size() < snapCount)
+        {
+            // Temporary, always is first element (oldest)
+            Long timeFix = snapshotList.firstKey();
+
+            // Calculate appropriate time, add it to the submap, then
+            // add
+            // that to the tempMap
+            snapshotList
+                    .put(
+                            (timeFix - (MRCConnector.getSnapshotDuration() * skipCount)),
+                            new Long(0));
+        }
+
+        /*
+         * This is where we will be inserting data to fill 'gaps' in the
+         * snapshots The initial for-loop will travel from the most recent
+         * snapshot to the oldest, checking that the snapshot_time along the
+         * way all align with what they should be
+         */
+        Set tempSet = snapshotList.keySet();
+        ArrayList<Long> tempArray = new ArrayList(tempSet);
+
+        for (int i = tempArray.size() - 1; i > 0; i--)
+        {
+            Long tempLong1 = tempArray.get(i);
+            Long tempLong2 = tempArray.get(i - 1);
+            // here is where we will in missing data
+            while (((((Long) tempLong1 / 1000) / 60)
+                    - (((Long) tempLong2 / 1000) / 60) > (((MRCConnector
+                    .getSnapshotDuration() / 1000) / 60) * skipCount)))
+            {
+
+                tempLong1 = tempLong1
+                        - (MRCConnector.getSnapshotDuration() * skipCount);
+                snapshotList.put(tempLong1, new Long(0));
+                snapshotList.remove(tempArray.get(0));
+                tempArray.remove(0);
+                tempLong2 = tempArray.get(i - 1);
+            }
+        }
+        return snapshotList;
+    }
+
+    @SuppressWarnings("unchecked")
     public HashMap<String, HashMap<String, Object>> getLatestSnapshots()
             throws Exception
     {



Mime
View raw message