1 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint;
3 import static com.google.common.base.Preconditions.checkNotNull;
7 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
8 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
9 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
10 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
11 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
12 import org.opendaylight.groupbasedpolicy.util.IidFactory;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Prefix;
16 import org.opendaylight.yangtools.concepts.ListenerRegistration;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 public class EndpointManagerListener implements DataChangeListener, AutoCloseable {
22 private final ListenerRegistration<DataChangeListener> registerListener;
23 private final EndpointManager endpointManager;
25 public EndpointManagerListener(DataBroker dataProvider, EndpointManager endpointManager) {
26 this.endpointManager = checkNotNull(endpointManager);
27 this.registerListener = checkNotNull(dataProvider).registerDataChangeListener(
28 LogicalDatastoreType.OPERATIONAL, IidFactory.endpointsIidWildcard(), this, AsyncDataBroker.DataChangeScope.SUBTREE);
32 public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
34 for (DataObject dao : change.getCreatedData().values()) {
35 if (dao instanceof Endpoint) {
36 endpointManager.processEndpoint(null, (Endpoint) dao);
37 } else if (dao instanceof EndpointL3) {
38 endpointManager.processL3Endpoint(null, (EndpointL3) dao);
39 } else if (dao instanceof EndpointL3Prefix) {
40 //noinspection UnnecessaryContinue
45 Map<InstanceIdentifier<?>, DataObject> dao = change.getUpdatedData();
46 for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : dao.entrySet()) {
47 if (entry.getValue() instanceof Endpoint) {
48 Endpoint oldEp = (Endpoint) change.getOriginalData().get(entry.getKey());
49 endpointManager.processEndpoint(oldEp, (Endpoint) entry.getValue());
50 } else if (entry.getValue() instanceof EndpointL3) {
51 EndpointL3 oldEp3 = (EndpointL3) change.getOriginalData().get(entry.getKey());
52 endpointManager.processL3Endpoint(oldEp3, (EndpointL3) entry.getValue());
53 } else if (entry.getValue() instanceof EndpointL3Prefix) {
54 //noinspection UnnecessaryContinue
59 for (InstanceIdentifier<?> iid : change.getRemovedPaths()) {
60 DataObject old = change.getOriginalData().get(iid);
64 if (old instanceof Endpoint) {
65 endpointManager.processEndpoint((Endpoint) old, null);
66 } else if (old instanceof EndpointL3) {
67 endpointManager.processL3Endpoint((EndpointL3) old, null);
68 } else if (old instanceof EndpointL3Prefix) {
69 //noinspection UnnecessaryContinue
76 public void close() throws Exception {
77 if (registerListener != null)
78 registerListener.close();