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