2 * Copyright (c) 2017 Ericsson S.A. and others. All rights reserved.
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
8 package org.opendaylight.genius.datastoreutils.listeners;
10 import java.util.Collection;
11 import java.util.concurrent.ExecutorService;
12 import javax.inject.Inject;
13 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
14 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
18 * Abstract class providing some common functionality to specific listeners.
19 * This listener launches the received notifications in a different thread by
20 * using the queuing functionality of the {@link ExecutorService}.
22 * @author David Suárez (david.suarez.fuentes@gmail.com)
25 * type of the data object the listener is registered to.
27 public abstract class AbstractAsyncDataTreeChangeListener<T extends DataObject>
28 implements DataTreeChangeListenerActions<T>, DataTreeChangeListener<T> {
29 private final ExecutorService executorService;
32 public AbstractAsyncDataTreeChangeListener(ExecutorService executorService) {
33 this.executorService = executorService;
37 public final void onDataTreeChanged(Collection<DataTreeModification<T>> collection) {
38 executorService.submit(() -> DataTreeChangeListenerActions.super.onDataTreeChanged(collection));