a333033c90a3f5e92d98030f9db78351aedb5e3b
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / src / main / java / org / opendaylight / mdsal / dom / store / inmemory / InMemoryDOMDataTreeShardChangePublisher.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.dom.store.inmemory;
9
10 import java.util.Collection;
11 import java.util.Map;
12 import java.util.concurrent.Executor;
13 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
14 import org.opendaylight.mdsal.dom.spi.AbstractDOMDataTreeChangeListenerRegistration;
15 import org.opendaylight.mdsal.dom.spi.shard.ChildShardContext;
16 import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
19 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 final class InMemoryDOMDataTreeShardChangePublisher extends AbstractDOMShardTreeChangePublisher {
24
25     private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMDataTreeShardChangePublisher.class);
26
27     private final QueuedNotificationManager<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate>
28         notificationManager;
29
30     InMemoryDOMDataTreeShardChangePublisher(final Executor executor,
31                                             final int maxQueueSize,
32                                             final DataTree dataTree,
33                                             final YangInstanceIdentifier rootPath,
34                                             final Map<DOMDataTreeIdentifier, ChildShardContext> childShards) {
35         super(dataTree, rootPath, childShards);
36         notificationManager = QueuedNotificationManager.create(executor, (listener, notifications) -> {
37             // FIXME: we are not checking for listener being closed
38             listener.getInstance().onDataTreeChanged(notifications);
39         }, maxQueueSize, "DataTreeChangeListenerQueueMgr");
40     }
41
42     @Override
43     protected void notifyListener(final AbstractDOMDataTreeChangeListenerRegistration<?> registration,
44             final Collection<DataTreeCandidate> changes) {
45         LOG.debug("Enqueueing candidates {} for registration {}", changes, registration);
46         notificationManager.submitNotifications(registration, changes);
47     }
48
49     @Override
50     protected void registrationRemoved(final AbstractDOMDataTreeChangeListenerRegistration<?> registration) {
51         LOG.debug("Closing registration {}", registration);
52
53     }
54
55     synchronized void publishChange(final DataTreeCandidate candidate) {
56         processCandidateTree(candidate);
57     }
58 }