You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by rw...@apache.org on 2011/08/10 05:28:38 UTC

svn commit: r1156009 - in /geronimo/server/trunk/plugins/monitoring: agent-jar/src/main/java/org/apache/geronimo/monitoring/ agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/ agent-jar/src/xsd/ agent-jmx/src/main/java/org/apache/geronimo...

Author: rwonly
Date: Wed Aug 10 03:28:37 2011
New Revision: 1156009

URL: http://svn.apache.org/viewvc?rev=1156009&view=rev
Log:
GERONIMO-5712 Geronimo should remember the monitoring server enablement status. ( Thanks Fang Shenghao for the patch!)

Modified:
    geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/MonitorConstants.java
    geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/ObjectFactory.java
    geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/SnapshotConfig.java
    geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/SnapshotConfigXMLBuilder.java
    geronimo/server/trunk/plugins/monitoring/agent-jar/src/xsd/SnapshotConfig.xsd
    geronimo/server/trunk/plugins/monitoring/agent-jmx/src/main/java/org/apache/geronimo/monitoring/jmx/MasterRemoteControlJMX.java

Modified: geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/MonitorConstants.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/MonitorConstants.java?rev=1156009&r1=1156008&r2=1156009&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/MonitorConstants.java (original)
+++ geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/MonitorConstants.java Wed Aug 10 03:28:37 2011
@@ -31,4 +31,6 @@ public class MonitorConstants {
     // used in SnapshotConfigXMLBuilder and MasterRemoteControl classes
     public static final String RETENTION = "retention";
     public static final String DURATION = "duration";
+    public static final String STARTED = "started";
+
 }

Modified: geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/ObjectFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/ObjectFactory.java?rev=1156009&r1=1156008&r2=1156009&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/ObjectFactory.java (original)
+++ geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/ObjectFactory.java Wed Aug 10 03:28:37 2011
@@ -14,17 +14,16 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
+
 package org.apache.geronimo.monitoring.snapshot;
 
 import javax.xml.bind.annotation.XmlRegistry;
-import org.apache.geronimo.monitoring.snapshot.SnapshotConfig;
-import org.apache.geronimo.monitoring.snapshot.SnapshotConfig.Mbeans;
 
 
 /**
  * This object contains factory methods for each 
  * Java content interface and Java element interface 
- * generated in the org.apache.geronimo package. 
+ * generated in the org.apache.geronimo.monitoring.snapshot package. 
  * <p>An ObjectFactory allows you to programatically 
  * construct new instances of the Java representation 
  * for XML content. The Java representation of XML 
@@ -40,18 +39,18 @@ public class ObjectFactory {
 
 
     /**
-     * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.apache.geronimo
+     * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.apache.geronimo.monitoring.snapshot
      * 
      */
     public ObjectFactory() {
     }
 
     /**
-     * Create an instance of {@link Mbeans }
+     * Create an instance of {@link SnapshotConfig.Mbeans }
      * 
      */
-    public Mbeans createSnapshotConfigMbeans() {
-        return new Mbeans();
+    public SnapshotConfig.Mbeans createSnapshotConfigMbeans() {
+        return new SnapshotConfig.Mbeans();
     }
 
     /**

Modified: geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/SnapshotConfig.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/SnapshotConfig.java?rev=1156009&r1=1156008&r2=1156009&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/SnapshotConfig.java (original)
+++ geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/SnapshotConfig.java Wed Aug 10 03:28:37 2011
@@ -14,45 +14,46 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
+
 package org.apache.geronimo.monitoring.snapshot;
 
 import java.util.ArrayList;
 import java.util.List;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 
 
 /**
- * <p>Java class for snapshot-config element declaration.
+ * <p>Java class for anonymous complex type.
  * 
  * <p>The following schema fragment specifies the expected content contained within this class.
  * 
  * <pre>
- * &lt;element name="snapshot-config">
- *   &lt;complexType>
- *     &lt;complexContent>
- *       &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *         &lt;sequence>
- *           &lt;element name="duration" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *           &lt;element name="retention" type="{http://www.w3.org/2001/XMLSchema}string"/>
- *           &lt;element name="mbeans">
- *             &lt;complexType>
- *               &lt;complexContent>
- *                 &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *                   &lt;sequence>
- *                     &lt;element name="mbean" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded" minOccurs="0"/>
- *                   &lt;/sequence>
- *                 &lt;/restriction>
- *               &lt;/complexContent>
- *             &lt;/complexType>
- *           &lt;/element>
- *         &lt;/sequence>
- *       &lt;/restriction>
- *     &lt;/complexContent>
- *   &lt;/complexType>
- * &lt;/element>
+ * &lt;complexType>
+ *   &lt;complexContent>
+ *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       &lt;sequence>
+ *         &lt;element name="duration" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *         &lt;element name="retention" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *         &lt;element name="started" type="{http://www.w3.org/2001/XMLSchema}string"/>
+ *         &lt;element name="mbeans">
+ *           &lt;complexType>
+ *             &lt;complexContent>
+ *               &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *                 &lt;sequence>
+ *                   &lt;element name="mbean" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded" minOccurs="0"/>
+ *                 &lt;/sequence>
+ *               &lt;/restriction>
+ *             &lt;/complexContent>
+ *           &lt;/complexType>
+ *         &lt;/element>
+ *       &lt;/sequence>
+ *     &lt;/restriction>
+ *   &lt;/complexContent>
+ * &lt;/complexType>
  * </pre>
  * 
  * 
@@ -61,14 +62,20 @@ import javax.xml.bind.annotation.XmlType
 @XmlType(name = "", propOrder = {
     "duration",
     "retention",
+    "started",
     "mbeans"
 })
 @XmlRootElement(name = "snapshot-config")
 public class SnapshotConfig {
 
+    @XmlElement(required = true)
     protected String duration;
+    @XmlElement(required = true)
     protected String retention;
-    protected Mbeans mbeans;
+    @XmlElement(required = true)
+    protected String started;
+    @XmlElement(required = true)
+    protected SnapshotConfig.Mbeans mbeans;
 
     /**
      * Gets the value of the duration property.
@@ -119,14 +126,38 @@ public class SnapshotConfig {
     }
 
     /**
+     * Gets the value of the started property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link String }
+     *     
+     */
+    public String getStarted() {
+        return started;
+    }
+
+    /**
+     * Sets the value of the started property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link String }
+     *     
+     */
+    public void setStarted(String value) {
+        this.started = value;
+    }
+
+    /**
      * Gets the value of the mbeans property.
      * 
      * @return
      *     possible object is
-     *     {@link Mbeans }
+     *     {@link SnapshotConfig.Mbeans }
      *     
      */
-    public Mbeans getMbeans() {
+    public SnapshotConfig.Mbeans getMbeans() {
         return mbeans;
     }
 
@@ -135,10 +166,10 @@ public class SnapshotConfig {
      * 
      * @param value
      *     allowed object is
-     *     {@link Mbeans }
+     *     {@link SnapshotConfig.Mbeans }
      *     
      */
-    public void setMbeans(Mbeans value) {
+    public void setMbeans(SnapshotConfig.Mbeans value) {
         this.mbeans = value;
     }
 

Modified: geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/SnapshotConfigXMLBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/SnapshotConfigXMLBuilder.java?rev=1156009&r1=1156008&r2=1156009&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/SnapshotConfigXMLBuilder.java (original)
+++ geronimo/server/trunk/plugins/monitoring/agent-jar/src/main/java/org/apache/geronimo/monitoring/snapshot/SnapshotConfigXMLBuilder.java Wed Aug 10 03:28:37 2011
@@ -132,7 +132,7 @@ public class SnapshotConfigXMLBuilder {
      */
     public static void saveDuration(long duration) {
         SnapshotConfig sc = getSnapshotConfig();
-        sc.setDuration("" + duration);
+        sc.setDuration(String.valueOf(duration));
         saveDocument(sc);
     }
 
@@ -142,10 +142,16 @@ public class SnapshotConfigXMLBuilder {
      */
     public static void saveRetention(int retention) {
         SnapshotConfig sc = getSnapshotConfig();
-        sc.setRetention("" + retention);
+        sc.setRetention(String.valueOf(retention));
         saveDocument(sc);
     }
-       
+    
+    public static void saveStarted(boolean started) {
+        SnapshotConfig sc = getSnapshotConfig();
+        sc.setStarted(String.valueOf(started));
+        saveDocument(sc);
+    }
+    
     /**
      * Returns the value of the configuration attribute, defined by the key
      * @param key
@@ -157,6 +163,8 @@ public class SnapshotConfigXMLBuilder {
             return getSnapshotConfig().getDuration();
         } else if(key.equals( MonitorConstants.RETENTION )) {
             return getSnapshotConfig().getRetention();
+        } else if(key.equals( MonitorConstants.STARTED)) {
+            return getSnapshotConfig().getStarted();
         } else {
             // Houston, we have a problem
             throw new Exception("[WARNING] Attribute: " + key + " is not valid.");

Modified: geronimo/server/trunk/plugins/monitoring/agent-jar/src/xsd/SnapshotConfig.xsd
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/monitoring/agent-jar/src/xsd/SnapshotConfig.xsd?rev=1156009&r1=1156008&r2=1156009&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/monitoring/agent-jar/src/xsd/SnapshotConfig.xsd (original)
+++ geronimo/server/trunk/plugins/monitoring/agent-jar/src/xsd/SnapshotConfig.xsd Wed Aug 10 03:28:37 2011
@@ -28,6 +28,8 @@
                              minOccurs="1"  maxOccurs="1"/>
                 <xsd:element name="retention" type="xsd:string"
                              minOccurs="1"  maxOccurs="1"/>
+                <xsd:element name="started" type="xsd:string"
+                             minOccurs="1" maxOccurs="1"/>
                 <xsd:element name="mbeans">
                     <xsd:complexType>
                         <xsd:sequence>

Modified: geronimo/server/trunk/plugins/monitoring/agent-jmx/src/main/java/org/apache/geronimo/monitoring/jmx/MasterRemoteControlJMX.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/monitoring/agent-jmx/src/main/java/org/apache/geronimo/monitoring/jmx/MasterRemoteControlJMX.java?rev=1156009&r1=1156008&r2=1156009&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/monitoring/agent-jmx/src/main/java/org/apache/geronimo/monitoring/jmx/MasterRemoteControlJMX.java (original)
+++ geronimo/server/trunk/plugins/monitoring/agent-jmx/src/main/java/org/apache/geronimo/monitoring/jmx/MasterRemoteControlJMX.java Wed Aug 10 03:28:37 2011
@@ -154,9 +154,17 @@ public class MasterRemoteControlJMX impl
     }
     
     /**
-     * Stops the snapshot thread
+     * Stops the snapshot thread and save the started status
      */
     public boolean stopSnapshot() {
+        setSnapshotStarted(false);
+        return stopSnapshotThread();
+    }
+    
+    /**
+     * Stops the snapshot thread
+     */
+    private boolean stopSnapshotThread() {
         if(snapshotThread != null) {
             if(snapshotThread.getSnapshotDuration() != Long.MAX_VALUE) {
                 saveDuration(snapshotThread.getSnapshotDuration());
@@ -242,6 +250,10 @@ public class MasterRemoteControlJMX impl
         saveRetention(retention.intValue());
     }
     
+    public void setSnapshotStarted(Boolean started) {
+        saveStarted(started.booleanValue());
+    }
+    
     /**
     * Begins the snapshot process given the time interval between snapshots
      *
@@ -251,6 +263,7 @@ public class MasterRemoteControlJMX impl
      * @param interval
      */
     public boolean startSnapshot(Long interval) {
+        setSnapshotStarted(true);
         // get the saved/default retention period
         String retentionStr = null;
         try {
@@ -331,7 +344,23 @@ public class MasterRemoteControlJMX impl
      * Executes when the GBean starts up. Also starts the snapshot thread.
      */
     public void doStart() {
-    
+        boolean started = false;
+        try {
+            started = Boolean.parseBoolean(
+                    SnapshotConfigXMLBuilder.getAttributeValue(MonitorConstants.STARTED));
+        } catch (Exception e) {
+            log.warn("Failed to parse 'started', set to default value " + started, e);            
+        }
+        if (started) {
+            long duration = MonitorConstants.DEFAULT_DURATION;
+            try {
+                duration = Long.parseLong(
+                        SnapshotConfigXMLBuilder.getAttributeValue(MonitorConstants.DURATION));
+            } catch (Exception e) {
+                log.warn("Failed to parse 'duration', set to default value " + duration, e);
+            }
+            startSnapshot(duration);
+        }
     }
     
     /**
@@ -339,7 +368,7 @@ public class MasterRemoteControlJMX impl
      */
     public void doStop() {
         if(SnapshotStatus() == 1) {
-            stopSnapshot();
+            stopSnapshotThread();
         }
     }
     
@@ -351,6 +380,10 @@ public class MasterRemoteControlJMX impl
         SnapshotConfigXMLBuilder.saveRetention(retention);
     }
     
+    private void saveStarted(boolean started) {
+        SnapshotConfigXMLBuilder.saveStarted(started);
+    }
+    
     /**
      * 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