2 * Copyright (c) 2017 Cisco Systems, Inc. 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
9 package org.opendaylight.controller.clustering.it.provider.impl;
11 import com.google.common.base.Preconditions;
12 import java.util.Collection;
13 import javax.annotation.Nonnull;
14 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
19 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public class IdIntsListener implements DOMDataTreeChangeListener {
25 private static final Logger LOG = LoggerFactory.getLogger(IdIntsListener.class);
27 private NormalizedNode<?, ?> localCopy = null;
30 public void onDataTreeChanged(@Nonnull final Collection<DataTreeCandidate> changes) {
32 // There should only be one candidate reported
33 Preconditions.checkState(changes.size() == 1);
35 // do not log the change into debug, only use trace since it will lead to OOM on default heap settings
36 LOG.debug("Received data tree changed");
38 changes.forEach(change -> {
39 if (change.getRootNode().getDataAfter().isPresent()) {
40 LOG.trace("Received change, data before: {}, data after: ", change.getRootNode().getDataBefore().get(),
41 change.getRootNode().getDataAfter().get());
43 if (localCopy == null || checkEqual(change.getRootNode().getDataBefore().get())) {
44 localCopy = change.getRootNode().getDataAfter().get();
46 LOG.debug("Ignoring notification: {}", change);
49 LOG.warn("getDataAfter() is missing from notification. change: {}", change);
54 public boolean checkEqual(final NormalizedNode<?, ?> expected) {
55 return localCopy.equals(expected);