2 * Copyright (c) 2016 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.mdsal.dom.store.inmemory;
11 import com.google.common.collect.ImmutableList;
12 import java.util.Collection;
14 import java.util.concurrent.Executor;
15 import javax.annotation.Nonnull;
16 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
17 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
18 import org.opendaylight.mdsal.dom.spi.AbstractDOMDataTreeChangeListenerRegistration;
19 import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager;
20 import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager.Invoker;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
23 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
24 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
25 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 final class InMemoryDOMDataTreeShardChangePublisher extends AbstractDOMShardTreeChangePublisher {
31 private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMDataTreeShardChangePublisher.class);
33 private static final Invoker<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate>
34 MANAGER_INVOKER = (listener, notification) -> {
35 final DOMDataTreeChangeListener inst = listener.getInstance();
37 inst.onDataTreeChanged(ImmutableList.of(notification));
41 private final QueuedNotificationManager<AbstractDOMDataTreeChangeListenerRegistration<?>,
42 DataTreeCandidate> notificationManager;
44 InMemoryDOMDataTreeShardChangePublisher(final Executor executor,
45 final int maxQueueSize,
46 final DataTree dataTree,
47 final YangInstanceIdentifier rootPath,
48 final Map<DOMDataTreeIdentifier, ChildShardContext> childShards) {
49 super(dataTree, rootPath, childShards);
50 notificationManager = new QueuedNotificationManager<>(
51 executor, MANAGER_INVOKER, maxQueueSize, "DataTreeChangeListenerQueueMgr");
55 protected void notifyListeners(
56 @Nonnull final Collection<AbstractDOMDataTreeChangeListenerRegistration<?>> registrations,
57 @Nonnull final YangInstanceIdentifier path,
58 @Nonnull final DataTreeCandidateNode node) {
59 final DataTreeCandidate candidate = DataTreeCandidates.newDataTreeCandidate(path, node);
61 for (final AbstractDOMDataTreeChangeListenerRegistration<?> reg : registrations) {
62 LOG.debug("Enqueueing candidate {} to registration {}", candidate, registrations);
63 notificationManager.submitNotification(reg, candidate);
68 protected void registrationRemoved(@Nonnull final AbstractDOMDataTreeChangeListenerRegistration<?> registration) {
69 LOG.debug("Closing registration {}", registration);
74 public <L extends DOMDataTreeChangeListener> AbstractDOMDataTreeChangeListenerRegistration<L>
75 registerTreeChangeListener(final YangInstanceIdentifier path, final L listener) {
76 return super.registerTreeChangeListener(path, listener);
79 synchronized void publishChange(@Nonnull final DataTreeCandidate candidate) {
80 processCandidateTree(candidate);