Migrate mdsal-dom-inmemory-datastore to JDT annotations
[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 com.google.common.collect.ImmutableList;
11 import java.util.Collection;
12 import java.util.Map;
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;
25
26 final class InMemoryDOMDataTreeShardChangePublisher extends AbstractDOMShardTreeChangePublisher {
27
28     private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMDataTreeShardChangePublisher.class);
29
30     private static final BatchedInvoker<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate>
31         MANAGER_INVOKER = (listener, notifications) -> {
32             final DOMDataTreeChangeListener inst = listener.getInstance();
33             if (inst != null) {
34                 inst.onDataTreeChanged(ImmutableList.copyOf(notifications));
35             }
36         };
37
38     private final QueuedNotificationManager<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate>
39         notificationManager;
40
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");
49     }
50
51     @Override
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);
56     }
57
58     @Override
59     protected void registrationRemoved(final AbstractDOMDataTreeChangeListenerRegistration<?> registration) {
60         LOG.debug("Closing registration {}", registration);
61
62     }
63
64     synchronized void publishChange(final DataTreeCandidate candidate) {
65         processCandidateTree(candidate);
66     }
67 }