Cleanup: Remove passing around of DataPersistenceProvider
[controller.git] / opendaylight / md-sal / sal-inmemory-datastore / src / main / java / org / opendaylight / controller / md / sal / dom / store / impl / InMemoryDOMStoreTreeChangePublisher.java
1 /*
2  * Copyright (c) 2014 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.controller.md.sal.dom.store.impl;
9
10 import java.util.Collection;
11 import java.util.Collections;
12 import java.util.concurrent.ExecutorService;
13 import javax.annotation.Nonnull;
14 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
15 import org.opendaylight.controller.md.sal.dom.spi.AbstractDOMDataTreeChangeListenerRegistration;
16 import org.opendaylight.controller.sal.core.spi.data.AbstractDOMStoreTreeChangePublisher;
17 import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager;
18 import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager.Invoker;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
21 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
22 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.DefaultDataTreeCandidate;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 final class InMemoryDOMStoreTreeChangePublisher extends AbstractDOMStoreTreeChangePublisher {
27     private static final Invoker<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate> MANAGER_INVOKER =
28             new Invoker<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate>() {
29                 @Override
30                 public void invokeListener(final AbstractDOMDataTreeChangeListenerRegistration<?> listener, final DataTreeCandidate notification) {
31                     // FIXME: this is inefficient, as we could grab the entire queue for the listener and post it
32                     final DOMDataTreeChangeListener inst = listener.getInstance();
33                     if (inst != null) {
34                         inst.onDataTreeChanged(Collections.singletonList(notification));
35                     }
36                 }
37             };
38     private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMStoreTreeChangePublisher.class);
39     private final QueuedNotificationManager<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate> notificationManager;
40
41     InMemoryDOMStoreTreeChangePublisher(final ExecutorService listenerExecutor, final int maxQueueSize) {
42         notificationManager = new QueuedNotificationManager<>(listenerExecutor, MANAGER_INVOKER, maxQueueSize, "DataTreeChangeListenerQueueMgr");
43     }
44
45     @Override
46     protected void notifyListeners(final Collection<AbstractDOMDataTreeChangeListenerRegistration<?>> registrations, final YangInstanceIdentifier path, final DataTreeCandidateNode node) {
47         final DataTreeCandidate candidate = new DefaultDataTreeCandidate(path, node);
48
49         for (AbstractDOMDataTreeChangeListenerRegistration<?> reg : registrations) {
50             LOG.debug("Enqueueing candidate {} to registration {}", candidate, registrations);
51             notificationManager.submitNotification(reg, candidate);
52         }
53     }
54
55     @Override
56     protected synchronized void registrationRemoved(final AbstractDOMDataTreeChangeListenerRegistration<?> registration) {
57         LOG.debug("Closing registration {}", registration);
58
59         // FIXME: remove the queue for this registration and make sure we clear it
60     }
61
62     synchronized void publishChange(@Nonnull final DataTreeCandidate candidate) {
63         // Runs synchronized with registrationRemoved()
64         processCandidateTree(candidate);
65     }
66 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.