2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.sal.connection.implementation.internal;
12 import java.util.concurrent.ConcurrentHashMap;
13 import java.util.concurrent.ConcurrentMap;
14 import org.opendaylight.controller.sal.connection.ConnectionConstants;
15 import org.opendaylight.controller.sal.connection.ConnectionLocality;
16 import org.opendaylight.controller.sal.connection.IConnectionListener;
17 import org.opendaylight.controller.sal.connection.IConnectionService;
18 import org.opendaylight.controller.sal.connection.IPluginInConnectionService;
19 import org.opendaylight.controller.sal.connection.IPluginOutConnectionService;
20 import org.opendaylight.controller.sal.core.Node;
21 import org.opendaylight.controller.sal.utils.GlobalConstants;
22 import org.opendaylight.controller.sal.utils.Status;
23 import org.opendaylight.controller.sal.utils.StatusCode;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class ConnectionService implements IPluginOutConnectionService, IConnectionService {
28 protected static final Logger logger = LoggerFactory
29 .getLogger(ConnectionService.class);
30 private IConnectionListener connectionListener;
31 private ConcurrentMap<String, IPluginInConnectionService> pluginService =
32 new ConcurrentHashMap<String, IPluginInConnectionService>();
34 void setPluginService (Map<?, ?> props, IPluginInConnectionService s) {
36 Object value = props.get(GlobalConstants.PROTOCOLPLUGINTYPE.toString());
37 if (value instanceof String) {
38 type = (String) value;
41 logger.error("Received a PluginInConnectionService without any "
42 + "protocolPluginType provided");
44 this.pluginService.put(type, s);
48 void unsetPluginService(Map<?, ?> props, IPluginInConnectionService s) {
51 Object value = props.get(GlobalConstants.PROTOCOLPLUGINTYPE.toString());
52 if (value instanceof String) {
53 type = (String) value;
56 logger.error("Received a PluginInConnectionService without any "
57 + "protocolPluginType provided");
58 } else if (this.pluginService.get(type).equals(s)) {
59 this.pluginService.remove(type);
63 void setListener(IConnectionListener s) {
64 this.connectionListener = s;
67 void unsetListener(IConnectionListener s) {
68 if (this.connectionListener == s) {
69 this.connectionListener = null;
74 * Function called by the dependency manager when all the required
75 * dependencies are satisfied
82 * Function called by the dependency manager when at least one dependency
83 * become unsatisfied or when the component is shutting down because for
84 * example bundle is being stopped.
88 connectionListener = null;
89 if (this.pluginService != null) {
90 this.pluginService.clear();
95 * Method to test if a node is local to a controller.
97 * @return true if node is local to this controller. false otherwise.
99 public boolean isLocal(Node node) {
100 if (this.connectionListener == null) return false;
101 return connectionListener.isLocal(node);
105 public ConnectionLocality getLocalityStatus(Node node) {
106 if (this.connectionListener == null) {
107 return ConnectionLocality.NOT_CONNECTED;
109 return connectionListener.getLocalityStatus(node);
113 public Node connect (String type, String connectionIdentifier, Map<ConnectionConstants, String> params) {
114 IPluginInConnectionService s = pluginService.get(type);
116 return s.connect(connectionIdentifier, params);
122 public Node connect (String connectionIdentifier, Map<ConnectionConstants, String> params) {
123 synchronized (this.pluginService) {
124 for (String pluginType : this.pluginService.keySet()) {
125 IPluginInConnectionService s = pluginService.get(pluginType);
126 Node node = s.connect(connectionIdentifier, params);
136 public Status disconnect(Node node) {
137 IPluginInConnectionService s = pluginService.get(node.getType());
139 return s.disconnect(node);
141 return new Status(StatusCode.NOTFOUND);
145 * View Change notification
148 public void notifyClusterViewChanged() {
149 for (String pluginType : this.pluginService.keySet()) {
150 IPluginInConnectionService s = pluginService.get(pluginType);
151 s.notifyClusterViewChanged();
156 * Node Disconnected from the node's master controller.
159 public void notifyNodeDisconnectFromMaster(Node node) {
160 IPluginInConnectionService s = pluginService.get(node.getType());
162 s.notifyNodeDisconnectFromMaster(node);