2 * Copyright (c) 2016 Brocade Communications 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 javax.annotation.concurrent.NotThreadSafe;
11 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
12 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
13 import org.opendaylight.controller.md.sal.dom.store.impl.DOMImmutableDataChangeEvent;
14 import org.opendaylight.controller.md.sal.dom.store.impl.DataChangeListenerRegistration;
15 import org.opendaylight.controller.md.sal.dom.store.impl.ResolveDataChangeEventsTask;
16 import org.opendaylight.controller.md.sal.dom.store.impl.tree.ListenerTree;
17 import org.opendaylight.yangtools.util.concurrent.NotificationManager;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Default implementation of ShardDataChangeListenerPublisher that directly generates and publishes
26 * notifications for DataChangeListeners.
28 * @author Thomas Pantelis
31 final class DefaultShardDataChangeListenerPublisher implements ShardDataChangeListenerPublisher,
32 NotificationManager<DataChangeListenerRegistration<?>, DOMImmutableDataChangeEvent> {
33 private static final Logger LOG = LoggerFactory.getLogger(DefaultShardDataChangeListenerPublisher.class);
35 private final ListenerTree dataChangeListenerTree = ListenerTree.create();
38 public void submitNotification(final DataChangeListenerRegistration<?> listener,
39 final DOMImmutableDataChangeEvent notification) {
40 LOG.debug("Notifying listener {} about {}", listener.getInstance(), notification);
42 listener.getInstance().onDataChanged(notification);
46 public void submitNotifications(final DataChangeListenerRegistration<?> listener,
47 final Iterable<DOMImmutableDataChangeEvent> notifications) {
48 final AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> instance = listener.getInstance();
49 LOG.debug("Notifying listener {} about {}", instance, notifications);
51 for (DOMImmutableDataChangeEvent n : notifications) {
52 instance.onDataChanged(n);
57 public void publishChanges(DataTreeCandidate candidate, String logContext) {
58 ResolveDataChangeEventsTask.create(candidate, dataChangeListenerTree).resolve(this);
62 public <L extends AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>>
63 DataChangeListenerRegistration<L> registerDataChangeListener(YangInstanceIdentifier path, L listener,
64 DataChangeScope scope) {
65 return dataChangeListenerTree.registerDataChangeListener(path, listener, scope);
69 public ShardDataChangeListenerPublisher newInstance() {
70 return new DefaultShardDataChangeListenerPublisher();