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