2 * Copyright (c) 2015 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
8 package org.opendaylight.controller.cluster.datastore;
10 import com.google.common.base.Stopwatch;
11 import java.util.Collection;
12 import java.util.Collections;
13 import java.util.concurrent.TimeUnit;
14 import javax.annotation.concurrent.NotThreadSafe;
15 import org.opendaylight.controller.md.sal.dom.spi.AbstractDOMDataTreeChangeListenerRegistration;
16 import org.opendaylight.controller.sal.core.spi.data.AbstractDOMStoreTreeChangePublisher;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
19 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
20 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Default implementation of ShardDataTreeChangeListenerPublisher that directly generates and publishes
26 * notifications for DataTreeChangeListeners.
28 * @author Thomas Pantelis
31 final class DefaultShardDataTreeChangeListenerPublisher extends AbstractDOMStoreTreeChangePublisher
32 implements ShardDataTreeChangeListenerPublisher {
33 private static final Logger LOG = LoggerFactory.getLogger(DefaultShardDataTreeChangeListenerPublisher.class);
35 private final Stopwatch timer = Stopwatch.createUnstarted();
38 public void publishChanges(final DataTreeCandidate candidate, String logContext) {
42 processCandidateTree(candidate);
45 long elapsedTime = timer.elapsed(TimeUnit.MILLISECONDS);
46 if(elapsedTime >= PUBLISH_DELAY_THRESHOLD_IN_MS) {
47 LOG.warn("{}: Generation of DataTreeCandidateNode events took longer than expected. Elapsed time: {}",
50 LOG.debug("{}: Elapsed time for generation of DataTreeCandidateNode events: {}", logContext, timer);
58 public ShardDataTreeChangeListenerPublisher newInstance() {
59 return new DefaultShardDataTreeChangeListenerPublisher();
63 protected void notifyListeners(final Collection<AbstractDOMDataTreeChangeListenerRegistration<?>> registrations,
64 final YangInstanceIdentifier path, final DataTreeCandidateNode node) {
65 final Collection<DataTreeCandidate> changes = Collections.<DataTreeCandidate>singleton(
66 DataTreeCandidates.newDataTreeCandidate(path, node));
68 for (AbstractDOMDataTreeChangeListenerRegistration<?> reg : registrations) {
69 reg.getInstance().onDataTreeChanged(changes);
74 protected void registrationRemoved(final AbstractDOMDataTreeChangeListenerRegistration<?> registration) {
75 LOG.debug("Registration {} removed", registration);