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.mdsal.dom.spi.shard.ChildShardContext;
20 import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager;
21 import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager.BatchedInvoker;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
24 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 final class InMemoryDOMDataTreeShardChangePublisher extends AbstractDOMShardTreeChangePublisher {
30 private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMDataTreeShardChangePublisher.class);
32 private static final BatchedInvoker<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate>
33 MANAGER_INVOKER = (listener, notifications) -> {
34 final DOMDataTreeChangeListener inst = listener.getInstance();
36 inst.onDataTreeChanged(ImmutableList.copyOf(notifications));
40 private final QueuedNotificationManager<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate>
43 InMemoryDOMDataTreeShardChangePublisher(final Executor executor,
44 final int maxQueueSize,
45 final DataTree dataTree,
46 final YangInstanceIdentifier rootPath,
47 final Map<DOMDataTreeIdentifier, ChildShardContext> childShards) {
48 super(dataTree, rootPath, childShards);
49 notificationManager = QueuedNotificationManager.create(
50 executor, MANAGER_INVOKER, maxQueueSize, "DataTreeChangeListenerQueueMgr");
54 protected void notifyListener(AbstractDOMDataTreeChangeListenerRegistration<?> registration,
55 Collection<DataTreeCandidate> changes) {
56 LOG.debug("Enqueueing candidates {} for registration {}", changes, registration);
57 notificationManager.submitNotifications(registration, changes);
61 protected void registrationRemoved(@Nonnull final AbstractDOMDataTreeChangeListenerRegistration<?> registration) {
62 LOG.debug("Closing registration {}", registration);
66 synchronized void publishChange(@Nonnull final DataTreeCandidate candidate) {
67 processCandidateTree(candidate);