3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.sal.implementation.internal;
12 import java.util.HashSet;
13 import java.util.List;
16 import java.util.concurrent.ConcurrentHashMap;
17 import java.util.concurrent.ConcurrentMap;
18 import java.util.concurrent.CopyOnWriteArrayList;
20 import org.opendaylight.controller.sal.core.Node;
21 import org.opendaylight.controller.sal.core.NodeConnector;
22 import org.opendaylight.controller.sal.core.Property;
23 import org.opendaylight.controller.sal.core.UpdateType;
24 import org.opendaylight.controller.sal.inventory.IInventoryService;
25 import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
26 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
27 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * The class describes SAL service to bridge inventory protocol plugin and upper
33 * applications. One instance per container of the network.
35 public class Inventory implements IPluginOutInventoryService, IInventoryService {
36 protected static final Logger logger = LoggerFactory
37 .getLogger(Inventory.class);
38 private List<IListenInventoryUpdates> updateService = new CopyOnWriteArrayList<IListenInventoryUpdates>();
39 private List<IPluginInInventoryService> pluginService = new CopyOnWriteArrayList<IPluginInInventoryService>();
42 * Function called by the dependency manager when all the required
43 * dependencies are satisfied
47 logger.trace("INIT called!");
51 * Function called by the dependency manager when at least one
52 * dependency become unsatisfied or when the component is shutting
53 * down because for example bundle is being stopped.
57 logger.trace("DESTROY called!");
61 * Function called by dependency manager after "init ()" is called
62 * and after the services provided by the class are registered in
63 * the service registry
67 logger.trace("START called!");
69 if (pluginService == null) {
70 logger.debug("plugin service not avaiable");
76 * Function called by the dependency manager before the services
77 * exported by the component are unregistered, this will be
78 * followed by a "destroy ()" calls
82 logger.trace("STOP called!");
85 public void setPluginService(IPluginInInventoryService service) {
86 logger.trace("Got plugin service set request {}", service);
87 this.pluginService.add(service);
90 public void unsetPluginService(IPluginInInventoryService service) {
91 logger.trace("Got plugin service UNset request");
92 this.pluginService.remove(service);
95 public void setUpdateService(IListenInventoryUpdates service) {
96 logger.trace("Got update service set request {}", service);
97 this.updateService.add(service);
100 public void unsetUpdateService(IListenInventoryUpdates service) {
101 logger.trace("Got a service UNset request");
102 this.updateService.remove(service);
106 public void updateNode(Node node, UpdateType type, Set<Property> props) {
108 logger.trace("Input type is null");
112 logger.trace("{} {}", node, type);
114 for (IListenInventoryUpdates s : this.updateService) {
115 s.updateNode(node, type, props);
120 public void updateNodeConnector(NodeConnector nodeConnector,
121 UpdateType type, Set<Property> props) {
123 logger.trace("Input type is null");
127 logger.trace("{} {}", nodeConnector, type);
129 for (IListenInventoryUpdates s : this.updateService) {
130 s.updateNodeConnector(nodeConnector, type, props);
135 public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
136 ConcurrentMap<Node, Map<String, Property>> nodeProps =
137 new ConcurrentHashMap<Node, Map<String, Property>>(), rv;
139 for (IPluginInInventoryService s : this.pluginService) {
140 rv = s.getNodeProps();
142 nodeProps.putAll(rv);
150 public Set<Node> getConfiguredNotConnectedNodes() {
151 Set<Node> configuredNotConnected = new HashSet<Node>(), rv;
152 for (IPluginInInventoryService s : this.pluginService) {
153 rv = s.getConfiguredNotConnectedNodes();
155 configuredNotConnected.addAll(rv);
158 return configuredNotConnected;
162 public ConcurrentMap<NodeConnector, Map<String, Property>> getNodeConnectorProps() {
163 ConcurrentMap<NodeConnector, Map<String, Property>> ncProps =
164 new ConcurrentHashMap<NodeConnector, Map<String, Property>>(), rv;
166 for (IPluginInInventoryService s : this.pluginService) {
167 rv = s.getNodeConnectorProps(true);