2 * Copyright (c) 2016 Cisco Systems 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.dsbenchmark.listener;
11 import java.util.Collection;
12 import java.util.concurrent.atomic.AtomicInteger;
14 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
15 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
16 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
17 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec;
19 import org.opendaylight.yangtools.yang.binding.DataObject;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 public class DsbenchmarkListener implements DataTreeChangeListener<TestExec> {
25 private static final Logger LOG = LoggerFactory.getLogger(DsbenchmarkListener.class);
26 private AtomicInteger numEvents = new AtomicInteger(0);
29 public void onDataTreeChanged(
30 Collection<DataTreeModification<TestExec>> changes) {
31 // Since we're registering the same DsbenchmarkListener object for both
32 // OPERATIONAL and CONFIG, the onDataTreeChanged() method can be called
33 // from different threads, and we need to use atomic counters.
35 final int eventNum = numEvents.incrementAndGet();
36 if(LOG.isDebugEnabled()){
37 logDataTreeChangeEvent(eventNum, changes);
41 private static synchronized void logDataTreeChangeEvent(int eventNum,
42 Collection<DataTreeModification<TestExec>> changes) {
43 LOG.debug("DsbenchmarkListener-onDataTreeChanged: Event {}", eventNum);
45 for(DataTreeModification<TestExec> change : changes) {
46 final DataObjectModification<TestExec> rootNode = change.getRootNode();
47 final ModificationType modType = rootNode.getModificationType();
48 final PathArgument changeId = rootNode.getIdentifier();
49 final Collection<DataObjectModification<? extends DataObject>> modifications = rootNode.getModifiedChildren();
51 LOG.debug(" changeId {}, modType {}, mods: {}", changeId, modType, modifications.size());
53 for (DataObjectModification<? extends DataObject> mod : modifications) {
54 LOG.debug(" mod-getDataAfter: {}", mod.getDataAfter());
59 public int getNumEvents() {
60 return numEvents.get();