changeset 1664:2535bda2cd98 1.4-branchpoint

Show progress/busy-waiting when performing heap dump Addresses PR2168 Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-January/012485.html
author Jie Kang <jkang@redhat.com>
date Wed, 04 Feb 2015 16:13:22 -0500
parents ec94647ae5a0
children 0a7e2edb2894
files client/core/src/main/java/com/redhat/thermostat/client/core/progress/ProgressHandle.java vm-heap-analysis/client-core/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/core/internal/HeapDumpController.java vm-heap-analysis/client-core/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/locale/LocaleResources.java
diffstat 3 files changed, 45 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/client/core/src/main/java/com/redhat/thermostat/client/core/progress/ProgressHandle.java	Wed Feb 04 15:52:17 2015 -0500
+++ b/client/core/src/main/java/com/redhat/thermostat/client/core/progress/ProgressHandle.java	Wed Feb 04 16:13:22 2015 -0500
@@ -170,6 +170,15 @@
         notifier.fireAction(Status.STOPPED);
     }
 
+    public void runTask(Runnable task) {
+        try {
+            this.start();
+            task.run();
+        } finally {
+            this.stop();
+        }
+    }
+
     public void addProgressListener(ActionListener<ProgressHandle.Status> listener) {
         notifier.addActionListener(listener);
     }
--- a/vm-heap-analysis/client-core/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/core/internal/HeapDumpController.java	Wed Feb 04 15:52:17 2015 -0500
+++ b/vm-heap-analysis/client-core/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/core/internal/HeapDumpController.java	Wed Feb 04 16:13:22 2015 -0500
@@ -245,7 +245,6 @@
         appService.getApplicationExecutor().execute(new Runnable() {
             @Override
             public void run() {
-
                 LocalizedString taskName = translator.localize(LocaleResources.HEAP_DUMP_IN_PROGRESS);
                 
                 final ProgressHandle handle = new ProgressHandle(taskName);
@@ -253,26 +252,28 @@
                 handle.setIndeterminate(true);
                 notifier.register(handle);
 
-                HeapDump dump = localHeapDump.getDump();
-                File file = localHeapDump.getFile();
+                final HeapDump dump = localHeapDump.getDump();
+                final File file = localHeapDump.getFile();
                 if (dump == null || file == null) {
                     // this is here mainly for the tests, since we don't
                     // expect files or dumps to be null
                     return;
                 }
                 
-                handle.start();
-                try (InputStream in = heapDAO.getHeapDumpData(dump.getInfo())) {
-                    Files.copy(in, file.toPath());
-                    
-                } catch (IOException e) {
-                    LocalizedString message = translator.localize(LocaleResources.ERROR_EXPORTING_FILE);
-                    view.displayWarning(message);
-                    Logger.getLogger(HeapDumpController.class.getSimpleName()).
-                        log(Level.WARNING, message.getContents(), e);
-                } finally {
-                    handle.stop();
-                }
+                handle.runTask(new Runnable() {
+                    @Override
+                    public void run() {
+                        try (InputStream in = heapDAO.getHeapDumpData(dump.getInfo())) {
+                            Files.copy(in, file.toPath());
+
+                        } catch (IOException e) {
+                            LocalizedString message = translator.localize(LocaleResources.ERROR_EXPORTING_FILE);
+                            view.displayWarning(message);
+                            Logger.getLogger(HeapDumpController.class.getSimpleName()).
+                                    log(Level.WARNING, message.getContents(), e);
+                        }
+                    }
+                });
             }
         });
     }
@@ -294,16 +295,27 @@
     
     private void requestDump(final HeapDumper heapDumper) {
         appService.getApplicationExecutor().execute(new Runnable() {
-            
             @Override
             public void run() {
-                try {
-                    heapDumper.dump();
-                    view.enableHeapDumping();
-                    view.notifyHeapDumpComplete();
-                } catch (CommandException e) {
-                    view.displayWarning(e.getTranslatedMessage());
-                }
+                LocalizedString taskName = translator.localize(LocaleResources.HEAP_DUMP_IN_PROGRESS);
+
+                final ProgressHandle handle = new ProgressHandle(taskName);
+                handle.setTask(taskName);
+                handle.setIndeterminate(true);
+                notifier.register(handle);
+
+                handle.runTask(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            heapDumper.dump();
+                            view.enableHeapDumping();
+                            view.notifyHeapDumpComplete();
+                        } catch (CommandException e) {
+                            view.displayWarning(e.getTranslatedMessage());
+                        }
+                    }
+                });
             }
         });
     }
--- a/vm-heap-analysis/client-core/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/locale/LocaleResources.java	Wed Feb 04 15:52:17 2015 -0500
+++ b/vm-heap-analysis/client-core/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/locale/LocaleResources.java	Wed Feb 04 16:13:22 2015 -0500
@@ -77,7 +77,7 @@
     
     DUMPS_LIST,
     LIST_DUMPS_ACTION,
-    
+
     ;
 
     static final String RESOURCE_BUNDLE = "com.redhat.thermostat.vm.heap.analysis.client.locale.strings";