BUG-1493: split off recursion tracking and rework it
[controller.git] / opendaylight / md-sal / sal-inmemory-datastore / src / main / java / org / opendaylight / controller / md / sal / dom / store / impl / ChangeListenerNotifyTask.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 com.google.common.base.Preconditions;
11
12 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
13 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
14 import org.opendaylight.yangtools.util.concurrent.NotificationManager;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 class ChangeListenerNotifyTask implements Runnable {
21     private static final Logger LOG = LoggerFactory.getLogger(ChangeListenerNotifyTask.class);
22
23     @SuppressWarnings("rawtypes")
24     private final NotificationManager<AsyncDataChangeListener,AsyncDataChangeEvent> notificationMgr;
25     private final AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> event;
26     private final DataChangeListenerRegistration<?> listener;
27
28     @SuppressWarnings("rawtypes")
29     public ChangeListenerNotifyTask(final DataChangeListenerRegistration<?> listener,
30             final AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> event,
31             final NotificationManager<AsyncDataChangeListener,AsyncDataChangeEvent> notificationMgr) {
32         this.notificationMgr = Preconditions.checkNotNull(notificationMgr);
33         this.listener = Preconditions.checkNotNull(listener);
34         this.event = Preconditions.checkNotNull(event);
35     }
36
37     @Override
38     public void run() {
39         final AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> l = listener.getInstance();
40         if (l == null) {
41             LOG.trace("Skipping event delivery to unregistered listener {}", l);
42             return;
43         }
44         LOG.trace("Listener {} event {}", l, event);
45
46         // FIXME: Yo dawg I heard you like queues, so this was queued to be queued
47         notificationMgr.submitNotification(l, event);
48     }
49
50     @Override
51     public String toString() {
52         return "ChangeListenerNotifyTask [listener=" + listener + ", event=" + event + "]";
53     }
54 }

©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.