GigaSpaces XAP 9.7.2 API

org.openspaces.events.adapter
Class TaskExecutorEventListenerAdapter

java.lang.Object
  extended by org.openspaces.events.adapter.TaskExecutorEventListenerAdapter
All Implemented Interfaces:
EventListenerAdapter, SpaceDataEventListener, InitializingBean

public class TaskExecutorEventListenerAdapter
extends Object
implements SpaceDataEventListener, InitializingBean, EventListenerAdapter

An adapter that delegates the execution of a SpaceDataEventListener to Spring TaskExecutor implementation (usually to be executed in a different thread).

Very handy when using notifications in order to release the notification thread.

Defualt task executor uses SimpleAsyncTaskExecutor which creates a new thread for each request.

Author:
kimchy
See Also:
TaskExecutor

Constructor Summary
TaskExecutorEventListenerAdapter()
           
 
Method Summary
 void afterPropertiesSet()
          Initializes the task executor adapter.
 Object getActualEventListener()
           
 void onEvent(Object data, GigaSpace gigaSpace, TransactionStatus txStatus, Object source)
          Listens for events and and delegates them to the setDelegate(org.openspaces.events.SpaceDataEventListener) to be executed using the provided setTaskExecutor(org.springframework.core.task.TaskExecutor).
 void setDelegate(SpaceDataEventListener delegate)
          Sets the delegate that will invoked using the task executor.
 void setTaskExecutor(TaskExecutor taskExecutor)
          Sets the task executor to be used to delegate the execution of the delegate listener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskExecutorEventListenerAdapter

public TaskExecutorEventListenerAdapter()
Method Detail

setTaskExecutor

public void setTaskExecutor(TaskExecutor taskExecutor)
Sets the task executor to be used to delegate the execution of the delegate listener.

Defualts to SimpleAsyncTaskExecutor which creates a new thread for each request.


setDelegate

public void setDelegate(SpaceDataEventListener delegate)
Sets the delegate that will invoked using the task executor.


afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Initializes the task executor adapter. Expects the delegate to be set. If no taskExecutor is provided will create a default one using SimpleAsyncTaskExecutor.

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception

getActualEventListener

public Object getActualEventListener()
Specified by:
getActualEventListener in interface EventListenerAdapter

onEvent

public void onEvent(Object data,
                    GigaSpace gigaSpace,
                    TransactionStatus txStatus,
                    Object source)
Listens for events and and delegates them to the setDelegate(org.openspaces.events.SpaceDataEventListener) to be executed using the provided setTaskExecutor(org.springframework.core.task.TaskExecutor).

Specified by:
onEvent in interface SpaceDataEventListener
Parameters:
data - The actual data object of the event
gigaSpace - A GigaSpace instance that can be used to perform additional operations against the space
txStatus - An optional transaction status allowing to rollback a transaction programmatically
source - Optional additional data or the actual source event data object (where relevant)

GigaSpaces XAP 9.7.2 API

Copyright © GigaSpaces.