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;
13 import java.util.ArrayList;
14 import java.util.Collection;
15 import java.util.List;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
18 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
19 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
20 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
21 import org.opendaylight.groupbasedpolicy.util.IidFactory;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
24 import org.opendaylight.yangtools.concepts.ListenerRegistration;
26 public class EndpointManagerListener implements AutoCloseable {
28 private final List<ListenerRegistration<?>> listenerRegistrations = new ArrayList<>();
29 private final EndpointManager endpointManager;
31 public EndpointManagerListener(DataBroker dataProvider, EndpointManager endpointManager) {
32 this.endpointManager = checkNotNull(endpointManager);
33 checkNotNull(dataProvider);
35 listenerRegistrations.add(dataProvider.registerDataTreeChangeListener(new DataTreeIdentifier<>(
36 LogicalDatastoreType.OPERATIONAL, IidFactory.endpointsIidWildcard().child(Endpoint.class)),
37 changes -> onEndpointChanged(changes)));
39 listenerRegistrations.add(dataProvider.registerDataTreeChangeListener(new DataTreeIdentifier<>(
40 LogicalDatastoreType.OPERATIONAL, IidFactory.endpointsIidWildcard().child(EndpointL3.class)),
41 changes -> onEndpointL3Changed(changes)));
44 private void onEndpointChanged(Collection<DataTreeModification<Endpoint>> changes) {
45 for (DataTreeModification<Endpoint> change: changes) {
46 DataObjectModification<Endpoint> rootNode = change.getRootNode();
47 switch (rootNode.getModificationType()) {
48 case SUBTREE_MODIFIED:
50 endpointManager.processEndpoint(rootNode.getDataBefore(), rootNode.getDataAfter());
53 endpointManager.processEndpoint(rootNode.getDataBefore(), null);
61 private void onEndpointL3Changed(Collection<DataTreeModification<EndpointL3>> changes) {
62 for (DataTreeModification<EndpointL3> change: changes) {
63 DataObjectModification<EndpointL3> rootNode = change.getRootNode();
64 switch (rootNode.getModificationType()) {
65 case SUBTREE_MODIFIED:
67 endpointManager.processL3Endpoint(rootNode.getDataBefore(), rootNode.getDataAfter());
70 endpointManager.processL3Endpoint(rootNode.getDataBefore(), null);
80 for (ListenerRegistration<?> reg: listenerRegistrations) {