Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / samples / clustering-test-app / provider / src / main / java / org / opendaylight / controller / clustering / it / provider / CarDataTreeChangeListener.java
1 /*
2  * Copyright (c) 2016 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.clustering.it.provider;
9
10 import java.util.List;
11 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
12 import org.opendaylight.mdsal.binding.api.DataTreeModification;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.Cars;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 /**
18  * Provides a basic DTCL implementation for performance testing reasons.  Emits a rudimentary
19  * summary of the changes that occurred.
20  *
21  * @author Ryan Goulding (ryandgoulding@gmail.com)
22  */
23 public final class CarDataTreeChangeListener implements DataTreeChangeListener<Cars> {
24     private static final Logger LOG = LoggerFactory.getLogger(CarDataTreeChangeListener.class);
25
26     @Override
27     public void onDataTreeChanged(final List<DataTreeModification<Cars>> changes) {
28         if (LOG.isTraceEnabled()) {
29             for (var change : changes) {
30                 outputChanges(change);
31             }
32         }
33     }
34
35     private static void outputChanges(final DataTreeModification<Cars> change) {
36         final var rootNode = change.getRootNode();
37         final var modificationType = rootNode.modificationType();
38         final var rootIdentifier = change.getRootPath().path();
39         switch (modificationType) {
40             case WRITE, SUBTREE_MODIFIED -> {
41                 LOG.trace("onDataTreeChanged - Cars config with path {} was added or changed from {} to {}",
42                     rootIdentifier, rootNode.dataBefore(), rootNode.dataAfter());
43             }
44             case DELETE -> {
45                 LOG.trace("onDataTreeChanged - Cars config with path {} was deleted", rootIdentifier);
46             }
47             default -> {
48                 LOG.trace("onDataTreeChanged called with unknown modificationType: {}", modificationType);
49             }
50         }
51     }
52 }