2 * Copyright (c) 2015 Brocade Communications 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
8 package org.opendaylight.ovsdb.southbound.ovsdb.transact;
10 import java.util.HashMap;
11 import java.util.HashSet;
14 import java.util.Map.Entry;
16 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 public class DataChangesTerminationPointEvent implements AsyncDataChangeEvent<InstanceIdentifier<?>,
22 OvsdbTerminationPointAugmentation> {
24 private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event;
25 private InstanceIdentifier<?> iid;
27 // local caches of computed data
28 private Map<InstanceIdentifier<?>, OvsdbTerminationPointAugmentation> createdData = null;
29 private Map<InstanceIdentifier<?>, OvsdbTerminationPointAugmentation> updatedData = null;
30 private Set<InstanceIdentifier<?>> removedPaths = null;
31 private Map<InstanceIdentifier<?>, OvsdbTerminationPointAugmentation> originalData;
33 public DataChangesTerminationPointEvent(InstanceIdentifier<?> iid,
34 AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event) {
39 private Map<InstanceIdentifier<?>, OvsdbTerminationPointAugmentation> filter(Map<InstanceIdentifier<?>,
41 Map<InstanceIdentifier<?>, OvsdbTerminationPointAugmentation> result
42 = new HashMap<InstanceIdentifier<?>, OvsdbTerminationPointAugmentation>();
43 for (Entry<InstanceIdentifier<?>, DataObject> created: data.entrySet()) {
44 if (created.getValue() != null
45 && created.getValue() instanceof OvsdbTerminationPointAugmentation
46 && ((OvsdbTerminationPointAugmentation)created.getValue()).getAttachedTo() != null
47 && ((OvsdbTerminationPointAugmentation)created.getValue()).getAttachedTo().getValue() != null) {
48 result.put(created.getKey(),((OvsdbTerminationPointAugmentation)created.getValue()));
55 public Map<InstanceIdentifier<?>, OvsdbTerminationPointAugmentation> getCreatedData() {
56 if (this.createdData == null) {
57 this.createdData = filter(event.getCreatedData());
59 return this.createdData;
63 public Map<InstanceIdentifier<?>, OvsdbTerminationPointAugmentation> getUpdatedData() {
64 if (this.updatedData == null) {
65 this.updatedData = filter(event.getUpdatedData());
67 return this.updatedData;
71 public Set<InstanceIdentifier<?>> getRemovedPaths() {
72 if (this.removedPaths != null) {
73 this.removedPaths = new HashSet<InstanceIdentifier<?>>();
74 for (InstanceIdentifier<?> path: event.getRemovedPaths()) {
75 DataObject original = this.event.getOriginalData().get(path);
77 && original instanceof OvsdbTerminationPointAugmentation) {
78 this.removedPaths.add(path);
82 return this.removedPaths;
86 public Map<InstanceIdentifier<?>, OvsdbTerminationPointAugmentation> getOriginalData() {
87 if (this.originalData == null) {
88 this.originalData = filter(event.getOriginalData());
90 return this.originalData;
94 public OvsdbTerminationPointAugmentation getOriginalSubtree() {
95 if (this.event.getOriginalSubtree() instanceof OvsdbTerminationPointAugmentation) {
96 return (OvsdbTerminationPointAugmentation)this.event.getOriginalSubtree();
103 public OvsdbTerminationPointAugmentation getUpdatedSubtree() {
104 if (this.event.getUpdatedSubtree() instanceof OvsdbTerminationPointAugmentation) {
105 return (OvsdbTerminationPointAugmentation)this.event.getUpdatedSubtree();