Porting Tristate logic to SAL Connection Service and make use of it in Inventory...
[controller.git] / opendaylight / connectionmanager / implementation / src / main / java / org / opendaylight / controller / connectionmanager / internal / ConnectionManager.java
index 9cbddbb13046202e482a6765c810bfd4e3507bd3..1beb7fe0bb609860865ed52347f27bfe126aeb2e 100644 (file)
@@ -30,8 +30,6 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.LinkedBlockingQueue;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.eclipse.osgi.framework.console.CommandInterpreter;
 import org.eclipse.osgi.framework.console.CommandProvider;
 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
@@ -42,6 +40,7 @@ import org.opendaylight.controller.connectionmanager.IConnectionManager;
 import org.opendaylight.controller.connectionmanager.scheme.AbstractScheme;
 import org.opendaylight.controller.connectionmanager.scheme.SchemeFactory;
 import org.opendaylight.controller.sal.connection.ConnectionConstants;
+import org.opendaylight.controller.sal.connection.ConnectionLocality;
 import org.opendaylight.controller.sal.connection.IConnectionListener;
 import org.opendaylight.controller.sal.connection.IConnectionService;
 import org.opendaylight.controller.sal.core.Node;
@@ -54,6 +53,8 @@ import org.opendaylight.controller.sal.utils.Status;
 import org.opendaylight.controller.sal.utils.StatusCode;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.FrameworkUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ConnectionManager implements IConnectionManager, IConnectionListener,
                                           ICoordinatorChangeAware, IListenInventoryUpdates,
@@ -122,8 +123,19 @@ public class ConnectionManager implements IConnectionManager, IConnectionListene
         }
     }
 
-    public void started() {
-        connectionEventThread = new Thread(new EventHandler(), "ConnectionEvent Thread");
+
+   public void started() {
+       String schemeStr = System.getProperty("connection.scheme");
+       for (ConnectionMgmtScheme scheme : ConnectionMgmtScheme.values()) {
+           AbstractScheme schemeImpl = SchemeFactory.getScheme(scheme, clusterServices);
+           if (schemeImpl != null) {
+               schemes.put(scheme, schemeImpl);
+               if (scheme.name().equalsIgnoreCase(schemeStr)) {
+                   activeScheme = scheme;
+               }
+           }
+       }
+
         connectionEventThread.start();
 
         registerWithOSGIConsole();
@@ -133,15 +145,12 @@ public class ConnectionManager implements IConnectionManager, IConnectionListene
     }
 
     public void init() {
+        connectionEventThread = new Thread(new EventHandler(), "ConnectionEvent Thread");
         this.connectionEvents = new LinkedBlockingQueue<ConnectionMgmtEvent>();
         schemes = new ConcurrentHashMap<ConnectionMgmtScheme, AbstractScheme>();
-        for (ConnectionMgmtScheme scheme : ConnectionMgmtScheme.values()) {
-            AbstractScheme schemeImpl = SchemeFactory.getScheme(scheme, clusterServices);
-            if (schemeImpl != null) schemes.put(scheme, schemeImpl);
-        }
     }
 
-    public void stop() {
+    public void stopping() {
         connectionEventThread.interrupt();
         Set<Node> localNodes = getLocalNodes();
         if (localNodes != null) {
@@ -179,6 +188,13 @@ public class ConnectionManager implements IConnectionManager, IConnectionListene
         return scheme.isLocal(node);
     }
 
+    @Override
+    public ConnectionLocality getLocalityStatus(Node node) {
+        AbstractScheme scheme = schemes.get(activeScheme);
+        if (scheme == null) return ConnectionLocality.NOT_CONNECTED;
+        return scheme.getLocalityStatus(node);
+    }
+
     @Override
     public void updateNode(Node node, UpdateType type, Set<Property> props) {
         logger.debug("updateNode: {} type {} props {}", node, type, props);
@@ -352,16 +368,21 @@ public class ConnectionManager implements IConnectionManager, IConnectionListene
         String controller = ci.nextArgument();
         if (controller == null) {
             ci.println("Nodes connected to this controller : ");
-            if (this.getLocalNodes() == null) ci.println("None");
-            else ci.println(this.getLocalNodes().toString());
+            if (this.getLocalNodes() == null) {
+                ci.println("None");
+            } else {
+                ci.println(this.getLocalNodes().toString());
+            }
             return;
         }
         try {
             InetAddress address = InetAddress.getByName(controller);
             ci.println("Nodes connected to controller "+controller);
-            if (this.getNodes(address) == null) ci.println("None");
-            else ci.println(this.getNodes(address).toString());
-            return;
+            if (this.getNodes(address) == null) {
+                ci.println("None");
+            } else {
+                ci.println(this.getNodes(address).toString());
+            }
         } catch (UnknownHostException e) {
            logger.error("An error occured",e);
         }