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