d80911a46533b39b63c075026c89f1352b0c4475
[controller.git] / opendaylight / connectionmanager / implementation / src / main / java / org / opendaylight / controller / connectionmanager / scheme / SingleControllerScheme.java
1 package org.opendaylight.controller.connectionmanager.scheme;
2
3 import java.net.InetAddress;
4 import java.util.Set;
5 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
6 import org.opendaylight.controller.connectionmanager.ConnectionMgmtScheme;
7 import org.opendaylight.controller.sal.core.Node;
8
9 class SingleControllerScheme extends AbstractScheme {
10
11     private static AbstractScheme myScheme= null;
12
13     protected SingleControllerScheme(IClusterGlobalServices clusterServices) {
14         super(clusterServices, ConnectionMgmtScheme.SINGLE_CONTROLLER);
15     }
16
17     public static AbstractScheme getScheme(IClusterGlobalServices clusterServices) {
18         if (myScheme == null) {
19             myScheme = new SingleControllerScheme(clusterServices);
20         }
21         return myScheme;
22     }
23
24     @SuppressWarnings("deprecation")
25     @Override
26     public boolean isConnectionAllowedInternal(Node node) {
27         if (nodeConnections == null) return true;
28         for (Node existingNode : nodeConnections.keySet()) {
29             Set<InetAddress> controllers = nodeConnections.get(existingNode);
30             if (controllers == null || controllers.size() == 0) continue;
31             if (!controllers.contains(clusterServices.getMyAddress())) return false;
32         }
33         return true;
34     }
35 }