* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.mdsal.dom.store.inmemory;
-import com.google.common.collect.ImmutableList;
import java.util.Collection;
import java.util.Map;
-import java.util.concurrent.ExecutorService;
-import javax.annotation.Nonnull;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
+import java.util.concurrent.Executor;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.mdsal.dom.spi.AbstractDOMDataTreeChangeListenerRegistration;
+import org.opendaylight.mdsal.dom.spi.shard.ChildShardContext;
import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager;
-import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager.Invoker;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMDataTreeShardChangePublisher.class);
- private static final Invoker<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate>
- MANAGER_INVOKER = (listener, notification) -> {
- final DOMDataTreeChangeListener inst = listener.getInstance();
- if (inst != null) {
- inst.onDataTreeChanged(ImmutableList.of(notification));
- }
- };
-
- private final QueuedNotificationManager<AbstractDOMDataTreeChangeListenerRegistration<?>,
- DataTreeCandidate> notificationManager;
+ private final QueuedNotificationManager<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate>
+ notificationManager;
- InMemoryDOMDataTreeShardChangePublisher(final ExecutorService executorService,
+ InMemoryDOMDataTreeShardChangePublisher(final Executor executor,
final int maxQueueSize,
final DataTree dataTree,
final YangInstanceIdentifier rootPath,
final Map<DOMDataTreeIdentifier, ChildShardContext> childShards) {
super(dataTree, rootPath, childShards);
- notificationManager = new QueuedNotificationManager<>(
- executorService, MANAGER_INVOKER, maxQueueSize, "DataTreeChangeListenerQueueMgr");
+ notificationManager = QueuedNotificationManager.create(executor, (listener, notifications) -> {
+ if (!listener.isClosed()) {
+ listener.getInstance().onDataTreeChanged(notifications);
+ }
+ }, maxQueueSize, "DataTreeChangeListenerQueueMgr");
}
@Override
- protected void notifyListeners(
- @Nonnull final Collection<AbstractDOMDataTreeChangeListenerRegistration<?>> registrations,
- @Nonnull final YangInstanceIdentifier path,
- @Nonnull final DataTreeCandidateNode node) {
- final DataTreeCandidate candidate = DataTreeCandidates.newDataTreeCandidate(path, node);
-
- for (final AbstractDOMDataTreeChangeListenerRegistration<?> reg : registrations) {
- LOG.debug("Enqueueing candidate {} to registration {}", candidate, registrations);
- notificationManager.submitNotification(reg, candidate);
- }
+ protected void notifyListener(final AbstractDOMDataTreeChangeListenerRegistration<?> registration,
+ final Collection<DataTreeCandidate> changes) {
+ LOG.debug("Enqueueing candidates {} for registration {}", changes, registration);
+ notificationManager.submitNotifications(registration, changes);
}
@Override
- protected void registrationRemoved(@Nonnull AbstractDOMDataTreeChangeListenerRegistration<?> registration) {
+ protected void registrationRemoved(final AbstractDOMDataTreeChangeListenerRegistration<?> registration) {
LOG.debug("Closing registration {}", registration);
}
- public <L extends DOMDataTreeChangeListener> AbstractDOMDataTreeChangeListenerRegistration<L>
- registerTreeChangeListener(YangInstanceIdentifier path, L listener) {
- return super.registerTreeChangeListener(path, listener);
- }
-
- synchronized void publishChange(@Nonnull final DataTreeCandidate candidate) {
+ synchronized void publishChange(final DataTreeCandidate candidate) {
processCandidateTree(candidate);
}
}