changeset 669:b3f7bae3400e

Use NetworkInterfaceInfoDAO as service NetworkInterfaceInfoDAO should either be obtained directly from the creator or as an OSGi service, never through DaoFactory (or ApplicationContext). Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-September/003488.html
author Omair Majid <omajid@redhat.com>
date Wed, 03 Oct 2012 18:05:54 -0400
parents 05b32d4c099c
children 1310dc5d5e48
files client/core/src/main/java/com/redhat/thermostat/client/internal/HostPanelFacadeImpl.java client/core/src/main/java/com/redhat/thermostat/client/internal/Main.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/HostOverviewController.java client/core/src/main/java/com/redhat/thermostat/client/ui/UiFacadeFactory.java client/core/src/test/java/com/redhat/thermostat/client/ui/HostOverviewControllerTest.java
diffstat 7 files changed, 27 insertions(+), 18 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
@@ -43,6 +43,7 @@
 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.NetworkInterfaceInfoDAO;
 
 public class HostPanelFacadeImpl implements HostPanelFacade {
 
@@ -51,8 +52,9 @@
     private final HostMemoryController memoryController;
 
     public HostPanelFacadeImpl(HostInfoDAO hostInfoDao,
-            CpuStatDAO cpuStatDao, MemoryStatDAO memoryStatDao, HostRef ref) {
-        overviewController = new HostOverviewController(hostInfoDao, ref);
+            CpuStatDAO cpuStatDao, MemoryStatDAO memoryStatDao,
+            NetworkInterfaceInfoDAO networkInfoDao, HostRef ref) {
+        overviewController = new HostOverviewController(hostInfoDao, networkInfoDao, ref);
         cpuController = new HostCpuController(hostInfoDao, cpuStatDao, ref);
         memoryController = new HostMemoryController(hostInfoDao, memoryStatDao, ref);
     }
--- 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
@@ -286,6 +286,8 @@
                 daoFactory.registerDAOsAndStorageAsOSGiServices();
                 uiFacadeFactory.setHostInfoDao(daoFactory.getHostInfoDAO());
                 uiFacadeFactory.setCpuStatDao(daoFactory.getCpuStatDAO());
+                uiFacadeFactory.setMemoryStatDao(daoFactory.getMemoryStatDAO());
+                uiFacadeFactory.setNetworkInfoDao(daoFactory.getNetworkInterfaceInfoDAO());
 
                 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
@@ -54,6 +54,7 @@
 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.NetworkInterfaceInfoDAO;
 import com.redhat.thermostat.common.dao.VmRef;
 
 public class UiFacadeFactoryImpl implements UiFacadeFactory {
@@ -67,6 +68,7 @@
     private HostInfoDAO hostInfoDao;
     private CpuStatDAO cpuStatDao;
     private MemoryStatDAO memoryStatDao;
+    private NetworkInterfaceInfoDAO networkInfoDao;
 
     public UiFacadeFactoryImpl(BundleContext context) {
         this.context = context;
@@ -85,6 +87,10 @@
         this.memoryStatDao = memoryStatDao;
     }
 
+    public void setNetworkInfoDao(NetworkInterfaceInfoDAO networkInfoDao) {
+        this.networkInfoDao = networkInfoDao;
+    }
+
     @Override
     public MainWindowController getMainWindow() {
         MainView mainView = new MainWindow();
@@ -100,7 +106,7 @@
 
     @Override
     public HostInformationController getHostController(HostRef ref) {
-        return new HostInformationController(hostInfoDao, cpuStatDao, memoryStatDao, ref);
+        return new HostInformationController(hostInfoDao, cpuStatDao, memoryStatDao, networkInfoDao, 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
@@ -45,6 +45,7 @@
 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.NetworkInterfaceInfoDAO;
 
 public class HostInformationController {
 
@@ -55,8 +56,10 @@
     private final HostInformationView view;
 
     public HostInformationController(HostInfoDAO hostInfoDao,
-            CpuStatDAO cpuStatDao, MemoryStatDAO memoryStatDao, HostRef ref) {
-        overviewController = new HostOverviewController(hostInfoDao, ref);
+            CpuStatDAO cpuStatDao, MemoryStatDAO memoryStatDao,
+            NetworkInterfaceInfoDAO networkInfoDao, HostRef ref) {
+
+        overviewController = new HostOverviewController(hostInfoDao, networkInfoDao, ref);
         cpuController = new HostCpuController(hostInfoDao, cpuStatDao, ref);
         memoryController = new HostMemoryController(hostInfoDao, memoryStatDao, ref);
 
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/HostOverviewController.java	Wed Oct 03 18:05:54 2012 -0400
+++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/HostOverviewController.java	Wed Oct 03 18:05:54 2012 -0400
@@ -53,7 +53,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.HostInfoDAO;
 import com.redhat.thermostat.common.dao.HostRef;
 import com.redhat.thermostat.common.dao.NetworkInterfaceInfoDAO;
@@ -75,11 +74,11 @@
 
     private final HostOverviewView view;
 
-    public HostOverviewController(HostInfoDAO hostInfoDAO, final HostRef ref) {
+    public HostOverviewController(HostInfoDAO hostInfoDAO, NetworkInterfaceInfoDAO networkInfoDAO,
+            final HostRef ref) {
         this.ref = ref;
-        DAOFactory df = ApplicationContext.getInstance().getDAOFactory();
         this.hostInfoDAO = hostInfoDAO;
-        networkInfoDAO = df.getNetworkInterfaceInfoDAO();
+        this.networkInfoDAO = networkInfoDAO;
 
         final Vector<String> networkTableColumnVector;
         networkTableColumnVector = new Vector<String>();
@@ -102,7 +101,8 @@
                 String readableTotalMemory = localize(LocaleResources.NUMBER_AND_UNIT, parts[0], parts[1]);
                 view.setTotalMemory(readableTotalMemory);
 
-                List<NetworkInterfaceInfo> networkInfo = networkInfoDAO.getNetworkInterfaces(ref);
+                List<NetworkInterfaceInfo> networkInfo =
+                        HostOverviewController.this.networkInfoDAO.getNetworkInterfaces(ref);
 
                 boolean firstRun = knownNetworkIfaces.isEmpty();
                 if (firstRun) {
--- 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
@@ -44,6 +44,7 @@
 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.NetworkInterfaceInfoDAO;
 import com.redhat.thermostat.common.dao.VmRef;
 
 public interface UiFacadeFactory {
@@ -54,6 +55,8 @@
 
     void setMemoryStatDao(MemoryStatDAO memoryStatDAO);
 
+    void setNetworkInfoDao(NetworkInterfaceInfoDAO networkInterfaceInfoDAO);
+
     public MainWindowController getMainWindow();
 
     public SummaryController getSummary();
--- a/client/core/src/test/java/com/redhat/thermostat/client/ui/HostOverviewControllerTest.java	Wed Oct 03 18:05:54 2012 -0400
+++ b/client/core/src/test/java/com/redhat/thermostat/client/ui/HostOverviewControllerTest.java	Wed Oct 03 18:05:54 2012 -0400
@@ -63,7 +63,6 @@
 import com.redhat.thermostat.common.Timer.SchedulingType;
 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.NetworkInterfaceInfoDAO;
@@ -111,18 +110,12 @@
 
         HostRef ref = mock(HostRef.class);
 
-        DAOFactory daoFactory = mock(DAOFactory.class);
-
         HostInfoDAO hostInfoDao = mock(HostInfoDAO.class);
         when(hostInfoDao.getHostInfo(any(HostRef.class))).thenReturn(hostInfo);
 
         NetworkInterfaceInfoDAO networkInfoDao = mock(NetworkInterfaceInfoDAO.class);
         when(networkInfoDao.getNetworkInterfaces(any(HostRef.class))).thenReturn(networkInfo);
 
-        when(daoFactory.getNetworkInterfaceInfoDAO()).thenReturn(networkInfoDao);
-
-        ApplicationContext.getInstance().setDAOFactory(daoFactory);
-
         // Setup View
         ArgumentCaptor<ActionListener> listenerCaptor = ArgumentCaptor.forClass(ActionListener.class);
         view = mock(HostOverviewView.class);
@@ -132,7 +125,7 @@
 
         ApplicationContext.getInstance().setViewFactory(viewFactory);
 
-        HostOverviewController controller = new HostOverviewController(hostInfoDao, ref);
+        HostOverviewController controller = new HostOverviewController(hostInfoDao, networkInfoDao, ref);
 
         listener = listenerCaptor.getValue();
         timerAction = timerActionCaptor.getValue();