Mercurial > hg > release > thermostat-1.6
changeset 1732:28d1691c7203
Show progress when checking for deadlocks
PR 2590
Reviewed-by: aazores, jerboaa
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-August/015083.html
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-August/015409.html
line wrap: on
line diff
--- a/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/LocaleResources.java Tue Aug 11 17:42:58 2015 -0400 +++ b/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/LocaleResources.java Wed Aug 12 20:06:57 2015 -0400 @@ -45,6 +45,7 @@ WARNING_CANNOT_DISABLE, WARNING_CANNOT_ENABLE, + CHECKING_FOR_DEADLOCKS, NO_DEADLOCK_DETECTED, ;
--- a/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationController.java Tue Aug 11 17:42:58 2015 -0400 +++ b/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationController.java Wed Aug 12 20:06:57 2015 -0400 @@ -37,6 +37,7 @@ package com.redhat.thermostat.thread.client.controller.impl; import com.redhat.thermostat.client.core.controllers.InformationServiceController; +import com.redhat.thermostat.client.core.progress.ProgressNotifier; import com.redhat.thermostat.client.core.views.UIComponent; import com.redhat.thermostat.common.ActionEvent; import com.redhat.thermostat.common.ActionListener; @@ -68,12 +69,16 @@ private ApplicationService appService; + private ProgressNotifier notifier; + public ThreadInformationController(VmRef ref, ApplicationService appService, VmInfoDAO vmInfoDao, ThreadCollectorFactory collectorFactory, - ThreadViewProvider viewFactory) + ThreadViewProvider viewFactory, + ProgressNotifier notifier) { this.appService = appService; + this.notifier = notifier; view = viewFactory.createView(); view.setApplicationService(appService, ref.getVmId() + "-" + ref.getHostRef().getAgentId()); @@ -147,7 +152,8 @@ TimerFactory tf = appService.getTimerFactory(); VmDeadLockController deadLockController = - new VmDeadLockController(view.createDeadLockView(), collector, tf.createTimer()); + new VmDeadLockController(view.createDeadLockView(), collector, tf.createTimer(), + appService.getApplicationExecutor(), notifier); deadLockController.initialize(); ThreadTableView threadTableView = view.createThreadTableView();
--- a/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationServiceImpl.java Tue Aug 11 17:42:58 2015 -0400 +++ b/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationServiceImpl.java Wed Aug 12 20:06:57 2015 -0400 @@ -38,6 +38,7 @@ import com.redhat.thermostat.client.core.NameMatchingRefFilter; import com.redhat.thermostat.client.core.controllers.InformationServiceController; +import com.redhat.thermostat.client.core.progress.ProgressNotifier; import com.redhat.thermostat.common.ApplicationService; import com.redhat.thermostat.common.Filter; import com.redhat.thermostat.storage.core.VmRef; @@ -55,16 +56,18 @@ private VmInfoDAO vmInfoDao; private ThreadCollectorFactory collectorFactory; private ThreadViewProvider viewFactory; + private ProgressNotifier notifier; public ThreadInformationServiceImpl(ApplicationService appService, VmInfoDAO vmInfoDao, ThreadCollectorFactory collectorFactory, - ThreadViewProvider viewFactory) + ThreadViewProvider viewFactory, ProgressNotifier notifier) { this.service = appService; this.vmInfoDao = vmInfoDao; this.collectorFactory = collectorFactory; this.viewFactory = viewFactory; + this.notifier = notifier; } @Override @@ -75,7 +78,7 @@ @Override public InformationServiceController<VmRef> getInformationServiceController(VmRef ref) { return new ThreadInformationController(ref, service, vmInfoDao, - collectorFactory, viewFactory); + collectorFactory, viewFactory, notifier); } @Override
--- a/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/VmDeadLockController.java Tue Aug 11 17:42:58 2015 -0400 +++ b/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/impl/VmDeadLockController.java Wed Aug 12 20:06:57 2015 -0400 @@ -39,14 +39,19 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; +import java.util.Objects; +import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import com.redhat.thermostat.client.core.progress.ProgressHandle; +import com.redhat.thermostat.client.core.progress.ProgressNotifier; import com.redhat.thermostat.client.core.views.BasicView.Action; import com.redhat.thermostat.common.ActionEvent; import com.redhat.thermostat.common.ActionListener; import com.redhat.thermostat.common.Timer; import com.redhat.thermostat.common.Timer.SchedulingType; +import com.redhat.thermostat.shared.locale.LocalizedString; import com.redhat.thermostat.shared.locale.Translate; import com.redhat.thermostat.thread.client.common.DeadlockParser; import com.redhat.thermostat.thread.client.common.DeadlockParser.Information; @@ -65,14 +70,20 @@ private VmDeadLockView view; private ThreadCollector collector; private Timer timer; + private ExecutorService executor; + private ProgressNotifier notifier; private final AtomicReference<String> descriptionRef = new AtomicReference<>(""); private String previousDeadlockData = null; - public VmDeadLockController(VmDeadLockView view, ThreadCollector collector, Timer timer) { + + public VmDeadLockController(VmDeadLockView view, ThreadCollector collector, Timer timer, + ExecutorService executor, ProgressNotifier notifier) { this.view = view; this.collector = collector; this.timer = timer; + this.executor = executor; + this.notifier = Objects.requireNonNull(notifier); } public void initialize() { @@ -81,8 +92,24 @@ public void actionPerformed(ActionEvent<VmDeadLockViewAction> actionEvent) { switch (actionEvent.getActionId()) { case CHECK_FOR_DEADLOCK: - checkForDeadLock(); - updateViewIfNeeded(); + executor.execute(new Runnable() { + @Override + public void run() { + LocalizedString message = translate.localize(LocaleResources.CHECKING_FOR_DEADLOCKS); + ProgressHandle handle = new ProgressHandle(message); + handle.setIndeterminate(true); + + notifier.register(handle); + + handle.start(); + try { + checkForDeadLock(); + updateViewIfNeeded(); + } finally { + handle.stop(); + } + } + }); break; default: break;
--- a/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/osgi/Activator.java Tue Aug 11 17:42:58 2015 -0400 +++ b/thread/client-controllers/src/main/java/com/redhat/thermostat/thread/client/controller/osgi/Activator.java Wed Aug 12 20:06:57 2015 -0400 @@ -37,6 +37,7 @@ package com.redhat.thermostat.thread.client.controller.osgi; import com.redhat.thermostat.client.core.InformationService; +import com.redhat.thermostat.client.core.progress.ProgressNotifier; import com.redhat.thermostat.common.ApplicationService; import com.redhat.thermostat.common.Constants; import com.redhat.thermostat.common.MultipleServiceTracker; @@ -47,10 +48,12 @@ import com.redhat.thermostat.thread.client.common.collector.ThreadCollectorFactory; import com.redhat.thermostat.thread.client.controller.ThreadInformationService; import com.redhat.thermostat.thread.client.controller.impl.ThreadInformationServiceImpl; + import java.util.Dictionary; import java.util.Hashtable; import java.util.Map; import java.util.Objects; + import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; @@ -66,6 +69,7 @@ ApplicationService.class, VmInfoDAO.class, ThreadViewProvider.class, + ProgressNotifier.class, }; Action action = new Action() { @@ -78,12 +82,14 @@ ApplicationService applicationService = (ApplicationService) services.get(ApplicationService.class.getName()); VmInfoDAO vmInfoDao = Objects.requireNonNull((VmInfoDAO) services.get(VmInfoDAO.class.getName())); ThreadViewProvider viewFactory = (ThreadViewProvider) services.get(ThreadViewProvider.class.getName()); + ProgressNotifier notifier = (ProgressNotifier) services.get(ProgressNotifier.class.getName()); ThreadInformationService vmInfoService = new ThreadInformationServiceImpl(applicationService, vmInfoDao, collectorFactory, - viewFactory); + viewFactory, + notifier); Dictionary<String, String> properties = new Hashtable<>(); properties.put(Constants.GENERIC_SERVICE_CLASSNAME, VmRef.class.getName());
--- a/thread/client-controllers/src/main/resources/com/redhat/thermostat/thread/client/controller/impl/strings.properties Tue Aug 11 17:42:58 2015 -0400 +++ b/thread/client-controllers/src/main/resources/com/redhat/thermostat/thread/client/controller/impl/strings.properties Wed Aug 12 20:06:57 2015 -0400 @@ -1,4 +1,5 @@ CONTROLLER_NAME = Threads WARNING_CANNOT_ENABLE = Cannot enable Thread recording WARNING_CANNOT_DISABLE = Cannot disable Thread recording +CHECKING_FOR_DEADLOCKS = Checking for deadlocks... NO_DEADLOCK_DETECTED = No Deadlocks Detected. \ No newline at end of file
--- a/thread/client-controllers/src/test/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationControllerTest.java Tue Aug 11 17:42:58 2015 -0400 +++ b/thread/client-controllers/src/test/java/com/redhat/thermostat/thread/client/controller/impl/ThreadInformationControllerTest.java Wed Aug 12 20:06:57 2015 -0400 @@ -36,6 +36,7 @@ package com.redhat.thermostat.thread.client.controller.impl; +import com.redhat.thermostat.client.core.progress.ProgressNotifier; import com.redhat.thermostat.common.ActionEvent; import com.redhat.thermostat.common.ActionListener; import com.redhat.thermostat.common.ApplicationCache; @@ -56,6 +57,7 @@ import com.redhat.thermostat.thread.client.common.view.ThreadTimelineView; import com.redhat.thermostat.thread.client.common.view.ThreadView; import com.redhat.thermostat.thread.client.common.view.VmDeadLockView; + import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -147,9 +149,11 @@ ThreadCollector collector = mock(ThreadCollector.class); when(collectorFactory.getCollector(ref)).thenReturn(collector); + ProgressNotifier notifier = mock(ProgressNotifier.class); + controller = new ThreadInformationController(ref, appService, vmInfoDao, collectorFactory, - viewFactory); + viewFactory, notifier); } @Test @@ -187,9 +191,11 @@ ApplicationCache cache = mock(ApplicationCache.class); when(appService.getApplicationCache()).thenReturn(cache); + ProgressNotifier notifier = mock(ProgressNotifier.class); + controller = new ThreadInformationController(ref, appService, vmInfoDao, collectorFactory, - viewFactory); + viewFactory, notifier); verify(collector).isHarvesterCollecting(); verify(view, times(1)).setRecording(false, false);
--- a/thread/client-controllers/src/test/java/com/redhat/thermostat/thread/client/controller/impl/VmDeadLockControllerTest.java Tue Aug 11 17:42:58 2015 -0400 +++ b/thread/client-controllers/src/test/java/com/redhat/thermostat/thread/client/controller/impl/VmDeadLockControllerTest.java Wed Aug 12 20:06:57 2015 -0400 @@ -38,6 +38,7 @@ import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -45,12 +46,15 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; +import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; +import com.redhat.thermostat.client.core.progress.ProgressHandle; +import com.redhat.thermostat.client.core.progress.ProgressNotifier; import com.redhat.thermostat.client.core.views.BasicView; import com.redhat.thermostat.client.core.views.BasicView.Action; import com.redhat.thermostat.common.ActionEvent; @@ -67,6 +71,8 @@ private Timer timer; private VmDeadLockView view; private ThreadCollector collector; + private ExecutorService executor; + private ProgressNotifier notifier; private VmDeadLockController controller; @@ -78,7 +84,11 @@ collector = mock(ThreadCollector.class); - controller = new VmDeadLockController(view, collector, timer); + executor = mock(ExecutorService.class); + + notifier = mock(ProgressNotifier.class); + + controller = new VmDeadLockController(view, collector, timer, executor, notifier); } @Test @@ -94,6 +104,9 @@ VmDeadLockData data = new VmDeadLockData("foo-agent"); data.setDeadLockDescription(DESCRIPTION); + ArgumentCaptor<Runnable> executionCaptor = ArgumentCaptor.forClass(Runnable.class); + doNothing().when(executor).execute(executionCaptor.capture()); + controller.initialize(); ArgumentCaptor<ActionListener> listenerCaptor = (ArgumentCaptor<ActionListener>) ArgumentCaptor.forClass(ActionListener.class); @@ -105,6 +118,9 @@ listener.actionPerformed(new ActionEvent<VmDeadLockViewAction>(view, VmDeadLockViewAction.CHECK_FOR_DEADLOCK)); + Runnable deferredTask = executionCaptor.getValue(); + deferredTask.run(); + verify(collector).requestDeadLockCheck(); verify(view).setDeadLockInformation(null, DESCRIPTION); } @@ -114,6 +130,9 @@ VmDeadLockData data = new VmDeadLockData("foo-agent"); data.setDeadLockDescription(VmDeadLockData.NO_DEADLOCK); + ArgumentCaptor<Runnable> executionCaptor = ArgumentCaptor.forClass(Runnable.class); + doNothing().when(executor).execute(executionCaptor.capture()); + controller.initialize(); ArgumentCaptor<ActionListener> listenerCaptor = (ArgumentCaptor<ActionListener>) ArgumentCaptor.forClass(ActionListener.class); @@ -125,6 +144,9 @@ listener.actionPerformed(new ActionEvent<VmDeadLockViewAction>(view, VmDeadLockViewAction.CHECK_FOR_DEADLOCK)); + Runnable deferredTask = executionCaptor.getValue(); + deferredTask.run(); + verify(collector).requestDeadLockCheck(); verify(view).setDeadLockInformation(null, "No Deadlocks Detected."); }