Mercurial > hg > release > thermostat-1.6
changeset 1745:0e4c60a50547
Show progress while enabling or disabling the profiler
PR 2608
Reviewed-by: jerboaa, neugens
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-March/013414.html
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-September/015755.html
line wrap: on
line diff
--- a/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/Activator.java Wed Sep 02 17:54:51 2015 +0200 +++ b/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/Activator.java Thu Sep 03 12:12:17 2015 -0400 @@ -45,6 +45,7 @@ import com.redhat.thermostat.client.command.RequestQueue; 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; @@ -63,6 +64,7 @@ Class<?>[] deps = new Class<?>[] { ApplicationService.class, + ProgressNotifier.class, AgentInfoDAO.class, VmInfoDAO.class, ProfileDAO.class, @@ -73,12 +75,13 @@ @Override public void dependenciesAvailable(Map<String, Object> services) { ApplicationService service = (ApplicationService) services.get(ApplicationService.class.getName()); + ProgressNotifier notifier = (ProgressNotifier) services.get(ProgressNotifier.class.getName()); AgentInfoDAO agentInfoDao = (AgentInfoDAO) services.get(AgentInfoDAO.class.getName()); VmInfoDAO vmInfoDao = (VmInfoDAO) services.get(VmInfoDAO.class.getName()); ProfileDAO profileDao = (ProfileDAO) services.get(ProfileDAO.class.getName()); RequestQueue queue = (RequestQueue) services.get(RequestQueue.class.getName()); - InformationService<VmRef> profileService = new VmProfileService(service, agentInfoDao, vmInfoDao, profileDao, queue); + InformationService<VmRef> profileService = new VmProfileService(service, notifier, agentInfoDao, vmInfoDao, profileDao, queue); Hashtable<String,String> properties = new Hashtable<>(); properties.put(Constants.GENERIC_SERVICE_CLASSNAME, VmRef.class.getName());
--- a/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/LocaleResources.java Wed Sep 02 17:54:51 2015 +0200 +++ b/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/LocaleResources.java Thu Sep 03 12:12:17 2015 -0400 @@ -48,7 +48,9 @@ PROFILER_CURRENT_STATUS_ACTIVE, PROFILER_CURRENT_STATUS_INACTIVE, START_PROFILING, + STARTING_PROFILING, STOP_PROFILING, + STOPPING_PROFILING, PROFILER_LIST_ITEM, PROFILER_RESULTS_METHOD,
--- a/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileController.java Wed Sep 02 17:54:51 2015 +0200 +++ b/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileController.java Thu Sep 03 12:12:17 2015 -0400 @@ -46,6 +46,8 @@ import com.redhat.thermostat.client.command.RequestQueue; import com.redhat.thermostat.client.core.controllers.InformationServiceController; +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.client.core.views.UIComponent; @@ -81,12 +83,13 @@ private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); - private ApplicationService service; - private ProfileDAO profileDao; - private AgentInfoDAO agentInfoDao; - private VmInfoDAO vmInfoDao; - private RequestQueue queue; - private VmRef vm; + private final ApplicationService service; + private final ProgressNotifier notifier; + private final ProfileDAO profileDao; + private final AgentInfoDAO agentInfoDao; + private final VmInfoDAO vmInfoDao; + private final RequestQueue queue; + private final VmRef vm; private VmProfileView view; @@ -98,18 +101,22 @@ private ProfileStatusChange previousStatus; - public VmProfileController(ApplicationService service, + private ProgressHandle progressDisplay; + + + public VmProfileController(ApplicationService service, ProgressNotifier notifier, AgentInfoDAO agentInfoDao, VmInfoDAO vmInfoDao, ProfileDAO dao, RequestQueue queue, VmRef vm) { - this(service, agentInfoDao, vmInfoDao, dao, queue, new SystemClock(), new SwingVmProfileView(), vm); + this(service, notifier, agentInfoDao, vmInfoDao, dao, queue, new SystemClock(), new SwingVmProfileView(), vm); } - VmProfileController(ApplicationService service, + VmProfileController(ApplicationService service, ProgressNotifier notifier, AgentInfoDAO agentInfoDao, VmInfoDAO vmInfoDao, ProfileDAO dao, RequestQueue queue, Clock clock, final VmProfileView view, VmRef vm) { this.service = service; + this.notifier = notifier; this.agentInfoDao = agentInfoDao; this.vmInfoDao = vmInfoDao; this.profileDao = dao; @@ -139,6 +146,7 @@ switch (actionEvent.getActionId()) { case HIDDEN: updater.stop(); + hideProgressNotificationIfVisible(); break; case VISIBLE: updater.start(); @@ -169,6 +177,7 @@ } }); + } private void startProfiling(final VmProfileView view) { @@ -180,10 +189,9 @@ } private void disableViewControlsAndSendRequest(VmProfileView view, boolean start) { + showProgressNotification(start); // disable the UI until we get a update in storage - view.enableStartProfiling(false); - view.enableStopProfiling(false); - + disableViewControls(); sendProfilingRequest(start); } @@ -201,6 +209,7 @@ default: // FIXME show message to user + hideProgressNotificationIfVisible(); profilingStartOrStopRequested = false; break; } @@ -226,30 +235,53 @@ } if (!isAlive()) { - view.enableStartProfiling(false); - view.enableStopProfiling(false); + disableViewControls(); view.setProfilingStatus(message, currentlyActive); } else if (profilingStartOrStopRequested) { boolean statusChanged = (previousStatus == null && currentStatus != null) || (currentStatus != null && !(currentStatus.equals(previousStatus))); if (statusChanged) { - view.enableStartProfiling(!currentlyActive); - view.enableStopProfiling(currentlyActive); - + enableViewControlsFor(currentlyActive); view.setProfilingStatus(message, currentlyActive); - profilingStartOrStopRequested = false; + hideProgressNotificationIfVisible(); } } else { - view.enableStartProfiling(!currentlyActive); - view.enableStopProfiling(currentlyActive); - + enableViewControlsFor(currentlyActive); view.setProfilingStatus(message, currentlyActive); } previousStatus = currentStatus; } + private void disableViewControls() { + view.enableStartProfiling(false); + view.enableStopProfiling(false); + } + + private void enableViewControlsFor(boolean currentlyActive) { + view.enableStartProfiling(!currentlyActive); + view.enableStopProfiling(currentlyActive); + } + + private void showProgressNotification(boolean start) { + if (start) { + progressDisplay = new ProgressHandle(translator.localize(LocaleResources.STARTING_PROFILING)); + } else { + progressDisplay = new ProgressHandle(translator.localize(LocaleResources.STOPPING_PROFILING)); + } + progressDisplay.setIndeterminate(true); + notifier.register(progressDisplay); + progressDisplay.start(); + } + + private void hideProgressNotificationIfVisible() { + if (progressDisplay != null) { + progressDisplay.stop(); + progressDisplay = null; + } + } + private boolean isAlive() { HostRef agent = vm.getHostRef(); AgentInformation agentInfo = agentInfoDao.getAgentInformation(agent);
--- a/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileService.java Wed Sep 02 17:54:51 2015 +0200 +++ b/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileService.java Thu Sep 03 12:12:17 2015 -0400 @@ -39,6 +39,7 @@ import com.redhat.thermostat.client.command.RequestQueue; import com.redhat.thermostat.client.core.InformationService; import com.redhat.thermostat.client.core.controllers.InformationServiceController; +import com.redhat.thermostat.client.core.progress.ProgressNotifier; import com.redhat.thermostat.common.AllPassFilter; import com.redhat.thermostat.common.ApplicationService; import com.redhat.thermostat.common.Filter; @@ -50,13 +51,17 @@ public class VmProfileService implements InformationService<VmRef> { private ApplicationService service; + private ProgressNotifier notifier; private AgentInfoDAO agentInfoDao; private VmInfoDAO vmInfoDao; private ProfileDAO dao; private RequestQueue queue; - public VmProfileService(ApplicationService service, AgentInfoDAO agentInfoDao, VmInfoDAO vmInfoDao, ProfileDAO dao, RequestQueue queue) { + public VmProfileService(ApplicationService service, ProgressNotifier notifier, + AgentInfoDAO agentInfoDao, VmInfoDAO vmInfoDao, ProfileDAO dao, + RequestQueue queue) { this.service = service; + this.notifier = notifier; this.agentInfoDao = agentInfoDao; this.vmInfoDao = vmInfoDao; this.dao = dao; @@ -76,7 +81,7 @@ @Override public InformationServiceController<VmRef> getInformationServiceController(VmRef ref) { - return new VmProfileController(service, agentInfoDao, vmInfoDao, dao, queue, ref); + return new VmProfileController(service, notifier, agentInfoDao, vmInfoDao, dao, queue, ref); } }
--- a/vm-profiler/client-swing/src/main/resources/com/redhat/thermostat/vm/profiler/client/swing/internal/strings.properties Wed Sep 02 17:54:51 2015 +0200 +++ b/vm-profiler/client-swing/src/main/resources/com/redhat/thermostat/vm/profiler/client/swing/internal/strings.properties Thu Sep 03 12:12:17 2015 -0400 @@ -8,7 +8,9 @@ PROFILER_CURRENT_STATUS_ACTIVE = Currently profiling: yes PROFILER_CURRENT_STATUS_INACTIVE = Currently profiling: no START_PROFILING = Start Profiling +STARTING_PROFILING = Starting profiling... STOP_PROFILING = Stop Profiling +STOPPING_PROFILING = Stopping profiling... PROFILER_LIST_ITEM = Session @ {1} ({0}) PROFILER_RESULTS_METHOD = Method
--- a/vm-profiler/client-swing/src/test/java/com/redhat/thermostat/vm/profiler/client/swing/internal/ActivatorTest.java Wed Sep 02 17:54:51 2015 +0200 +++ b/vm-profiler/client-swing/src/test/java/com/redhat/thermostat/vm/profiler/client/swing/internal/ActivatorTest.java Thu Sep 03 12:12:17 2015 -0400 @@ -43,6 +43,7 @@ import com.redhat.thermostat.client.command.RequestQueue; 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.storage.dao.AgentInfoDAO; import com.redhat.thermostat.storage.dao.VmInfoDAO; @@ -58,6 +59,9 @@ ApplicationService appService = mock(ApplicationService.class); bundleContext.registerService(ApplicationService.class, appService, null); + ProgressNotifier notifier = mock(ProgressNotifier.class); + bundleContext.registerService(ProgressNotifier.class, notifier, null); + AgentInfoDAO agentInfoDao = mock(AgentInfoDAO.class); bundleContext.registerService(AgentInfoDAO.class, agentInfoDao, null);
--- a/vm-profiler/client-swing/src/test/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileControllerTest.java Wed Sep 02 17:54:51 2015 +0200 +++ b/vm-profiler/client-swing/src/test/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileControllerTest.java Thu Sep 03 12:12:17 2015 -0400 @@ -56,6 +56,7 @@ import org.mockito.ArgumentCaptor; import com.redhat.thermostat.client.command.RequestQueue; +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; @@ -94,6 +95,7 @@ private Timer timer; private ApplicationService appService; + private ProgressNotifier notifier; private AgentInfoDAO agentInfoDao; private VmInfoDAO vmInfoDao; private ProfileDAO profileDao; @@ -116,6 +118,8 @@ appService = mock(ApplicationService.class); when(appService.getTimerFactory()).thenReturn(timerFactory); + notifier = mock(ProgressNotifier.class); + agentInfoDao = mock(AgentInfoDAO.class); vmInfoDao = mock(VmInfoDAO.class); vmInfo = mock(VmInfo.class); @@ -318,7 +322,7 @@ } private VmProfileController createController() { - return new VmProfileController(appService, agentInfoDao, vmInfoDao, profileDao, queue, clock, view, vm); + return new VmProfileController(appService, notifier, agentInfoDao, vmInfoDao, profileDao, queue, clock, view, vm); } private void assertRequestEquals(Request actual, Request expected) {
--- a/vm-profiler/client-swing/src/test/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileServiceTest.java Wed Sep 02 17:54:51 2015 +0200 +++ b/vm-profiler/client-swing/src/test/java/com/redhat/thermostat/vm/profiler/client/swing/internal/VmProfileServiceTest.java Thu Sep 03 12:12:17 2015 -0400 @@ -50,7 +50,7 @@ public void worksWithDeadAndAliveVms() throws Exception { VmRef vm = mock(VmRef.class); - VmProfileService service = new VmProfileService(null, null, null, null, null); + VmProfileService service = new VmProfileService(null, null, null, null, null, null); Filter<VmRef> filter = service.getFilter(); assertTrue(filter.matches(vm));