geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From genspr...@apache.org
Subject svn commit: r1040116 - in /geronimo/server/branches/2.1/plugins/monitoring: agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/SnapshotConfigXMLBuilder.java agent-jmx/src/main/java/org/apache/geronimo/monitoring/MasterRemoteControlJMX.java
Date Mon, 29 Nov 2010 14:09:17 GMT
Author: genspring
Date: Mon Nov 29 14:09:17 2010
New Revision: 1040116

URL: http://svn.apache.org/viewvc?rev=1040116&view=rev
Log:
GERONIMO-5712 Geronimo should remember the monitoring server enablement status. Eable JMX
agent snapshot thread status persistence

Modified:
    geronimo/server/branches/2.1/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/SnapshotConfigXMLBuilder.java
    geronimo/server/branches/2.1/plugins/monitoring/agent-jmx/src/main/java/org/apache/geronimo/monitoring/MasterRemoteControlJMX.java

Modified: geronimo/server/branches/2.1/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/SnapshotConfigXMLBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/SnapshotConfigXMLBuilder.java?rev=1040116&r1=1040115&r2=1040116&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/SnapshotConfigXMLBuilder.java
(original)
+++ geronimo/server/branches/2.1/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/SnapshotConfigXMLBuilder.java
Mon Nov 29 14:09:17 2010
@@ -17,7 +17,6 @@
 package org.apache.geronimo.monitoring.snapshot;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.util.ArrayList;
 
 import javax.xml.parsers.DocumentBuilder;
@@ -26,7 +25,6 @@ import javax.xml.parsers.ParserConfigura
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -37,6 +35,8 @@ import org.w3c.dom.NodeList;
  * In charge of dealing with the XML processing of the snapshot's data.
  */
 public class SnapshotConfigXMLBuilder {
+ 
+
     private static Log log = LogFactory.getLog(SnapshotConfigXMLBuilder.class);
     
     private static final String pathToXML = 
@@ -45,8 +45,10 @@ public class SnapshotConfigXMLBuilder {
     private static final String SNAPSHOT_CONFIG = "snapshot-config";
     private static final String DURATION = "duration";
     private static final String RETENTION = "retention";
+    private static final String SNAPSHOT_THREAD_START = "snapshotThreadStart";
     private static final String MBEAN = "mbean"; 
     
+    
     /**
      * @return A list of all mbean names that have been previously saved.
      * These mbean names are those to keep track of for per snapshot.
@@ -129,13 +131,14 @@ public class SnapshotConfigXMLBuilder {
             return true;
         }
     }
-    
+
     /**
      * Saves the duration of the snapshot as a configuration attribute
      * @param duration
      */
     public static void saveDuration(long duration) {
-        saveAttribute(DURATION, duration);
+        
+        saveAttribute(DURATION, Long.toString(duration));
     }
 
     /**
@@ -143,7 +146,16 @@ public class SnapshotConfigXMLBuilder {
      * @param retention
      */
     public static void saveRetention(int retention) {
-        saveAttribute(RETENTION, retention);
+        saveAttribute(RETENTION, Integer.toString(retention));
+    }
+    
+    /**
+     * Remember the flag to determine if the snapshot thread 
+     * should be started when the server is restarted.
+     * @param snapshotThreadStart
+     */
+    public static void saveSnapshotThreadStatus(boolean snapshotThreadStart) {
+        saveAttribute(SNAPSHOT_THREAD_START, Boolean.toString(snapshotThreadStart));
     }
     
     /**
@@ -152,7 +164,7 @@ public class SnapshotConfigXMLBuilder {
      * @param attrName
      * @param attributeValue
      */
-    private static void saveAttribute(String attrName, long attributeValue) {
+    private static void saveAttribute(String attrName, String attributeValue) {
         Document doc = openDocument();
         // get the root node        
         Element rootElement = doc.getDocumentElement();
@@ -164,14 +176,14 @@ public class SnapshotConfigXMLBuilder {
             Node configNode = configNodes.item(i);
             if(attrName.equals(configNode.getNodeName())) {
                 // found a match
-                configNode.setTextContent(attributeValue + "");
+                configNode.setTextContent(attributeValue);
                 foundNode = true;
             }
         }
         // if there was not a duration node, make one
         if(!foundNode) {
             Element element = doc.createElement(attrName);
-            element.setTextContent(attributeValue + "");
+            element.setTextContent(attributeValue);
             rootElement.appendChild(element);
         }
         try {
@@ -315,4 +327,6 @@ public class SnapshotConfigXMLBuilder {
             }
         }
     }
+
+   
 }

Modified: geronimo/server/branches/2.1/plugins/monitoring/agent-jmx/src/main/java/org/apache/geronimo/monitoring/MasterRemoteControlJMX.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/monitoring/agent-jmx/src/main/java/org/apache/geronimo/monitoring/MasterRemoteControlJMX.java?rev=1040116&r1=1040115&r2=1040116&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/monitoring/agent-jmx/src/main/java/org/apache/geronimo/monitoring/MasterRemoteControlJMX.java
(original)
+++ geronimo/server/branches/2.1/plugins/monitoring/agent-jmx/src/main/java/org/apache/geronimo/monitoring/MasterRemoteControlJMX.java
Mon Nov 29 14:09:17 2010
@@ -17,7 +17,6 @@
 package org.apache.geronimo.monitoring;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -28,33 +27,24 @@ import javax.management.Attribute;
 import javax.management.MBeanServer;
 import javax.management.MBeanServerFactory;
 import javax.management.ObjectName;
-import javax.management.j2ee.Management;
-import javax.management.j2ee.ManagementHome;
-import javax.management.j2ee.statistics.BoundedRangeStatistic;
 import javax.management.j2ee.statistics.RangeStatistic;
 import javax.management.j2ee.statistics.Stats;
 import javax.management.j2ee.statistics.CountStatistic;
 import javax.management.j2ee.statistics.Statistic;
 import javax.management.j2ee.statistics.TimeStatistic;
-import javax.naming.Context;
 import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import javax.sql.DataSource;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 
-import org.apache.geronimo.connector.outbound.ManagedConnectionFactoryWrapper;
-import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.GBeanLifecycle;
 
 import org.apache.geronimo.monitoring.MBeanHelper;
 
-import org.apache.xbean.naming.context.WritableContext.NestedWritableContext;
-
 import org.apache.geronimo.monitoring.snapshot.SnapshotThread;
 import org.apache.geronimo.monitoring.snapshot.SnapshotConfigXMLBuilder;
 import org.apache.geronimo.monitoring.snapshot.SnapshotDBHelper;
@@ -71,6 +61,7 @@ public class MasterRemoteControlJMX impl
     private static final int DEFAULT_RETENTION = 30;
     private static final String RETENTION = "retention";
     private static final String DURATION = "duration";
+    private static final String SNAPSHOT_THREAD_START = "snapshotThreadStart";
 
     // mbean server to talk to other components
     private static MBeanServer mbServer = null;
@@ -175,9 +166,18 @@ public class MasterRemoteControlJMX impl
      * Stops the snapshot thread
      */
     public boolean stopSnapshot() {
+        
+       saveSnapshotThreadStatus(false);
+       return  this.stopSnapshotOnly();
+       
+    }
+    
+    private boolean stopSnapshotOnly(){
+        
         if(snapshotThread != null) {
             if(snapshotThread.getSnapshotDuration() != Long.MAX_VALUE) {
                 saveDuration(snapshotThread.getSnapshotDuration());
+                saveSnapshotThreadStatus(false);
                 snapshotThread.setSnapshotDuration(Long.MAX_VALUE);
                 log.info("Snapshot thread stopped.");
                 return true;
@@ -188,6 +188,7 @@ public class MasterRemoteControlJMX impl
             log.error("There is not a snapshot thread running. Stopping aborted.");
             return false;
         }
+        
     }
     
     /**
@@ -297,9 +298,12 @@ public class MasterRemoteControlJMX impl
     public boolean startSnapshot(Long interval, Integer retention) {
         if((snapshotThread == null || (snapshotThread != null && (snapshotThread.SnapshotStatus()
== 0))) && interval.longValue() > 0) {
             saveDuration(interval.longValue());
-            saveRetention(retention.intValue());
+            saveRetention(retention.intValue());      
+            saveSnapshotThreadStatus(true);
             snapshotThread = new SnapshotThread(interval.longValue(), mbServer);
+            snapshotThread.setName("JMX Monitoring Agent Snapshot Thread");
             snapshotThread.start();
+
             log.info("Snapshot thread successfully created.");
             return true;
         } else {
@@ -349,7 +353,29 @@ public class MasterRemoteControlJMX impl
      * Executes when the GBean starts up. Also starts the snapshot thread.
      */
     public void doStart() {
-    
+        
+        String shouldJMXSnapshotBeOnlineStr="";
+        boolean shouldJMXSnapshotBeOnline = false;
+
+        try {
+            shouldJMXSnapshotBeOnlineStr = SnapshotConfigXMLBuilder.getAttributeValue(SNAPSHOT_THREAD_START);
+            shouldJMXSnapshotBeOnline = Boolean.parseBoolean(shouldJMXSnapshotBeOnlineStr);
+        } catch (Exception e1) {
+            log.debug("can't parse boolean value for string:"+shouldJMXSnapshotBeOnlineStr+",shouldJMXSnapshotBeOnline
will be the defaul value:false", e1);            
+        }
+        
+        if (shouldJMXSnapshotBeOnline) {
+            String duration="";
+            long interval=DEFAULT_DURATION;
+            try {
+                duration=SnapshotConfigXMLBuilder.getAttributeValue(DURATION);
+                interval = Long.parseLong(duration);
+            } catch (Exception e) {
+                log.warn("failed to parse DURATION:+"+duration, e);
+            }
+
+            this.startSnapshot(interval);
+        }
     }
     
     /**
@@ -357,7 +383,7 @@ public class MasterRemoteControlJMX impl
      */
     public void doStop() {
         if(SnapshotStatus() == 1) {
-            stopSnapshot();
+            stopSnapshotOnly();
         }
     }
     
@@ -369,6 +395,10 @@ public class MasterRemoteControlJMX impl
         SnapshotConfigXMLBuilder.saveRetention(retention);
     }
     
+    private void saveSnapshotThreadStatus(boolean snapshotThreadStart) {
+        SnapshotConfigXMLBuilder.saveSnapshotThreadStatus(snapshotThreadStart);
+    }
+    
     /**
      * Adds a record of the mbean via its name to take snapshots of. As a result
      * the mbeanName will be written to snapshot-config.xml



Mime
View raw message