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.BatchedInvoker;
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.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 final class InMemoryDOMDataTreeShardChangePublisher extends AbstractDOMShardTreeChangePublisher {
29 private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMDataTreeShardChangePublisher.class);
31 private static final BatchedInvoker<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate>
32 MANAGER_INVOKER = (listener, notifications) -> {
33 final DOMDataTreeChangeListener inst = listener.getInstance();
35 inst.onDataTreeChanged(ImmutableList.copyOf(notifications));
39 private final QueuedNotificationManager<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate>
42 InMemoryDOMDataTreeShardChangePublisher(final Executor executor,
43 final int maxQueueSize,
44 final DataTree dataTree,
45 final YangInstanceIdentifier rootPath,
46 final Map<DOMDataTreeIdentifier, ChildShardContext> childShards) {
47 super(dataTree, rootPath, childShards);
48 notificationManager = QueuedNotificationManager.create(
49 executor, MANAGER_INVOKER, maxQueueSize, "DataTreeChangeListenerQueueMgr");
53 protected void notifyListener(AbstractDOMDataTreeChangeListenerRegistration<?> registration,
54 Collection<DataTreeCandidate> changes) {
55 LOG.debug("Enqueueing candidates {} for registration {}", changes, registration);
56 notificationManager.submitNotifications(registration, changes);
60 protected void registrationRemoved(@Nonnull final AbstractDOMDataTreeChangeListenerRegistration<?> registration) {
61 LOG.debug("Closing registration {}", registration);
65 synchronized void publishChange(@Nonnull final DataTreeCandidate candidate) {
66 processCandidateTree(candidate);