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;
14 import javax.annotation.Nonnull;
15 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
16 import org.opendaylight.mdsal.dom.api.DOMDataTreeListener;
17 import org.opendaylight.mdsal.dom.api.DOMDataTreeListeningException;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public class IdIntsDOMDataTreeLIstener implements DOMDataTreeListener {
25 private static final Logger LOG = LoggerFactory.getLogger(IdIntsDOMDataTreeLIstener.class);
27 private NormalizedNode<?, ?> localCopy = null;
30 public void onDataTreeChanged(@Nonnull final Collection<DataTreeCandidate> changes,
31 @Nonnull final Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>> subtrees) {
33 // There should only be one candidate reported
34 Preconditions.checkState(changes.size() == 1);
36 // do not log the change into debug, only use trace since it will lead to OOM on default heap settings
37 LOG.debug("Received data tree changed");
39 changes.forEach(change -> {
40 if (change.getRootNode().getDataAfter().isPresent()) {
41 LOG.trace("Received change, data before: {}, data after: ",
42 change.getRootNode().getDataBefore().isPresent()
43 ? change.getRootNode().getDataBefore().get() : "",
44 change.getRootNode().getDataAfter().get());
46 if (localCopy == null || checkEqual(change.getRootNode().getDataBefore().get())) {
47 localCopy = change.getRootNode().getDataAfter().get();
49 LOG.warn("Ignoring notification.");
50 LOG.trace("Ignored notification content: {}", change);
53 LOG.warn("getDataAfter() is missing from notification. change: {}", change);
59 public void onDataTreeFailed(@Nonnull Collection<DOMDataTreeListeningException> causes) {
63 public boolean hasTriggered() {
64 return localCopy != null;
67 public boolean checkEqual(final NormalizedNode<?, ?> expected) {
68 return localCopy.equals(expected);