Class AbstractAsyncDataTreeChangeListener<T extends org.opendaylight.yangtools.yang.binding.DataObject>
- Type Parameters:
T
- type of the data object the listener is registered to.
- All Implemented Interfaces:
AutoCloseable
,EventListener
,org.opendaylight.mdsal.binding.api.DataTreeChangeListener<T>
,ChainableDataTreeChangeListener<T>
ExecutorService
.
The ExecutorService
passed to the constructor will depend on the use case. Here we have some examples:
- If the listener is fast enough and non-blocking: MoreExecutors.directExecutor might be used, or even better,
just use the AbstractSyncDataTreeChangeListener
.
- If the listener is heavy or could be blocked: use a multi-threaded executor.
We recommend using one of the factory methods in SpecialExecutors
.
You could and probably should share such an Executor among several listeners in your project.
- If the listener needs to preserve the order of notifications, then (only) use a single thread executor typically
an org.opendaylight.infrautils.utils.concurrent.Executors#newSingleThreadExecutor(String, org.slf4j.Logger)
.
- If there are multiple listeners: they could even share an Executor as the ones in SpecialExecutors
,
Subclasses are also encouraged to, in addition to passing the ExecutorService for use in production (by Blueprint wiring) based on above via super(), expose a public constructor letting tests specify an alternative ExecutorService; this is useful e.g. to inject infrautils' AwaitableExecutorService for testing.
- Author:
- David Suárez (david.suarez.fuentes@gmail.com)
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractAsyncDataTreeChangeListener
(org.opendaylight.mdsal.binding.api.DataBroker dataBroker, org.opendaylight.mdsal.binding.api.DataTreeIdentifier<T> dataTreeIdentifier, ExecutorService executorService) AbstractAsyncDataTreeChangeListener
(org.opendaylight.mdsal.binding.api.DataBroker dataBroker, org.opendaylight.mdsal.common.api.LogicalDatastoreType datastoreType, org.opendaylight.yangtools.yang.binding.InstanceIdentifier<T> instanceIdentifier, ExecutorService executorService) AbstractAsyncDataTreeChangeListener
(org.opendaylight.mdsal.binding.api.DataBroker dataBroker, org.opendaylight.mdsal.common.api.LogicalDatastoreType datastoreType, org.opendaylight.yangtools.yang.binding.InstanceIdentifier<T> instanceIdentifier, ExecutorService executorService, MetricProvider metricProvider) -
Method Summary
Modifier and TypeMethodDescriptiondefault void
add
(@NonNull org.opendaylight.yangtools.yang.binding.InstanceIdentifier<T> instanceIdentifier, T newDataObject) Invoked when a new data object is added.void
Deprecated.void
addAfterListener
(org.opendaylight.mdsal.binding.api.DataTreeChangeListener<T> listener) Adds a "chained" DataTreeChangeListener, to whichDataTreeChangeListener.onDataTreeChanged(java.util.Collection)
calls are forwarded AFTER having been processed by this DataTreeChangeListener.void
addBeforeListener
(org.opendaylight.mdsal.binding.api.DataTreeChangeListener<T> listener) Adds a "chained" DataTreeChangeListener, to whichDataTreeChangeListener.onDataTreeChanged(java.util.Collection)
calls are forwarded BEFORE having been processed by this DataTreeChangeListener.void
close()
protected org.opendaylight.mdsal.binding.api.DataBroker
protected org.opendaylight.serviceutils.tools.listener.DataStoreMetrics
protected ExecutorService
Returns the ExecutorService provided when constructing this instance.final void
onDataTreeChanged
(Collection<org.opendaylight.mdsal.binding.api.DataTreeModification<T>> collection) default void
onDataTreeChanged
(Collection<org.opendaylight.mdsal.binding.api.DataTreeModification<T>> changes, org.opendaylight.serviceutils.tools.listener.DataStoreMetrics dataStoreMetrics) Default method invoked upon data tree change, in turn it calls the appropriate method (add, update, remove) depending on the type of change.void
register()
default void
remove
(@NonNull org.opendaylight.yangtools.yang.binding.InstanceIdentifier<T> instanceIdentifier, T removedDataObject) Invoked when the data object has been removed.void
Deprecated.default void
update
(@NonNull org.opendaylight.yangtools.yang.binding.InstanceIdentifier<T> instanceIdentifier, T originalDataObject, T updatedDataObject) Invoked when there is a change in the data object.void
Deprecated.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.opendaylight.mdsal.binding.api.DataTreeChangeListener
onInitialData
-
Constructor Details
-
AbstractAsyncDataTreeChangeListener
public AbstractAsyncDataTreeChangeListener(org.opendaylight.mdsal.binding.api.DataBroker dataBroker, org.opendaylight.mdsal.binding.api.DataTreeIdentifier<T> dataTreeIdentifier, ExecutorService executorService) -
AbstractAsyncDataTreeChangeListener
public AbstractAsyncDataTreeChangeListener(org.opendaylight.mdsal.binding.api.DataBroker dataBroker, org.opendaylight.mdsal.common.api.LogicalDatastoreType datastoreType, org.opendaylight.yangtools.yang.binding.InstanceIdentifier<T> instanceIdentifier, ExecutorService executorService) -
AbstractAsyncDataTreeChangeListener
public AbstractAsyncDataTreeChangeListener(org.opendaylight.mdsal.binding.api.DataBroker dataBroker, org.opendaylight.mdsal.common.api.LogicalDatastoreType datastoreType, org.opendaylight.yangtools.yang.binding.InstanceIdentifier<T> instanceIdentifier, ExecutorService executorService, MetricProvider metricProvider)
-
-
Method Details
-
onDataTreeChanged
public final void onDataTreeChanged(Collection<org.opendaylight.mdsal.binding.api.DataTreeModification<T>> collection) -
getExecutorService
Returns the ExecutorService provided when constructing this instance. If the subclass owns the ExecutorService, it should be shut down when closing the listener using this getter.- Returns:
- executor service
-
addBeforeListener
public void addBeforeListener(org.opendaylight.mdsal.binding.api.DataTreeChangeListener<T> listener) Description copied from interface:ChainableDataTreeChangeListener
Adds a "chained" DataTreeChangeListener, to whichDataTreeChangeListener.onDataTreeChanged(java.util.Collection)
calls are forwarded BEFORE having been processed by this DataTreeChangeListener.If an asychronous DataTreeChangeListener supports chaining, it must forward the onDataTreeChanged() call BEFORE event are submitted to its async executor for processing.
- Specified by:
addBeforeListener
in interfaceChainableDataTreeChangeListener<T extends org.opendaylight.yangtools.yang.binding.DataObject>
- Parameters:
listener
- the chained DataTreeChangeListener to invoke after this one
-
addAfterListener
Description copied from interface:ChainableDataTreeChangeListener
Adds a "chained" DataTreeChangeListener, to whichDataTreeChangeListener.onDataTreeChanged(java.util.Collection)
calls are forwarded AFTER having been processed by this DataTreeChangeListener.If an asychronous DataTreeChangeListener supports chaining, it must forward the onDataTreeChanged() call ONLY AFTER its async executor processed the event.
- Specified by:
addAfterListener
in interfaceChainableDataTreeChangeListener<T extends org.opendaylight.yangtools.yang.binding.DataObject>
- Parameters:
listener
- the chained DataTreeChangeListener to invoke after this one
-
register
@PostConstruct public void register() -
getDataBroker
protected org.opendaylight.mdsal.binding.api.DataBroker getDataBroker() -
getDataStoreMetrics
protected org.opendaylight.serviceutils.tools.listener.DataStoreMetrics getDataStoreMetrics() -
close
@PreDestroy public void close()- Specified by:
close
in interfaceAutoCloseable
-
add
Deprecated. -
remove
Deprecated. -
update
Deprecated. -
onDataTreeChanged
default void onDataTreeChanged(Collection<org.opendaylight.mdsal.binding.api.DataTreeModification<T>> changes, org.opendaylight.serviceutils.tools.listener.DataStoreMetrics dataStoreMetrics) Default method invoked upon data tree change, in turn it calls the appropriate method (add, update, remove) depending on the type of change.- Parameters:
changes
- collection of changesdataStoreMetrics
- data store metrics
-
add
default void add(@NonNull org.opendaylight.yangtools.yang.binding.InstanceIdentifier<T> instanceIdentifier, T newDataObject) Invoked when a new data object is added.- Parameters:
instanceIdentifier
- instance id for this data objectnewDataObject
- newly added object
-
remove
default void remove(@NonNull org.opendaylight.yangtools.yang.binding.InstanceIdentifier<T> instanceIdentifier, T removedDataObject) Invoked when the data object has been removed.- Parameters:
instanceIdentifier
- instance id for this data objectremovedDataObject
- existing object being removed
-
update
default void update(@NonNull org.opendaylight.yangtools.yang.binding.InstanceIdentifier<T> instanceIdentifier, T originalDataObject, T updatedDataObject) Invoked when there is a change in the data object.- Parameters:
instanceIdentifier
- instance id for this data objectoriginalDataObject
- existing object being modifiedupdatedDataObject
- modified data object
-