2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint;
11 import static com.google.common.base.Preconditions.checkNotNull;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
17 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
18 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
19 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
20 import org.opendaylight.groupbasedpolicy.util.IidFactory;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Prefix;
24 import org.opendaylight.yangtools.concepts.ListenerRegistration;
25 import org.opendaylight.yangtools.yang.binding.DataObject;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 public class EndpointManagerListener implements DataChangeListener, AutoCloseable {
30 private final ListenerRegistration<DataChangeListener> registerListener;
31 private final EndpointManager endpointManager;
33 public EndpointManagerListener(DataBroker dataProvider, EndpointManager endpointManager) {
34 this.endpointManager = checkNotNull(endpointManager);
35 this.registerListener = checkNotNull(dataProvider).registerDataChangeListener(
36 LogicalDatastoreType.OPERATIONAL, IidFactory.endpointsIidWildcard(), this, AsyncDataBroker.DataChangeScope.SUBTREE);
40 public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
42 for (DataObject dao : change.getCreatedData().values()) {
43 if (dao instanceof Endpoint) {
44 endpointManager.processEndpoint(null, (Endpoint) dao);
45 } else if (dao instanceof EndpointL3) {
46 endpointManager.processL3Endpoint(null, (EndpointL3) dao);
47 } else if (dao instanceof EndpointL3Prefix) {
48 //noinspection UnnecessaryContinue
53 Map<InstanceIdentifier<?>, DataObject> dao = change.getUpdatedData();
54 for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : dao.entrySet()) {
55 if (entry.getValue() instanceof Endpoint) {
56 Endpoint oldEp = (Endpoint) change.getOriginalData().get(entry.getKey());
57 endpointManager.processEndpoint(oldEp, (Endpoint) entry.getValue());
58 } else if (entry.getValue() instanceof EndpointL3) {
59 EndpointL3 oldEp3 = (EndpointL3) change.getOriginalData().get(entry.getKey());
60 endpointManager.processL3Endpoint(oldEp3, (EndpointL3) entry.getValue());
61 } else if (entry.getValue() instanceof EndpointL3Prefix) {
62 //noinspection UnnecessaryContinue
67 for (InstanceIdentifier<?> iid : change.getRemovedPaths()) {
68 DataObject old = change.getOriginalData().get(iid);
72 if (old instanceof Endpoint) {
73 endpointManager.processEndpoint((Endpoint) old, null);
74 } else if (old instanceof EndpointL3) {
75 endpointManager.processL3Endpoint((EndpointL3) old, null);
76 } else if (old instanceof EndpointL3Prefix) {
77 //noinspection UnnecessaryContinue
84 public void close() throws Exception {
85 if (registerListener != null)
86 registerListener.close();