changeset 668:05b32d4c099c

Use MemoryStatDAO as an osgi service Use MemoryStatDAO either directly or as an osgi service, never through DaoFactory. Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-September/003487.html
author Omair Majid <omajid@redhat.com>
date Wed, 03 Oct 2012 18:05:54 -0400
parents 4e5c8f3164f9
children b3f7bae3400e
files client/core/src/main/java/com/redhat/thermostat/client/internal/HostPanelFacadeImpl.java client/core/src/main/java/com/redhat/thermostat/client/internal/UiFacadeFactoryImpl.java client/core/src/main/java/com/redhat/thermostat/client/ui/HostInformationController.java client/core/src/main/java/com/redhat/thermostat/client/ui/HostMemoryController.java client/core/src/main/java/com/redhat/thermostat/client/ui/UiFacadeFactory.java client/core/src/test/java/com/redhat/thermostat/client/ui/HostMemoryControllerTest.java
diffstat 6 files changed, 21 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/client/core/src/main/java/com/redhat/thermostat/client/internal/HostPanelFacadeImpl.java	Wed Oct 03 18:05:54 2012 -0400
+++ b/client/core/src/main/java/com/redhat/thermostat/client/internal/HostPanelFacadeImpl.java	Wed Oct 03 18:05:54 2012 -0400
@@ -42,6 +42,7 @@
 import com.redhat.thermostat.common.dao.CpuStatDAO;
 import com.redhat.thermostat.common.dao.HostInfoDAO;
 import com.redhat.thermostat.common.dao.HostRef;
+import com.redhat.thermostat.common.dao.MemoryStatDAO;
 
 public class HostPanelFacadeImpl implements HostPanelFacade {
 
@@ -49,10 +50,11 @@
     private final HostCpuController cpuController;
     private final HostMemoryController memoryController;
 
-    public HostPanelFacadeImpl(HostInfoDAO hostInfoDao, CpuStatDAO cpuStatDao, HostRef ref) {
+    public HostPanelFacadeImpl(HostInfoDAO hostInfoDao,
+            CpuStatDAO cpuStatDao, MemoryStatDAO memoryStatDao, HostRef ref) {
         overviewController = new HostOverviewController(hostInfoDao, ref);
         cpuController = new HostCpuController(hostInfoDao, cpuStatDao, ref);
-        memoryController = new HostMemoryController(hostInfoDao, ref);
+        memoryController = new HostMemoryController(hostInfoDao, memoryStatDao, ref);
     }
 
     @Override
--- 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
@@ -53,6 +53,7 @@
 import com.redhat.thermostat.common.dao.CpuStatDAO;
 import com.redhat.thermostat.common.dao.HostInfoDAO;
 import com.redhat.thermostat.common.dao.HostRef;
+import com.redhat.thermostat.common.dao.MemoryStatDAO;
 import com.redhat.thermostat.common.dao.VmRef;
 
 public class UiFacadeFactoryImpl implements UiFacadeFactory {
@@ -65,6 +66,7 @@
     private BundleContext context;
     private HostInfoDAO hostInfoDao;
     private CpuStatDAO cpuStatDao;
+    private MemoryStatDAO memoryStatDao;
 
     public UiFacadeFactoryImpl(BundleContext context) {
         this.context = context;
@@ -79,6 +81,10 @@
         this.cpuStatDao = cpuStatDao;
     }
 
+    public void setMemoryStatDao(MemoryStatDAO memoryStatDao) {
+        this.memoryStatDao = memoryStatDao;
+    }
+
     @Override
     public MainWindowController getMainWindow() {
         MainView mainView = new MainWindow();
@@ -94,7 +100,7 @@
 
     @Override
     public HostInformationController getHostController(HostRef ref) {
-        return new HostInformationController(hostInfoDao, cpuStatDao, ref);
+        return new HostInformationController(hostInfoDao, cpuStatDao, memoryStatDao, ref);
 
     }
 
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/HostInformationController.java	Wed Oct 03 18:05:54 2012 -0400
+++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/HostInformationController.java	Wed Oct 03 18:05:54 2012 -0400
@@ -44,6 +44,7 @@
 import com.redhat.thermostat.common.dao.CpuStatDAO;
 import com.redhat.thermostat.common.dao.HostInfoDAO;
 import com.redhat.thermostat.common.dao.HostRef;
+import com.redhat.thermostat.common.dao.MemoryStatDAO;
 
 public class HostInformationController {
 
@@ -53,10 +54,11 @@
 
     private final HostInformationView view;
 
-    public HostInformationController(HostInfoDAO hostInfoDao, CpuStatDAO cpuStatDao, HostRef ref) {
+    public HostInformationController(HostInfoDAO hostInfoDao,
+            CpuStatDAO cpuStatDao, MemoryStatDAO memoryStatDao, HostRef ref) {
         overviewController = new HostOverviewController(hostInfoDao, ref);
         cpuController = new HostCpuController(hostInfoDao, cpuStatDao, ref);
-        memoryController = new HostMemoryController(hostInfoDao ,ref);
+        memoryController = new HostMemoryController(hostInfoDao, memoryStatDao, ref);
 
         view = ApplicationContext.getInstance().getViewFactory().getView(HostInformationView.class);
 
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/HostMemoryController.java	Wed Oct 03 18:05:54 2012 -0400
+++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/HostMemoryController.java	Wed Oct 03 18:05:54 2012 -0400
@@ -74,11 +74,10 @@
 
     private long lastSeenTimeStamp = Long.MIN_VALUE;
 
-    public HostMemoryController(HostInfoDAO hostInfoDAO, final HostRef ref) {
+    public HostMemoryController(HostInfoDAO hostInfoDAO, MemoryStatDAO memoryStatDAO, final HostRef ref) {
         this.ref = ref;
-        DAOFactory daos = ApplicationContext.getInstance().getDAOFactory();
         this.hostInfoDAO = hostInfoDAO;
-        memoryStatDAO = daos.getMemoryStatDAO();
+        this.memoryStatDAO = memoryStatDAO;
 
         view = ApplicationContext.getInstance().getViewFactory().getView(HostMemoryView.class);
 
--- 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
@@ -43,6 +43,7 @@
 import com.redhat.thermostat.common.dao.CpuStatDAO;
 import com.redhat.thermostat.common.dao.HostInfoDAO;
 import com.redhat.thermostat.common.dao.HostRef;
+import com.redhat.thermostat.common.dao.MemoryStatDAO;
 import com.redhat.thermostat.common.dao.VmRef;
 
 public interface UiFacadeFactory {
@@ -51,6 +52,8 @@
 
     void setCpuStatDao(CpuStatDAO cpuStatDAO);
 
+    void setMemoryStatDao(MemoryStatDAO memoryStatDAO);
+
     public MainWindowController getMainWindow();
 
     public SummaryController getSummary();
--- a/client/core/src/test/java/com/redhat/thermostat/client/ui/HostMemoryControllerTest.java	Wed Oct 03 18:05:54 2012 -0400
+++ b/client/core/src/test/java/com/redhat/thermostat/client/ui/HostMemoryControllerTest.java	Wed Oct 03 18:05:54 2012 -0400
@@ -59,11 +59,9 @@
 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.HostInfoDAO;
 import com.redhat.thermostat.common.dao.HostRef;
 import com.redhat.thermostat.common.dao.MemoryStatDAO;
-import com.redhat.thermostat.common.dao.MongoDAOFactory;
 import com.redhat.thermostat.common.model.HostInfo;
 import com.redhat.thermostat.common.model.MemoryStat;
 
@@ -88,10 +86,6 @@
         MemoryStatDAO memoryStatDAO = mock(MemoryStatDAO.class);
         when(memoryStatDAO.getLatestMemoryStats(any(HostRef.class), anyLong())).thenReturn(memoryStats);
 
-        DAOFactory daoFactory = mock(MongoDAOFactory.class);
-        when(daoFactory.getMemoryStatDAO()).thenReturn(memoryStatDAO);
-        ApplicationContext.getInstance().setDAOFactory(daoFactory);
-
         Timer timer = mock(Timer.class);
         ArgumentCaptor<Runnable> timerActionCaptor = ArgumentCaptor.forClass(Runnable.class);
         doNothing().when(timer).setAction(timerActionCaptor.capture());
@@ -110,7 +104,7 @@
         when(viewFactory.getView(eq(HostMemoryView.class))).thenReturn(view);
         ApplicationContext.getInstance().setViewFactory(viewFactory);
 
-        HostMemoryController controller = new HostMemoryController(hostInfoDAO, ref);
+        HostMemoryController controller = new HostMemoryController(hostInfoDAO, memoryStatDAO, ref);
 
         ActionListener<HostMemoryView.Action> l = viewArgumentCaptor.getValue();