Bug 1430: Off-load notifications from single commit thread
[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 org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
11 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
12 import org.opendaylight.yangtools.util.concurrent.NotificationManager;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 class ChangeListenerNotifyTask implements Runnable {
19
20     private static final Logger LOG = LoggerFactory.getLogger(ChangeListenerNotifyTask.class);
21
22     private final Iterable<? extends DataChangeListenerRegistration<?>> listeners;
23     private final AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> event;
24
25     @SuppressWarnings("rawtypes")
26     private final NotificationManager<AsyncDataChangeListener,AsyncDataChangeEvent>
27                                                                             notificationMgr;
28
29     @SuppressWarnings("rawtypes")
30     public ChangeListenerNotifyTask(final Iterable<? extends DataChangeListenerRegistration<?>> listeners,
31             final AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> event,
32             final NotificationManager<AsyncDataChangeListener,AsyncDataChangeEvent> notificationMgr) {
33         this.listeners = listeners;
34         this.event = event;
35         this.notificationMgr = notificationMgr;
36     }
37
38     @Override
39     public void run() {
40
41         for (DataChangeListenerRegistration<?> listener : listeners) {
42             notificationMgr.submitNotification(listener.getInstance(), event);
43         }
44     }
45
46     @Override
47     public String toString() {
48         return "ChangeListenerNotifyTask [listeners=" + listeners + ", event=" + event + "]";
49     }
50 }

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