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
8 package org.opendaylight.dsbenchmark.listener;
10 import java.util.List;
11 import java.util.concurrent.atomic.AtomicInteger;
12 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
13 import org.opendaylight.mdsal.binding.api.DataTreeModification;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.TestExec;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 public class DsbenchmarkListener implements DataTreeChangeListener<TestExec> {
19 private static final Logger LOG = LoggerFactory.getLogger(DsbenchmarkListener.class);
20 private final AtomicInteger numEvents = new AtomicInteger(0);
21 private final AtomicInteger numDataChanges = new AtomicInteger(0);
24 public void onDataTreeChanged(final List<DataTreeModification<TestExec>> changes) {
25 // Since we're registering the same DsbenchmarkListener object for both
26 // OPERATIONAL and CONFIG, the onDataTreeChanged() method can be called
27 // from different threads, and we need to use atomic counters.
29 final int eventNum = numEvents.incrementAndGet();
30 numDataChanges.addAndGet(changes.size());
32 if (LOG.isDebugEnabled()) {
33 logDataTreeChangeEvent(eventNum, changes);
37 private static synchronized void logDataTreeChangeEvent(final int eventNum,
38 final List<DataTreeModification<TestExec>> changes) {
39 LOG.debug("DsbenchmarkListener-onDataTreeChanged: Event {}", eventNum);
41 for (var change : changes) {
42 final var rootNode = change.getRootNode();
43 final var modType = rootNode.modificationType();
44 final var changeId = rootNode.step();
45 final var modifications = rootNode.modifiedChildren();
47 LOG.debug(" changeId {}, modType {}, mods: {}", changeId, modType, modifications.size());
49 for (var mod : modifications) {
50 LOG.debug(" mod-getDataAfter: {}", mod.dataAfter());
55 public int getNumEvents() {
56 return numEvents.get();
59 public int getNumDataChanges() {
60 return numDataChanges.get();