public abstract class AbstractReflectionEventListenerAdapter extends AbstractResultEventListenerAdapter implements InitializingBean, EventListenerAdapter
setDelegate(Object)
.
Subclasses must implement the doGetListenerMethods()
in order to list all the possible
event listener methods. If more than one event listener method is found, all event listener
methods must have the same name.
For best performance a single event listener method should be used. If a single event listener is found (by subclasses), caching of the method can be done in order to perform the reflection execution faster. If more than one event listener method is found - dynamic discovery of the appropriate method is done for each listener invocation.
Event listening methods can have no parameters or one or more parameters mapping to
SpaceDataEventListener.onEvent(Object,org.openspaces.core.GigaSpace,org.springframework.transaction.TransactionStatus,Object)
parameters order. If the method has a return value it will be handled thanks to
AbstractResultEventListenerAdapter
.
Having more than one event listening method allows for writing specific listener methods handling
different data event types (usually different types within the same inheritance tree). This
allows to remove the need for instanceof
checks within the listener code. If a
single listening method is used, it can still have a specific class type for the event data
object thanks to Java reflection, though if the event listener will be invoked with a different
type a reflection exception will be thrown.
Modifier and Type | Field and Description |
---|---|
protected Log |
logger
Logger available to subclasses
|
Constructor and Description |
---|
AbstractReflectionEventListenerAdapter() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected abstract Method[] |
doGetListenerMethods()
Subclasses should implement this in order to provide a list of all the possible event
listener delegate methods.
|
Object |
getActualEventListener() |
protected Object |
getDelegate()
Returns the event listener delegate.
|
protected Object |
onEventWithResult(Object data,
GigaSpace gigaSpace,
TransactionStatus txStatus,
Object source)
Delegates the event listener invocation to the appropriate method of the configured
setDelegate(Object) . |
void |
setDelegate(Object delegate)
The event listener delegate that will be searched for event listening methods and will have
its method executed.
|
void |
setUseFastReflection(boolean useFastReflection)
Controls if the listener will be invoked using fast reflection or not.
|
handleResult, onEvent, setUpdateOrWrite, setUpdateTimeout, setWriteLease
protected final Log logger
public AbstractReflectionEventListenerAdapter()
public void setDelegate(Object delegate)
protected Object getDelegate()
public void setUseFastReflection(boolean useFastReflection)
true
.public void afterPropertiesSet()
afterPropertiesSet
in interface InitializingBean
protected Object onEventWithResult(Object data, GigaSpace gigaSpace, TransactionStatus txStatus, Object source)
setDelegate(Object)
. If a single event listener delegate method is found, uses the
cached reflection Method. If more than one event listener delegate method is configured uses
reflection to dynamically find the relevant event listener method.onEventWithResult
in class AbstractResultEventListenerAdapter
data
- The event data objectgigaSpace
- A GigaSpace instance that can be used to perform additional operations against the
spacetxStatus
- An optional transaction status allowing to rollback a transaction programmaticallysource
- Optional additional data or the actual source event data object (where relevant)public Object getActualEventListener()
getActualEventListener
in interface EventListenerAdapter
protected abstract Method[] doGetListenerMethods()
Copyright © GigaSpaces.