Mercurial > hg > release > thermostat-0.6
changeset 672:161aa00723d5
Use VmMemoryStatDAO as a service
VmMemoryStatDAO is obtained either directly from the creator of
VmMemoryStatDAO or through OSGi as a service, never through
DaoFactory.
Reviewed-by: jerboaa
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-September/003491.html
line wrap: on
line diff
--- a/agent/core/src/main/java/com/redhat/thermostat/backend/system/JvmStatHostListener.java Wed Oct 03 18:05:54 2012 -0400 +++ b/agent/core/src/main/java/com/redhat/thermostat/backend/system/JvmStatHostListener.java Wed Oct 03 18:05:54 2012 -0400 @@ -61,6 +61,7 @@ import com.redhat.thermostat.agent.JvmStatusNotifier; import com.redhat.thermostat.common.dao.DAOFactory; import com.redhat.thermostat.common.dao.VmInfoDAO; +import com.redhat.thermostat.common.dao.VmMemoryStatDAO; import com.redhat.thermostat.common.model.VmInfo; import com.redhat.thermostat.common.utils.LoggingUtils; @@ -69,17 +70,20 @@ private static final Logger logger = LoggingUtils.getLogger(JvmStatHostListener.class); private boolean attachNew; + private final DAOFactory df; private final VmInfoDAO vmInfoDAO; + private final VmMemoryStatDAO vmMemoryStatDAO; private Map<Integer, MonitoredVm> monitoredVms = new HashMap<>(); private Map<MonitoredVm, List<VmListener>> registeredListeners = new ConcurrentHashMap<>(); private Set<JvmStatusListener> statusListeners = new CopyOnWriteArraySet<JvmStatusListener>(); - JvmStatHostListener(DAOFactory df, VmInfoDAO vmInfoDAO, boolean attachNew) { + JvmStatHostListener(DAOFactory df, VmInfoDAO vmInfoDAO, VmMemoryStatDAO vmMemoryStatDAO, boolean attachNew) { this.df = df; this.vmInfoDAO = vmInfoDAO; + this.vmMemoryStatDAO = vmMemoryStatDAO; this.attachNew = attachNew; } @@ -161,7 +165,7 @@ listeners = new CopyOnWriteArrayList<>(); } - VmListener listener = new JvmStatVmListener(df, vmId); + VmListener listener = new JvmStatVmListener(df, vmMemoryStatDAO, vmId); vm.addVmListener(listener); listeners.add(listener);
--- a/agent/core/src/main/java/com/redhat/thermostat/backend/system/JvmStatVmListener.java Wed Oct 03 18:05:54 2012 -0400 +++ b/agent/core/src/main/java/com/redhat/thermostat/backend/system/JvmStatVmListener.java Wed Oct 03 18:05:54 2012 -0400 @@ -64,9 +64,9 @@ private final VmGcStatDAO gcDAO; private final VmMemoryStatDAO memDAO; - public JvmStatVmListener(DAOFactory df, int vmId) { + public JvmStatVmListener(DAOFactory df, VmMemoryStatDAO vmMemoryStatDao, int vmId) { gcDAO = df.getVmGcStatDAO(); - memDAO = df.getVmMemoryStatDAO(); + memDAO = vmMemoryStatDao; this.vmId = vmId; }
--- a/agent/core/src/main/java/com/redhat/thermostat/backend/system/SystemBackend.java Wed Oct 03 18:05:54 2012 -0400 +++ b/agent/core/src/main/java/com/redhat/thermostat/backend/system/SystemBackend.java Wed Oct 03 18:05:54 2012 -0400 @@ -131,7 +131,7 @@ memoryStats = df.getMemoryStatDAO(); vmCpuStats = df.getVmCpuStatDAO(); networkInterfaces = df.getNetworkInterfaceInfoDAO(); - hostListener = new JvmStatHostListener(df, df.getVmInfoDAO(), getObserveNewJvm()); + hostListener = new JvmStatHostListener(df, df.getVmInfoDAO(), df.getVmMemoryStatDAO(), getObserveNewJvm()); } @Override
--- a/agent/core/src/test/java/com/redhat/thermostat/backend/system/JvmStatHostListenerTest.java Wed Oct 03 18:05:54 2012 -0400 +++ b/agent/core/src/test/java/com/redhat/thermostat/backend/system/JvmStatHostListenerTest.java Wed Oct 03 18:05:54 2012 -0400 @@ -83,7 +83,7 @@ VmInfoDAO vmInfoDAO = mock(VmInfoDAO.class); DAOFactory df = mock(DAOFactory.class); when(df.getVmClassStatsDAO()).thenReturn(vmClassDAO); - JvmStatHostListener l = new JvmStatHostListener(df, vmInfoDAO, true); + JvmStatHostListener l = new JvmStatHostListener(df, vmInfoDAO, null, true); SystemBackend backend = mock(SystemBackend.class); when(backend.getObserveNewJvm()).thenReturn(true);
--- a/client/core/src/main/java/com/redhat/thermostat/client/internal/Main.java Wed Oct 03 18:05:54 2012 -0400 +++ b/client/core/src/main/java/com/redhat/thermostat/client/internal/Main.java Wed Oct 03 18:05:54 2012 -0400 @@ -290,8 +290,8 @@ uiFacadeFactory.setNetworkInfoDao(daoFactory.getNetworkInterfaceInfoDAO()); uiFacadeFactory.setVmInfoDao(daoFactory.getVmInfoDAO()); - uiFacadeFactory.setVmCpuStatDao(daoFactory.getVmCpuStatDAO()); + uiFacadeFactory.setVmMemoryStatDao(daoFactory.getVmMemoryStatDAO()); showMainWindow(); } else if (newStatus == ConnectionStatus.FAILED_TO_CONNECT) {
--- a/client/core/src/main/java/com/redhat/thermostat/client/internal/UiFacadeFactoryImpl.java Wed Oct 03 18:05:54 2012 -0400 +++ b/client/core/src/main/java/com/redhat/thermostat/client/internal/UiFacadeFactoryImpl.java Wed Oct 03 18:05:54 2012 -0400 @@ -57,6 +57,7 @@ import com.redhat.thermostat.common.dao.NetworkInterfaceInfoDAO; import com.redhat.thermostat.common.dao.VmCpuStatDAO; import com.redhat.thermostat.common.dao.VmInfoDAO; +import com.redhat.thermostat.common.dao.VmMemoryStatDAO; import com.redhat.thermostat.common.dao.VmRef; public class UiFacadeFactoryImpl implements UiFacadeFactory { @@ -75,6 +76,7 @@ private VmInfoDAO vmInfoDao; private VmCpuStatDAO vmCpuStatDao; + private VmMemoryStatDAO vmMemoryStatDao; public UiFacadeFactoryImpl(BundleContext context) { this.context = context; @@ -106,6 +108,11 @@ } @Override + public void setVmMemoryStatDao(VmMemoryStatDAO vmMemoryStatDao) { + this.vmMemoryStatDao = vmMemoryStatDao; + } + + @Override public MainWindowController getMainWindow() { MainView mainView = new MainWindow(); RegistryFactory registryFactory = new RegistryFactory(context); @@ -126,7 +133,7 @@ @Override public VmInformationController getVmController(VmRef ref) { - return new VmInformationController(this, vmInfoDao, vmCpuStatDao, ref); + return new VmInformationController(this, vmInfoDao, vmCpuStatDao, vmMemoryStatDao, ref); }
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/UiFacadeFactory.java Wed Oct 03 18:05:54 2012 -0400 +++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/UiFacadeFactory.java Wed Oct 03 18:05:54 2012 -0400 @@ -47,6 +47,7 @@ import com.redhat.thermostat.common.dao.NetworkInterfaceInfoDAO; import com.redhat.thermostat.common.dao.VmCpuStatDAO; import com.redhat.thermostat.common.dao.VmInfoDAO; +import com.redhat.thermostat.common.dao.VmMemoryStatDAO; import com.redhat.thermostat.common.dao.VmRef; public interface UiFacadeFactory { @@ -58,6 +59,7 @@ void setVmInfoDao(VmInfoDAO vmInfoDAO); void setVmCpuStatDao(VmCpuStatDAO vmCpuStatDAO); + void setVmMemoryStatDao(VmMemoryStatDAO vmMemoryStatDao); public MainWindowController getMainWindow();
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/VmGcController.java Wed Oct 03 18:05:54 2012 -0400 +++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/VmGcController.java Wed Oct 03 18:05:54 2012 -0400 @@ -82,14 +82,14 @@ private long lastSeenTimeStamp = Long.MIN_VALUE; - public VmGcController(VmRef ref) { + public VmGcController(VmMemoryStatDAO vmMemoryStatDao, VmRef ref) { this.ref = ref; this.view = ApplicationContext.getInstance().getViewFactory().getView(VmGcView.class); this.timer = ApplicationContext.getInstance().getTimerFactory().createTimer(); DAOFactory df = ApplicationContext.getInstance().getDAOFactory(); gcDao = df.getVmGcStatDAO(); - memDao = df.getVmMemoryStatDAO(); + memDao = vmMemoryStatDao; view.addActionListener(new ActionListener<VmGcView.Action>() { @Override
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/VmInformationController.java Wed Oct 03 18:05:54 2012 -0400 +++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/VmInformationController.java Wed Oct 03 18:05:54 2012 -0400 @@ -47,6 +47,7 @@ import com.redhat.thermostat.common.appctx.ApplicationContext; import com.redhat.thermostat.common.dao.VmCpuStatDAO; import com.redhat.thermostat.common.dao.VmInfoDAO; +import com.redhat.thermostat.common.dao.VmMemoryStatDAO; import com.redhat.thermostat.common.dao.VmRef; public class VmInformationController { @@ -58,10 +59,10 @@ private final VmGcController gcController; public VmInformationController(UiFacadeFactory uiFacadeFactory, - VmInfoDAO vmInfoDao, VmCpuStatDAO vmCpuStatDao, VmRef vmRef) { + VmInfoDAO vmInfoDao, VmCpuStatDAO vmCpuStatDao, VmMemoryStatDAO vmMemoryStatDao, VmRef vmRef) { overviewController = new VmOverviewController(vmInfoDao, vmRef); cpuController = new VmCpuController(vmCpuStatDao, vmRef); - gcController = new VmGcController(vmRef); + gcController = new VmGcController(vmMemoryStatDao ,vmRef); view = ApplicationContext.getInstance().getViewFactory().getView(VmInformationView.class);
--- a/client/core/src/test/java/com/redhat/thermostat/client/ui/VmGcControllerTest.java Wed Oct 03 18:05:54 2012 -0400 +++ b/client/core/src/test/java/com/redhat/thermostat/client/ui/VmGcControllerTest.java Wed Oct 03 18:05:54 2012 -0400 @@ -112,7 +112,6 @@ DAOFactory daoFactory = mock(DAOFactory.class); when(daoFactory.getVmGcStatDAO()).thenReturn(vmGcStatDAO); - when(daoFactory.getVmMemoryStatDAO()).thenReturn(vmMemoryStatDAO); ApplicationContext.getInstance().setDAOFactory(daoFactory); // Setup View @@ -128,7 +127,7 @@ // Now start the controller VmRef ref = mock(VmRef.class); - new VmGcController(ref); + new VmGcController(vmMemoryStatDAO, ref); // Extract relevant objects viewListener = viewArgumentCaptor.getValue();
--- a/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/Activator.java Wed Oct 03 18:05:54 2012 -0400 +++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/Activator.java Wed Oct 03 18:05:54 2012 -0400 @@ -60,6 +60,7 @@ import com.redhat.thermostat.common.cli.CommandRegistry; import com.redhat.thermostat.common.cli.CommandRegistryImpl; import com.redhat.thermostat.common.dao.AgentInfoDAO; +import com.redhat.thermostat.common.dao.VmMemoryStatDAO; public class Activator implements BundleActivator { @@ -79,6 +80,7 @@ Class<?>[] deps = new Class<?>[] { ApplicationService.class, AgentInfoDAO.class, + VmMemoryStatDAO.class, }; heapDumperServiceTracker = new MultipleServiceTracker(context, deps, new Action() { @@ -89,9 +91,11 @@ Objects.requireNonNull(appService); AgentInfoDAO agentDao = (AgentInfoDAO) services.get(AgentInfoDAO.class.getName()); Objects.requireNonNull(agentDao); + VmMemoryStatDAO vmMemoryStatDao = (VmMemoryStatDAO) services.get(VmMemoryStatDAO.class.getName()); + Objects.requireNonNull(vmMemoryStatDao); heapDumperServiceRegistration = context.registerService( VmInformationService.class.getName(), - new HeapDumperService(appService, agentDao), + new HeapDumperService(appService, agentDao, vmMemoryStatDao), null); }
--- a/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/HeapDumpController.java Wed Oct 03 18:05:54 2012 -0400 +++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/HeapDumpController.java Wed Oct 03 18:05:54 2012 -0400 @@ -80,15 +80,15 @@ private OverviewChart model; private ApplicationService appService; - public HeapDumpController(final AgentInfoDAO agentInfoDao, final VmRef ref, final ApplicationService appService) { - this(agentInfoDao, ref, appService, new HeapDumperCommand()); + public HeapDumpController(final AgentInfoDAO agentInfoDao, final VmMemoryStatDAO vmMemoryStatDao, final VmRef ref, final ApplicationService appService) { + this(agentInfoDao, vmMemoryStatDao, ref, appService, new HeapDumperCommand()); } - HeapDumpController(final AgentInfoDAO agentInfoDao, final VmRef ref, final ApplicationService appService, final HeapDumperCommand command) { + HeapDumpController(final AgentInfoDAO agentInfoDao, final VmMemoryStatDAO vmMemoryStatDao, final VmRef ref, final ApplicationService appService, final HeapDumperCommand command) { this.appService = appService; this.ref = ref; - this.vmDao = ApplicationContext.getInstance().getDAOFactory().getVmMemoryStatDAO(); + this.vmDao = vmMemoryStatDao; this.heapDAO = ApplicationContext.getInstance().getDAOFactory().getHeapDAO(); model = new OverviewChart(
--- a/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/HeapDumperService.java Wed Oct 03 18:05:54 2012 -0400 +++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/HeapDumperService.java Wed Oct 03 18:05:54 2012 -0400 @@ -42,22 +42,27 @@ import com.redhat.thermostat.client.osgi.service.VmInformationService; import com.redhat.thermostat.client.osgi.service.VmInformationServiceController; import com.redhat.thermostat.common.dao.AgentInfoDAO; +import com.redhat.thermostat.common.dao.VmMemoryStatDAO; import com.redhat.thermostat.common.dao.VmRef; public class HeapDumperService implements VmInformationService { + private ApplicationService appService; private AgentInfoDAO agentInfoDao; - private ApplicationService appService; + private VmMemoryStatDAO vmMemoryStatDao; + private VmFilter filter = new AlwaysMatchFilter(); - public HeapDumperService(ApplicationService appService, AgentInfoDAO agentInfoDao) { + public HeapDumperService(ApplicationService appService, + AgentInfoDAO agentInfoDao, VmMemoryStatDAO vmMemoryStatDao) { + this.appService = appService; this.agentInfoDao = agentInfoDao; - this.appService = appService; + this.vmMemoryStatDao = vmMemoryStatDao; } @Override public VmInformationServiceController getInformationServiceController(VmRef ref) { - return new HeapDumpController(agentInfoDao, ref, appService); + return new HeapDumpController(agentInfoDao, vmMemoryStatDao, ref, appService); } @Override
--- a/client/heapdumper/src/test/java/com/redhat/thermostat/client/heap/HeapDumpControllerTest.java Wed Oct 03 18:05:54 2012 -0400 +++ b/client/heapdumper/src/test/java/com/redhat/thermostat/client/heap/HeapDumpControllerTest.java Wed Oct 03 18:05:54 2012 -0400 @@ -85,7 +85,7 @@ private AgentInfoDAO agentDao; private HeapDAO heapDAO; - private VmMemoryStatDAO vmDAO; + private VmMemoryStatDAO vmDao; private HeapView view; private HeapDumpDetailsView detailsView; @@ -106,8 +106,7 @@ agentDao = mock(AgentInfoDAO.class); heapDAO = mock(HeapDAO.class); when(daoFactory.getHeapDAO()).thenReturn(heapDAO); - vmDAO = mock(VmMemoryStatDAO.class); - when(daoFactory.getVmMemoryStatDAO()).thenReturn(vmDAO); + vmDao = mock(VmMemoryStatDAO.class); ApplicationContext.getInstance().setDAOFactory(daoFactory); @@ -162,13 +161,13 @@ when(appService.getApplicationCache()).thenReturn(cache); VmRef ref = mock(VmRef.class); heapDumperCommand = mock(HeapDumperCommand.class); - controller = new HeapDumpController(agentDao, ref, appService, heapDumperCommand); + controller = new HeapDumpController(agentDao, vmDao, ref, appService, heapDumperCommand); } @After public void tearDown() { controller = null; - vmDAO = null; + vmDao = null; heapDAO = null; ApplicationContextUtil.resetApplicationContext(); } @@ -237,7 +236,7 @@ appService = mock(ApplicationService.class); when(appService.getApplicationCache()).thenReturn(cache); VmRef ref = mock(VmRef.class); - controller = new HeapDumpController(agentDao, ref, appService); + controller = new HeapDumpController(agentDao, vmDao, ref, appService); verify(view, times(1)).setChildView(any(HeapView.class)); verify(view, times(1)).openDumpView(); @@ -260,7 +259,7 @@ appService = mock(ApplicationService.class); when(appService.getApplicationCache()).thenReturn(cache); VmRef ref = mock(VmRef.class); - controller = new HeapDumpController(agentDao, ref, appService); + controller = new HeapDumpController(agentDao, vmDao, ref, appService); verify(view, times(0)).openDumpView(); }
--- a/client/memory-stats-panel/src/main/java/com/redhat/thermostat/client/stats/memory/MemoryStatsController.java Wed Oct 03 18:05:54 2012 -0400 +++ b/client/memory-stats-panel/src/main/java/com/redhat/thermostat/client/stats/memory/MemoryStatsController.java Wed Oct 03 18:05:54 2012 -0400 @@ -136,12 +136,12 @@ } } - public MemoryStatsController(final VmRef ref) { + public MemoryStatsController(final VmMemoryStatDAO vmMemoryStatDao, final VmRef ref) { regions = new HashMap<>(); this.ref = ref; view = ApplicationContext.getInstance().getViewFactory().getView(MemoryStatsView.class); - vmDao = ApplicationContext.getInstance().getDAOFactory().getVmMemoryStatDAO(); + vmDao = vmMemoryStatDao; timer = ApplicationContext.getInstance().getTimerFactory().createTimer();
--- a/client/memory-stats-panel/src/main/java/com/redhat/thermostat/client/stats/memory/MemoryStatsPanelActivator.java Wed Oct 03 18:05:54 2012 -0400 +++ b/client/memory-stats-panel/src/main/java/com/redhat/thermostat/client/stats/memory/MemoryStatsPanelActivator.java Wed Oct 03 18:05:54 2012 -0400 @@ -36,32 +36,53 @@ package com.redhat.thermostat.client.stats.memory; +import java.util.Map; + import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTracker; +import org.osgi.framework.ServiceRegistration; import com.redhat.thermostat.client.osgi.service.ApplicationService; import com.redhat.thermostat.client.osgi.service.VmInformationService; +import com.redhat.thermostat.common.MultipleServiceTracker; +import com.redhat.thermostat.common.MultipleServiceTracker.Action; import com.redhat.thermostat.common.appctx.ApplicationContext; +import com.redhat.thermostat.common.dao.VmMemoryStatDAO; public class MemoryStatsPanelActivator implements BundleActivator { + private MultipleServiceTracker tracker; + private ServiceRegistration memoryStatRegistration; + @Override - public void start(BundleContext context) throws Exception { - ServiceTracker tracker = new ServiceTracker(context, ApplicationService.class.getName(), null) { + public void start(final BundleContext context) throws Exception { + Class<?>[] deps = new Class<?>[] { + ApplicationService.class, + VmMemoryStatDAO.class, + }; + + tracker = new MultipleServiceTracker(context, deps, new Action() { + @Override - public Object addingService(ServiceReference reference) { + public void dependenciesUnavailable() { + memoryStatRegistration.unregister(); + memoryStatRegistration = null; + } + + @Override + public void dependenciesAvailable(Map<String, Object> services) { ApplicationContext.getInstance().getViewFactory().setViewClass(MemoryStatsView.class, MemoryStatsViewImpl.class); - context.registerService(VmInformationService.class.getName(), new MemoryStatsService(), null); - return super.addingService(reference); + VmMemoryStatDAO memoryStatDao = (VmMemoryStatDAO) services.get(VmMemoryStatDAO.class.getName()); + MemoryStatsService impl = new MemoryStatsService(memoryStatDao); + memoryStatRegistration = context.registerService(VmInformationService.class.getName(), impl , null); } - }; + }); tracker.open(); + } - + @Override public void stop(BundleContext context) throws Exception { - + tracker.close(); } }
--- a/client/memory-stats-panel/src/main/java/com/redhat/thermostat/client/stats/memory/MemoryStatsService.java Wed Oct 03 18:05:54 2012 -0400 +++ b/client/memory-stats-panel/src/main/java/com/redhat/thermostat/client/stats/memory/MemoryStatsService.java Wed Oct 03 18:05:54 2012 -0400 @@ -40,16 +40,22 @@ import com.redhat.thermostat.client.osgi.service.VmFilter; import com.redhat.thermostat.client.osgi.service.VmInformationService; import com.redhat.thermostat.client.osgi.service.VmInformationServiceController; -import com.redhat.thermostat.common.dao.Ref; +import com.redhat.thermostat.common.dao.VmMemoryStatDAO; import com.redhat.thermostat.common.dao.VmRef; class MemoryStatsService implements VmInformationService { private VmFilter filter = new AlwaysMatchFilter(); + + private VmMemoryStatDAO vmMemoryStatDao; + + public MemoryStatsService(VmMemoryStatDAO vmMemoryStatDao) { + this.vmMemoryStatDao = vmMemoryStatDao; + } @Override public VmInformationServiceController getInformationServiceController(VmRef ref) { - return new MemoryStatsController(ref); + return new MemoryStatsController(vmMemoryStatDao, ref); } @Override
--- a/client/memory-stats-panel/src/test/java/com/redhat/thermostat/client/stats/memory/MemoryStatsControllerTest.java Wed Oct 03 18:05:54 2012 -0400 +++ b/client/memory-stats-panel/src/test/java/com/redhat/thermostat/client/stats/memory/MemoryStatsControllerTest.java Wed Oct 03 18:05:54 2012 -0400 @@ -63,7 +63,6 @@ import com.redhat.thermostat.common.ViewFactory; import com.redhat.thermostat.common.appctx.ApplicationContext; import com.redhat.thermostat.common.appctx.ApplicationContextUtil; -import com.redhat.thermostat.common.dao.DAOFactory; import com.redhat.thermostat.common.dao.VmMemoryStatDAO; import com.redhat.thermostat.common.dao.VmRef; import com.redhat.thermostat.common.model.VmMemoryStat; @@ -129,11 +128,6 @@ VmMemoryStatDAO memoryStatDao = mock(VmMemoryStatDAO.class); when(memoryStatDao.getLatestVmMemoryStats(any(VmRef.class), anyLong())).thenReturn(vmInfo); - - DAOFactory daoFactory = mock(DAOFactory.class); - when(daoFactory.getVmMemoryStatDAO()).thenReturn(memoryStatDao); - - ApplicationContext.getInstance().setDAOFactory(daoFactory); view = mock(MemoryStatsView.class); ViewFactory viewFactory = mock(ViewFactory.class); @@ -146,7 +140,7 @@ VmRef ref = mock(VmRef.class); - controller = new MemoryStatsController(ref); + controller = new MemoryStatsController(memoryStatDao, ref); viewListener = viewArgumentCaptor.getValue(); }
--- a/tools/src/main/java/com/redhat/thermostat/tools/LocaleResources.java Wed Oct 03 18:05:54 2012 -0400 +++ b/tools/src/main/java/com/redhat/thermostat/tools/LocaleResources.java Wed Oct 03 18:05:54 2012 -0400 @@ -45,6 +45,7 @@ HOST_SERVICE_UNAVAILABLE, VM_SERVICE_UNAVAILABLE, VM_CPU_SERVICE_NOT_AVAILABLE, + VM_MEMORY_SERVICE_NOT_AVAILABLE, COMMAND_CONNECT_ALREADY_CONNECTED, COMMAND_CONNECT_FAILED_TO_CONNECT,
--- a/tools/src/main/java/com/redhat/thermostat/tools/cli/VMStatCommand.java Wed Oct 03 18:05:54 2012 -0400 +++ b/tools/src/main/java/com/redhat/thermostat/tools/cli/VMStatCommand.java Wed Oct 03 18:05:54 2012 -0400 @@ -48,7 +48,6 @@ import com.redhat.thermostat.common.cli.CommandException; import com.redhat.thermostat.common.cli.HostVMArguments; import com.redhat.thermostat.common.cli.SimpleCommand; -import com.redhat.thermostat.common.dao.DAOFactory; import com.redhat.thermostat.common.dao.VmCpuStatDAO; import com.redhat.thermostat.common.dao.VmMemoryStatDAO; import com.redhat.thermostat.common.dao.VmRef; @@ -74,14 +73,15 @@ @Override public void run(final CommandContext ctx) throws CommandException { - DAOFactory daoFactory = ApplicationContext.getInstance().getDAOFactory(); - VmCpuStatDAO vmCpuStatDAO = serviceProvider.getServiceAllowNull(VmCpuStatDAO.class); if (vmCpuStatDAO == null) { throw new CommandException(Translate.localize(LocaleResources.VM_CPU_SERVICE_NOT_AVAILABLE)); } - VmMemoryStatDAO vmMemoryStatDAO = daoFactory.getVmMemoryStatDAO(); + VmMemoryStatDAO vmMemoryStatDAO = serviceProvider.getServiceAllowNull(VmMemoryStatDAO.class); + if (vmMemoryStatDAO == null) { + throw new CommandException(Translate.localize(LocaleResources.VM_MEMORY_SERVICE_NOT_AVAILABLE)); + } HostVMArguments hostVMArgs = new HostVMArguments(ctx.getArguments()); VmRef vm = hostVMArgs.getVM(); @@ -92,6 +92,7 @@ startContinuousStats(ctx, statPrinter); } + serviceProvider.ungetService(VmMemoryStatDAO.class, vmMemoryStatDAO); serviceProvider.ungetService(VmCpuStatDAO.class, vmCpuStatDAO); }
--- a/tools/src/main/resources/com/redhat/thermostat/tools/strings.properties Wed Oct 03 18:05:54 2012 -0400 +++ b/tools/src/main/resources/com/redhat/thermostat/tools/strings.properties Wed Oct 03 18:05:54 2012 -0400 @@ -5,6 +5,7 @@ HOST_SERVICE_UNAVAILABLE = Unable to get host information (HostInfoDAO is unavailable) VM_SERVICE_UNAVAILABLE = Unable to get vm information (VmInfoDAO is unavailable) VM_CPU_SERVICE_NOT_AVAILABLE = Unable to access vm cpu information (VmCpuStats not available) +VM_MEMORY_SERVICE_NOT_AVAILABLE = Unable to access vm memory information (VmCpuStats not available) COMMAND_CONNECT_ALREADY_CONNECTED = Already connected to storage. Please use disconnect command to disconnect. COMMAND_CONNECT_FAILED_TO_CONNECT = Could not connect to db {0}
--- a/tools/src/test/java/com/redhat/thermostat/tools/cli/VmStatCommandTest.java Wed Oct 03 18:05:54 2012 -0400 +++ b/tools/src/test/java/com/redhat/thermostat/tools/cli/VmStatCommandTest.java Wed Oct 03 18:05:54 2012 -0400 @@ -64,7 +64,6 @@ import com.redhat.thermostat.common.appctx.ApplicationContextUtil; import com.redhat.thermostat.common.cli.CommandException; import com.redhat.thermostat.common.cli.SimpleArguments; -import com.redhat.thermostat.common.dao.DAOFactory; import com.redhat.thermostat.common.dao.HostRef; import com.redhat.thermostat.common.dao.VmCpuStatDAO; import com.redhat.thermostat.common.dao.VmMemoryStatDAO; @@ -113,6 +112,7 @@ OSGIUtils serviceProvider = mock(OSGIUtils.class); when(serviceProvider.getServiceAllowNull(VmCpuStatDAO.class)).thenReturn(vmCpuStatDAO); + when(serviceProvider.getServiceAllowNull(VmMemoryStatDAO.class)).thenReturn(vmMemoryStatDAO); cmd = new VMStatCommand(serviceProvider); } @@ -140,8 +140,6 @@ List<VmCpuStat> cpuStats = Arrays.asList(cpustat1, cpustat2); List<VmCpuStat> cpuStats2 = Collections.emptyList(); when(vmCpuStatDAO.getLatestVmCpuStats(vm, Long.MIN_VALUE)).thenReturn(cpuStats).thenReturn(cpuStats2); - DAOFactory daoFactory = mock(DAOFactory.class); - ApplicationContext.getInstance().setDAOFactory(daoFactory); VmMemoryStat.Space space1_1_1 = newSpace("space1", 123456, 12345, 1, 0); VmMemoryStat.Space space1_1_2 = newSpace("space2", 123456, 12345, 1, 0); @@ -205,7 +203,6 @@ when(vmMemoryStatDAO.getLatestVmMemoryStats(vm, memStat3.getTimeStamp())).thenReturn(Arrays.asList(memStat4)); - when(daoFactory.getVmMemoryStatDAO()).thenReturn(vmMemoryStatDAO); } private Space newSpace(String name, long maxCapacity, long capacity, long used, int index) {