Initial opendaylight infrastructure commit!!
[controller.git] / opendaylight / sal / implementation / src / main / java / org / opendaylight / controller / sal / implementation / internal / Topology.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.HashSet;
13 import java.util.Set;
14 import java.util.Collections;
15
16 import org.opendaylight.controller.sal.core.Edge;
17 import org.opendaylight.controller.sal.core.Property;
18 import org.opendaylight.controller.sal.core.UpdateType;
19 import org.opendaylight.controller.sal.topology.IListenTopoUpdates;
20 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
21 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
22 import org.opendaylight.controller.sal.topology.ITopologyService;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 public class Topology implements IPluginOutTopologyService, ITopologyService {
27     protected static final Logger logger = LoggerFactory
28             .getLogger(Topology.class);
29     private Set<IListenTopoUpdates> updateService = Collections
30             .synchronizedSet(new HashSet<IListenTopoUpdates>());
31     private Set<IPluginInTopologyService> pluginService = Collections
32             .synchronizedSet(new HashSet<IPluginInTopologyService>());
33
34     void setPluginService(IPluginInTopologyService s) {
35         if (this.pluginService != null) {
36             this.pluginService.add(s);
37         }
38     }
39
40     void unsetPluginService(IPluginInTopologyService s) {
41         if (this.pluginService != null) {
42             this.pluginService.remove(s);
43         }
44     }
45
46     void setUpdateService(IListenTopoUpdates s) {
47         if (this.updateService != null) {
48             this.updateService.add(s);
49         }
50     }
51
52     void unsetUpdateService(IListenTopoUpdates s) {
53         if (this.updateService != null) {
54             this.updateService.remove(s);
55         }
56     }
57
58     /**
59      * Function called by the dependency manager when all the required
60      * dependencies are satisfied
61      *
62      */
63     void init() {
64     }
65
66     /**
67      * Function called by the dependency manager when at least one
68      * dependency become unsatisfied or when the component is shutting
69      * down because for example bundle is being stopped.
70      *
71      */
72     void destroy() {
73         // Make sure to clear all the data structure we use to track
74         // services
75         if (this.updateService != null) {
76             this.updateService.clear();
77         }
78         if (this.pluginService != null) {
79             this.pluginService.clear();
80         }
81     }
82
83     @Override
84     public void sollicitRefresh() {
85         synchronized (this.pluginService) {
86             for (IPluginInTopologyService s : this.pluginService) {
87                 s.sollicitRefresh();
88             }
89         }
90     }
91
92     @Override
93     public void edgeUpdate(Edge e, UpdateType type, Set<Property> props) {
94         synchronized (this.updateService) {
95             for (IListenTopoUpdates s : this.updateService) {
96                 s.edgeUpdate(e, type, props);
97             }
98         }
99     }
100
101     @Override
102     public void edgeOverUtilized(Edge edge) {
103         synchronized (this.updateService) {
104             for (IListenTopoUpdates s : this.updateService) {
105                 s.edgeOverUtilized(edge);
106             }
107         }
108     }
109
110     @Override
111     public void edgeUtilBackToNormal(Edge edge) {
112         synchronized (this.updateService) {
113             for (IListenTopoUpdates s : this.updateService) {
114                 s.edgeUtilBackToNormal(edge);
115             }
116         }
117     }
118 }