Mercurial > hg > release > thermostat-0.6
changeset 676:27610016edd6
Use VmGcStatDAO as a service
Reviewed-by: jerboaa
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-September/003494.html
line wrap: on
line diff
--- a/agent/core/src/main/java/com/redhat/thermostat/backend/system/JvmStatHostListener.java Wed Oct 03 18:26:56 2012 -0400 +++ b/agent/core/src/main/java/com/redhat/thermostat/backend/system/JvmStatHostListener.java Thu Oct 04 12:52:09 2012 -0400 @@ -59,8 +59,8 @@ import com.redhat.thermostat.agent.JvmStatusListener; import com.redhat.thermostat.agent.JvmStatusNotifier; -import com.redhat.thermostat.common.dao.DAOFactory; import com.redhat.thermostat.common.dao.VmClassStatDAO; +import com.redhat.thermostat.common.dao.VmGcStatDAO; import com.redhat.thermostat.common.dao.VmInfoDAO; import com.redhat.thermostat.common.dao.VmMemoryStatDAO; import com.redhat.thermostat.common.model.VmInfo; @@ -72,21 +72,21 @@ private boolean attachNew; - private final DAOFactory df; private final VmInfoDAO vmInfoDAO; private final VmMemoryStatDAO vmMemoryStatDAO; private final VmClassStatDAO vmClassStatDAO; + private final VmGcStatDAO vmGcStatDAO; 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, VmMemoryStatDAO vmMemoryStatDAO, + JvmStatHostListener(VmInfoDAO vmInfoDAO, VmMemoryStatDAO vmMemoryStatDAO, VmGcStatDAO vmGcStatDAO, VmClassStatDAO vmClassStatDAO, boolean attachNew) { - this.df = df; this.vmInfoDAO = vmInfoDAO; this.vmMemoryStatDAO = vmMemoryStatDAO; + this.vmGcStatDAO = vmGcStatDAO; this.vmClassStatDAO = vmClassStatDAO; this.attachNew = attachNew; } @@ -169,7 +169,7 @@ listeners = new CopyOnWriteArrayList<>(); } - VmListener listener = new JvmStatVmListener(df, vmMemoryStatDAO, vmId); + VmListener listener = new JvmStatVmListener(vmMemoryStatDAO, vmGcStatDAO, vmId); vm.addVmListener(listener); listeners.add(listener);
--- a/agent/core/src/main/java/com/redhat/thermostat/backend/system/JvmStatVmListener.java Wed Oct 03 18:26:56 2012 -0400 +++ b/agent/core/src/main/java/com/redhat/thermostat/backend/system/JvmStatVmListener.java Thu Oct 04 12:52:09 2012 -0400 @@ -47,7 +47,6 @@ import sun.jvmstat.monitor.event.VmEvent; import sun.jvmstat.monitor.event.VmListener; -import com.redhat.thermostat.common.dao.DAOFactory; import com.redhat.thermostat.common.dao.VmGcStatDAO; import com.redhat.thermostat.common.dao.VmMemoryStatDAO; import com.redhat.thermostat.common.model.VmGcStat; @@ -64,8 +63,8 @@ private final VmGcStatDAO gcDAO; private final VmMemoryStatDAO memDAO; - public JvmStatVmListener(DAOFactory df, VmMemoryStatDAO vmMemoryStatDao, int vmId) { - gcDAO = df.getVmGcStatDAO(); + public JvmStatVmListener(VmMemoryStatDAO vmMemoryStatDao, VmGcStatDAO vmGcStatDao, int vmId) { + gcDAO = vmGcStatDao; memDAO = vmMemoryStatDao; this.vmId = vmId; }
--- a/agent/core/src/main/java/com/redhat/thermostat/backend/system/SystemBackend.java Wed Oct 03 18:26:56 2012 -0400 +++ b/agent/core/src/main/java/com/redhat/thermostat/backend/system/SystemBackend.java Thu Oct 04 12:52:09 2012 -0400 @@ -131,7 +131,7 @@ memoryStats = df.getMemoryStatDAO(); vmCpuStats = df.getVmCpuStatDAO(); networkInterfaces = df.getNetworkInterfaceInfoDAO(); - hostListener = new JvmStatHostListener(df, df.getVmInfoDAO(), df.getVmMemoryStatDAO(), df.getVmClassStatsDAO(), getObserveNewJvm()); + hostListener = new JvmStatHostListener(df.getVmInfoDAO(), df.getVmMemoryStatDAO(), df.getVmGcStatDAO(), df.getVmClassStatsDAO(), getObserveNewJvm()); } @Override
--- a/agent/core/src/test/java/com/redhat/thermostat/backend/system/JvmStatHostListenerTest.java Wed Oct 03 18:26:56 2012 -0400 +++ b/agent/core/src/test/java/com/redhat/thermostat/backend/system/JvmStatHostListenerTest.java Thu Oct 04 12:52:09 2012 -0400 @@ -48,10 +48,6 @@ import org.junit.Test; import org.mockito.Matchers; -import com.redhat.thermostat.common.dao.DAOFactory; -import com.redhat.thermostat.common.dao.VmClassStatDAO; -import com.redhat.thermostat.common.dao.VmInfoDAO; - import sun.jvmstat.monitor.HostIdentifier; import sun.jvmstat.monitor.MonitoredHost; import sun.jvmstat.monitor.MonitoredVm; @@ -59,6 +55,9 @@ import sun.jvmstat.monitor.VmIdentifier; import sun.jvmstat.monitor.event.VmStatusChangeEvent; +import com.redhat.thermostat.common.dao.VmClassStatDAO; +import com.redhat.thermostat.common.dao.VmInfoDAO; + public class JvmStatHostListenerTest { @Test @@ -81,9 +80,8 @@ VmClassStatDAO vmClassDAO = mock(VmClassStatDAO.class); VmInfoDAO vmInfoDAO = mock(VmInfoDAO.class); - DAOFactory df = mock(DAOFactory.class); - JvmStatHostListener l = new JvmStatHostListener(df, vmInfoDAO, null, vmClassDAO ,true); + JvmStatHostListener l = new JvmStatHostListener(vmInfoDAO, null, null, vmClassDAO ,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:26:56 2012 -0400 +++ b/client/core/src/main/java/com/redhat/thermostat/client/internal/Main.java Thu Oct 04 12:52:09 2012 -0400 @@ -292,6 +292,7 @@ uiFacadeFactory.setVmInfoDao(daoFactory.getVmInfoDAO()); uiFacadeFactory.setVmCpuStatDao(daoFactory.getVmCpuStatDAO()); uiFacadeFactory.setVmMemoryStatDao(daoFactory.getVmMemoryStatDAO()); + uiFacadeFactory.setVmGcStatDao(daoFactory.getVmGcStatDAO()); 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:26:56 2012 -0400 +++ b/client/core/src/main/java/com/redhat/thermostat/client/internal/UiFacadeFactoryImpl.java Thu Oct 04 12:52:09 2012 -0400 @@ -56,6 +56,7 @@ import com.redhat.thermostat.common.dao.MemoryStatDAO; import com.redhat.thermostat.common.dao.NetworkInterfaceInfoDAO; import com.redhat.thermostat.common.dao.VmCpuStatDAO; +import com.redhat.thermostat.common.dao.VmGcStatDAO; import com.redhat.thermostat.common.dao.VmInfoDAO; import com.redhat.thermostat.common.dao.VmMemoryStatDAO; import com.redhat.thermostat.common.dao.VmRef; @@ -77,6 +78,7 @@ private VmInfoDAO vmInfoDao; private VmCpuStatDAO vmCpuStatDao; private VmMemoryStatDAO vmMemoryStatDao; + private VmGcStatDAO vmGcStatDao; public UiFacadeFactoryImpl(BundleContext context) { this.context = context; @@ -113,6 +115,11 @@ } @Override + public void setVmGcStatDao(VmGcStatDAO vmGcStatDao) { + this.vmGcStatDao = vmGcStatDao; + } + + @Override public MainWindowController getMainWindow() { MainView mainView = new MainWindow(); RegistryFactory registryFactory = new RegistryFactory(context); @@ -133,7 +140,7 @@ @Override public VmInformationController getVmController(VmRef ref) { - return new VmInformationController(this, vmInfoDao, vmCpuStatDao, vmMemoryStatDao, ref); + return new VmInformationController(this, vmInfoDao, vmCpuStatDao, vmMemoryStatDao, vmGcStatDao, ref); }
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/UiFacadeFactory.java Wed Oct 03 18:26:56 2012 -0400 +++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/UiFacadeFactory.java Thu Oct 04 12:52:09 2012 -0400 @@ -46,6 +46,7 @@ import com.redhat.thermostat.common.dao.MemoryStatDAO; import com.redhat.thermostat.common.dao.NetworkInterfaceInfoDAO; import com.redhat.thermostat.common.dao.VmCpuStatDAO; +import com.redhat.thermostat.common.dao.VmGcStatDAO; import com.redhat.thermostat.common.dao.VmInfoDAO; import com.redhat.thermostat.common.dao.VmMemoryStatDAO; import com.redhat.thermostat.common.dao.VmRef; @@ -60,6 +61,7 @@ void setVmInfoDao(VmInfoDAO vmInfoDAO); void setVmCpuStatDao(VmCpuStatDAO vmCpuStatDAO); void setVmMemoryStatDao(VmMemoryStatDAO vmMemoryStatDao); + void setVmGcStatDao(VmGcStatDAO vmGcStatDao); public MainWindowController getMainWindow();
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/VmGcController.java Wed Oct 03 18:26:56 2012 -0400 +++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/VmGcController.java Thu Oct 04 12:52:09 2012 -0400 @@ -56,7 +56,6 @@ import com.redhat.thermostat.common.Timer; import com.redhat.thermostat.common.Timer.SchedulingType; import com.redhat.thermostat.common.appctx.ApplicationContext; -import com.redhat.thermostat.common.dao.DAOFactory; import com.redhat.thermostat.common.dao.VmGcStatDAO; import com.redhat.thermostat.common.dao.VmMemoryStatDAO; import com.redhat.thermostat.common.dao.VmRef; @@ -82,13 +81,12 @@ private long lastSeenTimeStamp = Long.MIN_VALUE; - public VmGcController(VmMemoryStatDAO vmMemoryStatDao, VmRef ref) { + public VmGcController(VmMemoryStatDAO vmMemoryStatDao, VmGcStatDAO vmGcStatDao, 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(); + gcDao = vmGcStatDao; memDao = vmMemoryStatDao; view.addActionListener(new ActionListener<VmGcView.Action>() {
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/VmInformationController.java Wed Oct 03 18:26:56 2012 -0400 +++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/VmInformationController.java Thu Oct 04 12:52:09 2012 -0400 @@ -46,6 +46,7 @@ import com.redhat.thermostat.client.osgi.service.VmInformationServiceController; import com.redhat.thermostat.common.appctx.ApplicationContext; import com.redhat.thermostat.common.dao.VmCpuStatDAO; +import com.redhat.thermostat.common.dao.VmGcStatDAO; import com.redhat.thermostat.common.dao.VmInfoDAO; import com.redhat.thermostat.common.dao.VmMemoryStatDAO; import com.redhat.thermostat.common.dao.VmRef; @@ -59,10 +60,11 @@ private final VmGcController gcController; public VmInformationController(UiFacadeFactory uiFacadeFactory, - VmInfoDAO vmInfoDao, VmCpuStatDAO vmCpuStatDao, VmMemoryStatDAO vmMemoryStatDao, VmRef vmRef) { + VmInfoDAO vmInfoDao, VmCpuStatDAO vmCpuStatDao, + VmMemoryStatDAO vmMemoryStatDao, VmGcStatDAO vmGcStatDao, VmRef vmRef) { overviewController = new VmOverviewController(vmInfoDao, vmRef); cpuController = new VmCpuController(vmCpuStatDao, vmRef); - gcController = new VmGcController(vmMemoryStatDao ,vmRef); + gcController = new VmGcController(vmMemoryStatDao, vmGcStatDao, 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:26:56 2012 -0400 +++ b/client/core/src/test/java/com/redhat/thermostat/client/ui/VmGcControllerTest.java Thu Oct 04 12:52:09 2012 -0400 @@ -61,7 +61,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.VmGcStatDAO; import com.redhat.thermostat.common.dao.VmMemoryStatDAO; import com.redhat.thermostat.common.dao.VmRef; @@ -110,10 +109,6 @@ VmMemoryStatDAO vmMemoryStatDAO = mock(VmMemoryStatDAO.class); when(vmMemoryStatDAO.getLatestMemoryStat(isA(VmRef.class))).thenReturn(memoryStat); - DAOFactory daoFactory = mock(DAOFactory.class); - when(daoFactory.getVmGcStatDAO()).thenReturn(vmGcStatDAO); - ApplicationContext.getInstance().setDAOFactory(daoFactory); - // Setup View view = mock(VmGcView.class); ArgumentCaptor<ActionListener> viewArgumentCaptor = ArgumentCaptor.forClass(ActionListener.class); @@ -127,7 +122,7 @@ // Now start the controller VmRef ref = mock(VmRef.class); - new VmGcController(vmMemoryStatDAO, ref); + new VmGcController(vmMemoryStatDAO, vmGcStatDAO, ref); // Extract relevant objects viewListener = viewArgumentCaptor.getValue();