geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akulshresh...@apache.org
Subject svn commit: r583346 - in /geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor: MasterRemoteControl.java SMP.java snapshot/SnapshotThread.java
Date Wed, 10 Oct 2007 02:50:13 GMT
Author: akulshreshtha
Date: Tue Oct  9 19:50:12 2007
New Revision: 583346

URL: http://svn.apache.org/viewvc?rev=583346&view=rev
Log:
GERONIMO-3524 Monitoring Server Patch by Viet H. Nguyen

Modified:
    geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/MasterRemoteControl.java
    geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/SMP.java
    geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotThread.java

Modified: geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/MasterRemoteControl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/MasterRemoteControl.java?rev=583346&r1=583345&r2=583346&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/MasterRemoteControl.java
(original)
+++ geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/MasterRemoteControl.java
Tue Oct  9 19:50:12 2007
@@ -171,31 +171,36 @@
      * 
      * @param interval
      */
-    public void startSnapshot(Long interval) /*throws Exception*/ {
+    public boolean startSnapshot(Long interval) {
         if((snapshotThread == null || (snapshotThread != null && !snapshotThread.isAlive()))
&&
                 interval.longValue() > 0) {
             saveDuration(interval.longValue());
             snapshotThread = new SnapshotThread(interval.longValue(), mbServer);
             snapshotThread.start();
+            return true;
         } else {
-            //throw new Exception("There is already a snapshot thread running.");
+            System.out.println("There is already a snapshot thread running; Duration: " +
interval.longValue());
+            return false;
         }
     }
     
     /**
      * Stops the snapshot thread
      */
-    public void stopSnapshot() {
+    public boolean stopSnapshot() {
         if(snapshotThread != null) {
             if(snapshotThread.getSnapshotDuration() == Long.MAX_VALUE) {
                 saveDuration(DEFAULT_DURATION);
             } else {
                 saveDuration(snapshotThread.getSnapshotDuration());
             }
-            snapshotThread.setSnapshotDuration(Long.MAX_VALUE);
+            snapshotThread.setEnd();
+            snapshotThread.interrupt();
+            return true;
         } else {
             System.out.println("There is not a snapshot thread running. Stopping aborted.");
             //log.error("There is not a snapshot thread running. Stopping aborted.");
+            return false;
         }
     }
     
@@ -370,8 +375,8 @@
         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("MasterRemoteControl",
MasterRemoteControl.class);
         infoFactory.addOperation("getStats", new Class[] {String.class}, "HashMap");
         infoFactory.addOperation("setAttribute", new Class[] {String.class, String.class,
Object.class}, "void");
-        infoFactory.addOperation("startSnapshot", new Class[] {Long.class}, "void");
-        infoFactory.addOperation("stopSnapshot", new Class[] {}, "void");
+        infoFactory.addOperation("startSnapshot", new Class[] {Long.class}, "boolean");
+        infoFactory.addOperation("stopSnapshot", new Class[] {}, "boolean");
         infoFactory.addOperation("fetchSnapshotData", new Class[] {Integer.class, Integer.class},
"ArrayList");
         infoFactory.addOperation("fetchMaxSnapshotData", new Class[] {Integer.class}, "HashMap");
         infoFactory.addOperation("fetchMinSnapshotData", new Class[] {Integer.class}, "HashMap");

Modified: geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/SMP.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/SMP.java?rev=583346&r1=583345&r2=583346&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/SMP.java
(original)
+++ geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/SMP.java
Tue Oct  9 19:50:12 2007
@@ -67,8 +67,11 @@
                 System.out.println(e.getMessage());
             }
             */
-//            testSnapshotThread(mbServerConn, 5000);
-//            testSnapshotThreadStop(mbServerConn);
+            testSnapshotThreadStop(mbServerConn);
+            System.out.println("Stopped");
+            Thread.sleep(1000);
+            testSnapshotThread(mbServerConn, 5000);
+            System.out.println("Started");
 //            testFetchingSnapshot(mbServerConn, new Integer(10), new Integer(3));
 //            testFetchingMaxSnapshot(mbServerConn, new Integer(1000));
 //            testFetchingMinSnapshot(mbServerConn, new Integer(1000));
@@ -79,8 +82,8 @@
 //            testAddMBeanToSnapshot(mbServerConn);
 //            testGetMBeans(mbServerConn);
 //            testSetSnapshotDuration(mbServerConn, new Long(60000));
-            testRemoveMBeanToSnapshot(mbServerConn);
-            testGetStatsAttr(mbServerConn);
+//            testRemoveMBeanToSnapshot(mbServerConn);
+//            testGetStatsAttr(mbServerConn);
             
         } catch (Exception e) {
             e.printStackTrace();

Modified: geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotThread.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotThread.java?rev=583346&r1=583345&r2=583346&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotThread.java
(original)
+++ geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotThread.java
Tue Oct  9 19:50:12 2007
@@ -42,6 +42,8 @@
     // list of mbean names that we will be taking snapshots of
     private ArrayList<String> mbeanNames;
     
+    private boolean end = false;
+    
     public SnapshotThread(long snapshot_length, MBeanServer mbServer) {
         SNAPSHOT_DURATION = snapshot_length;
         this.mbServer = mbServer;
@@ -51,6 +53,14 @@
     }
     
     /**
+     * Set the 'end' flag to true, which will break the while loop inside run()
+     * essentially ending the thread.
+     */
+    public void setEnd() {
+        end = true;
+    }
+    
+    /**
      * Gets the elapsed time in milliseconds between each snapshot.
      * 
      * @return long
@@ -98,7 +108,8 @@
         // turn on all stats in the list
         setStatsOn(mbeanNames);
         // pause the thread from running every SNAPSHOT_DURATION seconds
-        while(true && SNAPSHOT_DURATION != Long.MAX_VALUE) {
+        // until something flips the flag to end this thread
+        while( !end ) {
             try {
                 // take a snapshot
                 System.out.println("======SNAPSHOT======");
@@ -133,6 +144,7 @@
                 e.printStackTrace();
             }
         }
+        System.out.println("Thread is stopped.");
     }
     
     /**



Mime
View raw message