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