Merge "Adding some more traces for better debuggability"
[controller.git] / opendaylight / connectionmanager / implementation / src / main / java / org / opendaylight / controller / connectionmanager / scheme / AbstractScheme.java
index 062fd1ee777564aa1a90863e3826ef7648e12454..68d1b233b2ebe7c71663f4341983a98e9938ccc1 100644 (file)
@@ -1,7 +1,15 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.controller.connectionmanager.scheme;
 
 import java.net.InetAddress;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.EnumSet;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -14,8 +22,8 @@ import org.opendaylight.controller.clustering.services.CacheConfigException;
 import org.opendaylight.controller.clustering.services.CacheExistException;
 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
 import org.opendaylight.controller.clustering.services.IClusterServices;
-import org.opendaylight.controller.connectionmanager.ConnectionLocality;
 import org.opendaylight.controller.connectionmanager.ConnectionMgmtScheme;
+import org.opendaylight.controller.sal.connection.ConnectionLocality;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.utils.Status;
 import org.opendaylight.controller.sal.utils.StatusCode;
@@ -46,7 +54,7 @@ public abstract class AbstractScheme {
             allocateCaches();
             retrieveCaches();
         } else {
-            log.error("Couldn't retrieve caches for scheme %s. Clustering service unavailable", name);
+            log.error("Couldn't retrieve caches for scheme {}. Clustering service unavailable", name);
         }
     }
 
@@ -134,7 +142,7 @@ public abstract class AbstractScheme {
 
     public Set<InetAddress> getControllers(Node node) {
         if (nodeConnections != null) return nodeConnections.get(node);
-        return null;
+        return Collections.emptySet();
     }
 
     public ConcurrentMap<Node, Set<InetAddress>> getNodeConnections() {
@@ -276,6 +284,11 @@ public abstract class AbstractScheme {
 
     public Status addNode (Node node, InetAddress controller) {
         if (node == null || controller == null) {
+            if (node == null) {
+                log.warn("addNode: node is null");
+            } else if (controller == null) {
+                log.error("Failed to add node {}. The controller address retrieved from clusterServices is null.", node);
+            }
             return new Status(StatusCode.BADREQUEST);
         }
         if (isLocal(node))  {
@@ -322,4 +335,56 @@ public abstract class AbstractScheme {
             log.error("An error occured",e);
         }
     }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        result = prime * result + ((nodeConnections == null) ? 0 : nodeConnections.hashCode());
+        result = prime * result + ((nodeConnectionsCacheName == null) ? 0 : nodeConnectionsCacheName.hashCode());
+        return result;
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (!(obj instanceof AbstractScheme)) {
+            return false;
+        }
+        AbstractScheme other = (AbstractScheme) obj;
+        if (name == null) {
+            if (other.name != null) {
+                return false;
+            }
+        } else if (!name.equals(other.name)) {
+            return false;
+        }
+        if (nodeConnections == null) {
+            if (other.nodeConnections != null) {
+                return false;
+            }
+        } else if (!nodeConnections.equals(other.nodeConnections)) {
+            return false;
+        }
+        if (nodeConnectionsCacheName == null) {
+            if (other.nodeConnectionsCacheName != null) {
+                return false;
+            }
+        } else if (!nodeConnectionsCacheName.equals(other.nodeConnectionsCacheName)) {
+            return false;
+        }
+        return true;
+    }
 }