Remove deprecated MD-SAL APIs
[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 org.opendaylight.mdsal.binding.api.DataObjectModification;
11 import org.opendaylight.mdsal.binding.api.DataObjectModification.ModificationType;
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.controller.config.sal.clustering.it.car.rev140818.Cars;
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * Provides a basic DTCL implementation for performance testing reasons.  Emits a rudimentary
21  * summary of the changes that occurred.
22  *
23  * @author Ryan Goulding (ryandgoulding@gmail.com)
24  */
25 public class CarDataTreeChangeListener implements DataTreeChangeListener<Cars> {
26     private static final Logger LOG = LoggerFactory.getLogger(CarDataTreeChangeListener.class);
27
28     @java.lang.Override
29     public void onDataTreeChanged(final java.util.Collection<DataTreeModification<Cars>> changes) {
30         if (LOG.isTraceEnabled()) {
31             for (DataTreeModification<Cars> change : changes) {
32                 outputChanges(change);
33             }
34         }
35     }
36
37     private static void outputChanges(final DataTreeModification<Cars> change) {
38         final DataObjectModification<Cars> rootNode = change.getRootNode();
39         final ModificationType modificationType = rootNode.getModificationType();
40         final InstanceIdentifier<Cars> rootIdentifier = change.getRootPath().getRootIdentifier();
41         switch (modificationType) {
42             case WRITE:
43             case SUBTREE_MODIFIED: {
44                 LOG.trace("onDataTreeChanged - Cars config with path {} was added or changed from {} to {}",
45                         rootIdentifier, rootNode.getDataBefore(), rootNode.getDataAfter());
46                 break;
47             }
48             case DELETE: {
49                 LOG.trace("onDataTreeChanged - Cars config with path {} was deleted", rootIdentifier);
50                 break;
51             }
52             default: {
53                 LOG.trace("onDataTreeChanged called with unknown modificationType: {}", modificationType);
54                 break;
55             }
56         }
57     }
58 }