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.List;
15 import java.util.concurrent.ConcurrentHashMap;
16 import java.util.concurrent.ConcurrentMap;
17 import java.util.concurrent.CopyOnWriteArrayList;
19 import org.opendaylight.controller.sal.core.Node;
20 import org.opendaylight.controller.sal.core.NodeConnector;
21 import org.opendaylight.controller.sal.core.Property;
22 import org.opendaylight.controller.sal.core.UpdateType;
23 import org.opendaylight.controller.sal.inventory.IInventoryService;
24 import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
25 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
26 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * The class describes SAL service to bridge inventory protocol plugin and upper
32 * applications. One instance per container of the network.
34 public class Inventory implements IPluginOutInventoryService, IInventoryService {
35 protected static final Logger logger = LoggerFactory
36 .getLogger(Inventory.class);
37 private List<IListenInventoryUpdates> updateService = new CopyOnWriteArrayList<IListenInventoryUpdates>();
38 private List<IPluginInInventoryService> pluginService = new CopyOnWriteArrayList<IPluginInInventoryService>();
41 * Function called by the dependency manager when all the required
42 * dependencies are satisfied
46 logger.trace("INIT called!");
50 * Function called by the dependency manager when at least one
51 * dependency become unsatisfied or when the component is shutting
52 * down because for example bundle is being stopped.
56 logger.trace("DESTROY called!");
60 * Function called by dependency manager after "init ()" is called
61 * and after the services provided by the class are registered in
62 * the service registry
66 logger.trace("START called!");
68 if (pluginService == null) {
69 logger.debug("plugin service not avaiable");
75 * Function called by the dependency manager before the services
76 * exported by the component are unregistered, this will be
77 * followed by a "destroy ()" calls
81 logger.trace("STOP called!");
84 public void setPluginService(IPluginInInventoryService service) {
85 logger.trace("Got plugin service set request {}", service);
86 this.pluginService.add(service);
89 public void unsetPluginService(IPluginInInventoryService service) {
90 logger.trace("Got plugin service UNset request");
91 this.pluginService.remove(service);
94 public void setUpdateService(IListenInventoryUpdates service) {
95 logger.trace("Got update service set request {}", service);
96 this.updateService.add(service);
99 public void unsetUpdateService(IListenInventoryUpdates service) {
100 logger.trace("Got a service UNset request");
101 this.updateService.remove(service);
105 public void updateNode(Node node, UpdateType type, Set<Property> props) {
107 logger.trace("Input type is null");
111 logger.trace("{} {}", node, type);
113 for (IListenInventoryUpdates s : this.updateService) {
114 s.updateNode(node, type, props);
119 public void updateNodeConnector(NodeConnector nodeConnector,
120 UpdateType type, Set<Property> props) {
122 logger.trace("Input type is null");
126 logger.trace("{} {}", nodeConnector, type);
128 for (IListenInventoryUpdates s : this.updateService) {
129 s.updateNodeConnector(nodeConnector, type, props);
134 public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
135 ConcurrentMap<Node, Map<String, Property>> nodeProps =
136 new ConcurrentHashMap<Node, Map<String, Property>>(), rv;
138 for (IPluginInInventoryService s : this.pluginService) {
139 rv = s.getNodeProps();
141 nodeProps.putAll(rv);
149 public ConcurrentMap<NodeConnector, Map<String, Property>> getNodeConnectorProps() {
150 ConcurrentMap<NodeConnector, Map<String, Property>> ncProps =
151 new ConcurrentHashMap<NodeConnector, Map<String, Property>>(), rv;
153 for (IPluginInInventoryService s : this.pluginService) {
154 rv = s.getNodeConnectorProps(true);