Initial opendaylight infrastructure commit!!
[controller.git] / opendaylight / sal / implementation / src / main / java / org / opendaylight / controller / sal / implementation / internal / Inventory.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
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
8  */
9
10 package org.opendaylight.controller.sal.implementation.internal;
11
12 import java.util.Map;
13 import java.util.Set;
14 import java.util.concurrent.ConcurrentMap;
15
16 import org.opendaylight.controller.sal.core.Node;
17 import org.opendaylight.controller.sal.core.NodeConnector;
18 import org.opendaylight.controller.sal.core.Property;
19 import org.opendaylight.controller.sal.core.UpdateType;
20 import org.opendaylight.controller.sal.inventory.IInventoryService;
21 import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
22 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
23 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28  * The class describes SAL service to bridge inventory protocol plugin and upper
29  * applications. One instance per container of the network.
30  */
31 public class Inventory implements IPluginOutInventoryService, IInventoryService {
32     protected static final Logger logger = LoggerFactory
33             .getLogger(Inventory.class);
34     private IListenInventoryUpdates updateService = null;
35     private IPluginInInventoryService pluginService = null;
36
37     /**
38      * Function called by the dependency manager when all the required
39      * dependencies are satisfied
40      *
41      */
42     void init() {
43         logger.trace("INIT called!");
44     }
45
46     /**
47      * Function called by the dependency manager when at least one
48      * dependency become unsatisfied or when the component is shutting
49      * down because for example bundle is being stopped.
50      *
51      */
52     void destroy() {
53         logger.trace("DESTROY called!");
54     }
55
56     /**
57      * Function called by dependency manager after "init ()" is called
58      * and after the services provided by the class are registered in
59      * the service registry
60      *
61      */
62     void start() {
63         logger.trace("START called!");
64
65         if (pluginService == null) {
66             logger.debug("plugin service not avaiable");
67             return;
68         }
69     }
70
71     /**
72      * Function called by the dependency manager before the services
73      * exported by the component are unregistered, this will be
74      * followed by a "destroy ()" calls
75      *
76      */
77     void stop() {
78         logger.trace("STOP called!");
79     }
80
81     public void setPluginService(IPluginInInventoryService service) {
82         logger.trace("Got plugin service set request {}", service);
83         this.pluginService = service;
84     }
85
86     public void unsetPluginService(IPluginInInventoryService service) {
87         logger.trace("Got plugin service UNset request");
88         this.pluginService = null;
89     }
90
91     public void setUpdateService(IListenInventoryUpdates service) {
92         logger.trace("Got update service set request {}", service);
93         this.updateService = service;
94     }
95
96     public void unsetUpdateService(IListenInventoryUpdates service) {
97         logger.trace("Got a service UNset request");
98         this.updateService = null;
99     }
100
101     @Override
102     public void updateNode(Node node, UpdateType type, Set<Property> props) {
103         logger.trace("{} {}", node, type);
104         if (updateService != null) {
105             updateService.updateNode(node, type, props);
106         }
107     }
108
109     @Override
110     public void updateNodeConnector(NodeConnector nodeConnector,
111             UpdateType type, Set<Property> props) {
112         logger.trace("{} {}", nodeConnector, type);
113
114         if ((updateService != null) && (type != null)) {
115             updateService.updateNodeConnector(nodeConnector, type, props);
116         }
117     }
118
119     @Override
120     public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
121         if (pluginService != null)
122             return pluginService.getNodeProps();
123         else
124             return null;
125     }
126
127     @Override
128     public ConcurrentMap<NodeConnector, Map<String, Property>> getNodeConnectorProps() {
129         if (pluginService != null)
130             return pluginService.getNodeConnectorProps(true);
131         else
132             return null;
133     }
134 }