changeset 1638:461cef9a84c4

Remove locking and implement fail fast for thread monitor review-thread: http://icedtea.classpath.org/pipermail/thermostat/2014-December/012285.html reviewed-by: jerboaa
author Mario Torre <neugens.limasoftware@gmail.com>
date Mon, 15 Dec 2014 13:23:01 +0100
parents c9f9c00e3cbb
children 4bea04866e8e
files thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadTableController.java thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadTimelineController.java thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/timeline/RangeComponent.java
diffstat 3 files changed, 61 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadTableController.java	Mon Dec 15 13:23:00 2014 +0100
+++ b/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadTableController.java	Mon Dec 15 13:23:01 2014 +0100
@@ -54,6 +54,8 @@
     private ThreadTableView threadTableView;
     private ThreadCollector collector;
 
+    private volatile boolean stopLooping;
+
     public ThreadTableController(ThreadTableView threadTableView,
                                  ThreadCollector collector,
                                  Timer timer)
@@ -64,6 +66,16 @@
         timer.setAction(new ThreadTableControllerAction());
     }
 
+    @Override
+    protected void onViewVisible() {
+        stopLooping = false;
+    }
+
+    @Override
+    protected void onViewHidden() {
+        stopLooping = true;
+    }
+
     private class ThreadTableControllerAction implements Runnable {
 
         private ThreadResultHandler handler;
@@ -93,8 +105,8 @@
             }
             if (lastSession == null ||
                     !session.get().equals(lastSession.get())) {
-                // since we only visualise one sessions at a time and this
-                // is a new session needs, let's clear the view
+                // since we only visualise one session at a time and this is
+                // a new session, let's clear the view
                 resetState();
             }
             lastSession = session;
@@ -166,7 +178,8 @@
 
             threadTableView.display(bean);
 
-            return true;
+            boolean _stopLooping = stopLooping;
+            return !_stopLooping;
         }
     }
 
--- a/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadTimelineController.java	Mon Dec 15 13:23:00 2014 +0100
+++ b/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadTimelineController.java	Mon Dec 15 13:23:01 2014 +0100
@@ -57,9 +57,7 @@
     private ThreadTimelineView view;
     private ThreadCollector collector;
 
-    private static final String lock = new String("ThreadTimelineController");
-
-    private boolean requestClear;
+    private volatile boolean stopLooping;
 
     public ThreadTimelineController(ThreadTimelineView view,
                                     ThreadCollector collector,
@@ -95,46 +93,52 @@
 
         @Override
         public void run() {
-
-            synchronized (lock) {
+            // FIXME: show only the last sessions for now, support for
+            // filtering over sessions will come later
+            SessionID session = collector.getLastThreadSession();
+            if (session == null) {
+                // ok, no data, let's skip this round
+                return;
+            }
 
-                // FIXME: show only the last sessions for now, support for
-                // filtering over sessions will come later
-                SessionID session = collector.getLastThreadSession();
-                if (session == null) {
-                    // ok, no data, let's skip this round
-                    return;
-                }
-
-                if (lastSession == null ||
-                    !session.get().equals(lastSession.get()))
-                {
-                    // since we only visualise one sessions at a time and this
-                    // is a new session needs, let's clear the view
-                    resetState();
-                }
-                lastSession = session;
+            if (lastSession == null ||
+                !session.get().equals(lastSession.get()))
+            {
+                // since we only visualise one session at a time and this is
+                // a new session, let's clear the view
+                resetState();
+            }
+            lastSession = session;
 
-                // get the full range of known timelines per vm
-                Range<Long> totalRange = collector.getThreadRange(session);
-                if (totalRange == null) {
-                    // this just means we don't have any data yet
-                    return;
-                }
+            // get the full range of known timelines per vm
+            Range<Long> totalRange = collector.getThreadRange(session);
+            if (totalRange == null) {
+                // this just means we don't have any data yet
+                return;
+            }
+
+            if (!totalRange.equals(lastRange)) {
+                view.setTotalRange(totalRange);
+            }
+            lastRange = totalRange;
+
+            range = new Range<>(lastUpdate, totalRange.getMax());
+            lastUpdate = totalRange.getMax();
 
-                if (!totalRange.equals(lastRange)) {
-                    view.setTotalRange(totalRange);
-                }
-                lastRange = totalRange;
+            collector.getThreadStates(session,
+                                      threadStateResultHandler,
+                                      range);
+        }
+    }
 
-                range = new Range<>(lastUpdate, totalRange.getMax());
-                lastUpdate = totalRange.getMax();
+    @Override
+    protected void onViewVisible() {
+        stopLooping = false;
+    }
 
-                collector.getThreadStates(session,
-                                          threadStateResultHandler,
-                                          range);
-            }
-        }
+    @Override
+    protected void onViewHidden() {
+        stopLooping = true;
     }
 
     private class ThreadStateResultHandler implements ResultHandler<ThreadState> {
@@ -161,7 +165,8 @@
             TimelineProbe probe = TimelineFactory.createTimelineProbe(state);
             view.addProbe(info, probe);
 
-            return true;
+            boolean _stopLooping = stopLooping;
+            return !_stopLooping;
         }
     }
 }
--- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/timeline/RangeComponent.java	Mon Dec 15 13:23:00 2014 +0100
+++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/timeline/RangeComponent.java	Mon Dec 15 13:23:01 2014 +0100
@@ -49,6 +49,7 @@
 
     public RangeComponent(RangedTimelineProbe info) {
         this.info = info;
+        setOpaque(false);
     }
 
     public RangedTimelineProbe getInfo() {