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
8 package org.opendaylight.mdsal.dom.store.inmemory;
10 import com.google.common.collect.ImmutableList;
11 import java.util.Collection;
13 import java.util.concurrent.Executor;
14 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
15 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
16 import org.opendaylight.mdsal.dom.spi.AbstractDOMDataTreeChangeListenerRegistration;
17 import org.opendaylight.mdsal.dom.spi.shard.ChildShardContext;
18 import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager;
19 import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager.BatchedInvoker;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
22 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 final class InMemoryDOMDataTreeShardChangePublisher extends AbstractDOMShardTreeChangePublisher {
28 private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMDataTreeShardChangePublisher.class);
30 private static final BatchedInvoker<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate>
31 MANAGER_INVOKER = (listener, notifications) -> {
32 final DOMDataTreeChangeListener inst = listener.getInstance();
34 inst.onDataTreeChanged(ImmutableList.copyOf(notifications));
38 private final QueuedNotificationManager<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate>
41 InMemoryDOMDataTreeShardChangePublisher(final Executor executor,
42 final int maxQueueSize,
43 final DataTree dataTree,
44 final YangInstanceIdentifier rootPath,
45 final Map<DOMDataTreeIdentifier, ChildShardContext> childShards) {
46 super(dataTree, rootPath, childShards);
47 notificationManager = QueuedNotificationManager.create(executor, MANAGER_INVOKER, maxQueueSize,
48 "DataTreeChangeListenerQueueMgr");
52 protected void notifyListener(final AbstractDOMDataTreeChangeListenerRegistration<?> registration,
53 final Collection<DataTreeCandidate> changes) {
54 LOG.debug("Enqueueing candidates {} for registration {}", changes, registration);
55 notificationManager.submitNotifications(registration, changes);
59 protected void registrationRemoved(final AbstractDOMDataTreeChangeListenerRegistration<?> registration) {
60 LOG.debug("Closing registration {}", registration);
64 synchronized void publishChange(final DataTreeCandidate candidate) {
65 processCandidateTree(candidate);