Package org.nuxeo.ecm.core.event.impl
Class EventServiceImpl
- java.lang.Object
-
- org.nuxeo.ecm.core.event.impl.EventServiceImpl
-
- All Implemented Interfaces:
javax.transaction.Synchronization
,EventProducer
,EventService
,EventServiceAdmin
public class EventServiceImpl extends Object implements EventService, EventServiceAdmin, javax.transaction.Synchronization
Implementation of the event service.
-
-
Field Summary
Fields Modifier and Type Field Description protected AsyncEventExecutor
asyncExec
protected List<AsyncWaitHook>
asyncWaitHooks
protected boolean
blockAsyncProcessing
protected boolean
blockSyncPostCommitProcessing
protected boolean
bulkModeEnabled
protected EventDispatcherRegistry
dispatchers
protected DescriptorRegistry
domainEventProducers
protected EventListenerList
listenerDescriptors
protected EventBundleDispatcher
pipeDispatcher
protected PostCommitEventExecutor
postCommitExec
protected EventPipeRegistry
registeredPipes
protected static String
REGISTRY_TARGET_NAME
protected static ThreadLocal<org.nuxeo.ecm.core.event.impl.EventServiceImpl.CompositeEventBundle>
threadBundles
static VMID
VMID
-
Constructor Summary
Constructors Constructor Description EventServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDomainEventProducer(DomainEventProducerDescriptor descriptor)
void
addEventDispatcher(EventDispatcherDescriptor dispatcherDescriptor)
void
addEventListener(EventListenerDescriptor listener)
Adds a new event listener.void
addEventPipe(EventPipeDescriptor pipeDescriptor)
void
afterCompletion(int status)
void
beforeCompletion()
List<DomainEventProducer>
createDomainEventProducers()
Creates the registered domain event producers.void
fireEvent(String name, EventContext context)
Fires an event given its name and a context.void
fireEvent(Event event)
Fires an event.void
fireEventBundle(EventBundle event)
Fires all recorded events in a transaction.void
fireEventBundleSync(EventBundle event)
Fires an event bundle in synchronous mode.int
getActiveThreadsCount()
EventBundleDispatcher
getEventBundleDispatcher()
EventListenerDescriptor
getEventListener(String name)
Gets the event listener descriptor corresponding to the give name.EventListenerList
getEventListenerList()
List<EventListener>
getEventListeners()
Gets the list of the registered event listeners.int
getEventsInQueueCount()
EventListenerList
getListenerList()
List<PostCommitEventListener>
getPostCommitEventListeners()
Get the list of the registered post commit event listeners.protected void
handleTxCommited()
protected void
handleTxRollbacked()
void
init()
protected void
initDomainEventStreams()
boolean
isBlockAsyncHandlers()
boolean
isBlockSyncPostCommitHandlers()
boolean
isBulkModeEnabled()
protected void
recordEvent(Event event)
void
registerForAsyncWait(AsyncWaitHook callback)
void
removeDomainEventProducer(DomainEventProducerDescriptor descriptor)
void
removeEventDispatcher(EventDispatcherDescriptor dispatcherDescriptor)
void
removeEventListener(EventListenerDescriptor listener)
Removes an event listener.void
removeEventPipe(EventPipeDescriptor pipeDescriptor)
void
setBlockAsyncHandlers(boolean blockAsyncHandlers)
void
setBlockSyncPostCommitHandlers(boolean blockSyncPostComitHandlers)
void
setBulkModeEnabled(boolean bulkModeEnabled)
void
setListenerEnabledFlag(String listenerName, boolean enabled)
void
shutdown(long timeoutMillis)
protected void
traceAddAnnotation(Event event, io.opencensus.trace.Tracer tracer, long elapsed, String listener)
void
unregisterForAsyncWait(AsyncWaitHook callback)
void
waitForAsyncCompletion()
Waits until all asynchronous tasks are finished.void
waitForAsyncCompletion(long timeout)
Waits until all asynchronous tasks are finished, but waits no longer than the given number of milliseconds.
-
-
-
Field Detail
-
VMID
public static final VMID VMID
-
threadBundles
protected static final ThreadLocal<org.nuxeo.ecm.core.event.impl.EventServiceImpl.CompositeEventBundle> threadBundles
-
listenerDescriptors
protected final EventListenerList listenerDescriptors
-
postCommitExec
protected PostCommitEventExecutor postCommitExec
-
asyncExec
protected volatile AsyncEventExecutor asyncExec
-
asyncWaitHooks
protected final List<AsyncWaitHook> asyncWaitHooks
-
blockAsyncProcessing
protected boolean blockAsyncProcessing
-
blockSyncPostCommitProcessing
protected boolean blockSyncPostCommitProcessing
-
bulkModeEnabled
protected boolean bulkModeEnabled
-
registeredPipes
protected EventPipeRegistry registeredPipes
-
dispatchers
protected EventDispatcherRegistry dispatchers
-
pipeDispatcher
protected EventBundleDispatcher pipeDispatcher
-
domainEventProducers
protected DescriptorRegistry domainEventProducers
-
REGISTRY_TARGET_NAME
protected static final String REGISTRY_TARGET_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public void init()
-
getEventBundleDispatcher
public EventBundleDispatcher getEventBundleDispatcher()
-
addDomainEventProducer
public void addDomainEventProducer(DomainEventProducerDescriptor descriptor)
-
removeDomainEventProducer
public void removeDomainEventProducer(DomainEventProducerDescriptor descriptor)
-
shutdown
public void shutdown(long timeoutMillis) throws InterruptedException
- Throws:
InterruptedException
-
registerForAsyncWait
public void registerForAsyncWait(AsyncWaitHook callback)
-
unregisterForAsyncWait
public void unregisterForAsyncWait(AsyncWaitHook callback)
-
waitForAsyncCompletion
public void waitForAsyncCompletion()
Description copied from interface:EventService
Waits until all asynchronous tasks are finished.- Specified by:
waitForAsyncCompletion
in interfaceEventService
-
waitForAsyncCompletion
public void waitForAsyncCompletion(long timeout)
Description copied from interface:EventService
Waits until all asynchronous tasks are finished, but waits no longer than the given number of milliseconds.- Specified by:
waitForAsyncCompletion
in interfaceEventService
- Parameters:
timeout
- the maximum time to wait for, in milliseconds
-
addEventListener
public void addEventListener(EventListenerDescriptor listener)
Description copied from interface:EventService
Adds a new event listener. Used by the framework.The event listener is described by a
EventListenerDescriptor
that may specify a priority. Both types of listeners (immediate and post-commit) are registered.- Specified by:
addEventListener
in interfaceEventService
- Parameters:
listener
- the listener to add
-
addEventPipe
public void addEventPipe(EventPipeDescriptor pipeDescriptor)
-
addEventDispatcher
public void addEventDispatcher(EventDispatcherDescriptor dispatcherDescriptor)
-
removeEventListener
public void removeEventListener(EventListenerDescriptor listener)
Description copied from interface:EventService
Removes an event listener. Used by the framework.- Specified by:
removeEventListener
in interfaceEventService
- Parameters:
listener
- the listener to remove
-
removeEventPipe
public void removeEventPipe(EventPipeDescriptor pipeDescriptor)
-
removeEventDispatcher
public void removeEventDispatcher(EventDispatcherDescriptor dispatcherDescriptor)
-
fireEvent
public void fireEvent(String name, EventContext context)
Description copied from interface:EventService
Fires an event given its name and a context.- Specified by:
fireEvent
in interfaceEventService
- Parameters:
name
- the event namecontext
- the event context
-
fireEvent
public void fireEvent(Event event)
Description copied from interface:EventService
Fires an event.If a transaction was started, the event is registered if needed to be sent after the transaction commit.
- Specified by:
fireEvent
in interfaceEventProducer
- Specified by:
fireEvent
in interfaceEventService
- Parameters:
event
- the event to fire
-
traceAddAnnotation
protected void traceAddAnnotation(Event event, io.opencensus.trace.Tracer tracer, long elapsed, String listener)
-
fireEventBundle
public void fireEventBundle(EventBundle event)
Description copied from interface:EventService
Fires all recorded events in a transaction. Used by the framework.The events are fired to
PostCommitEventListener
listeners. Events are fired in the form of an event bundle.- Specified by:
fireEventBundle
in interfaceEventProducer
- Specified by:
fireEventBundle
in interfaceEventService
- Parameters:
event
- the event bundle
-
fireEventBundleSync
public void fireEventBundleSync(EventBundle event)
Description copied from interface:EventService
Fires an event bundle in synchronous mode. Used by the framework.This means that asynchronous listeners will be run synchronously.
- Specified by:
fireEventBundleSync
in interfaceEventService
-
getEventListeners
public List<EventListener> getEventListeners()
Description copied from interface:EventService
Gets the list of the registered event listeners.Modification on this list will not modify the internal lists in this
EventService
.- Specified by:
getEventListeners
in interfaceEventService
- Returns:
- the event listeners
-
getPostCommitEventListeners
public List<PostCommitEventListener> getPostCommitEventListeners()
Description copied from interface:EventService
Get the list of the registered post commit event listeners.Modification on this list will not modify the internal lists in this
EventService
.- Specified by:
getPostCommitEventListeners
in interfaceEventService
- Returns:
- the post commit event listeners
-
getEventListenerList
public EventListenerList getEventListenerList()
-
getEventListener
public EventListenerDescriptor getEventListener(String name)
Description copied from interface:EventService
Gets the event listener descriptor corresponding to the give name.- Specified by:
getEventListener
in interfaceEventService
- Parameters:
name
- the event listener name- Returns:
- the descriptor, or
null
if not found
-
getListenerList
public EventListenerList getListenerList()
- Specified by:
getListenerList
in interfaceEventServiceAdmin
-
setListenerEnabledFlag
public void setListenerEnabledFlag(String listenerName, boolean enabled)
- Specified by:
setListenerEnabledFlag
in interfaceEventServiceAdmin
-
getActiveThreadsCount
public int getActiveThreadsCount()
- Specified by:
getActiveThreadsCount
in interfaceEventServiceAdmin
-
getEventsInQueueCount
public int getEventsInQueueCount()
- Specified by:
getEventsInQueueCount
in interfaceEventServiceAdmin
-
isBlockAsyncHandlers
public boolean isBlockAsyncHandlers()
- Specified by:
isBlockAsyncHandlers
in interfaceEventServiceAdmin
-
isBlockSyncPostCommitHandlers
public boolean isBlockSyncPostCommitHandlers()
- Specified by:
isBlockSyncPostCommitHandlers
in interfaceEventServiceAdmin
-
setBlockAsyncHandlers
public void setBlockAsyncHandlers(boolean blockAsyncHandlers)
- Specified by:
setBlockAsyncHandlers
in interfaceEventServiceAdmin
-
setBlockSyncPostCommitHandlers
public void setBlockSyncPostCommitHandlers(boolean blockSyncPostComitHandlers)
- Specified by:
setBlockSyncPostCommitHandlers
in interfaceEventServiceAdmin
-
isBulkModeEnabled
public boolean isBulkModeEnabled()
- Specified by:
isBulkModeEnabled
in interfaceEventServiceAdmin
-
setBulkModeEnabled
public void setBulkModeEnabled(boolean bulkModeEnabled)
- Specified by:
setBulkModeEnabled
in interfaceEventServiceAdmin
-
recordEvent
protected void recordEvent(Event event)
-
beforeCompletion
public void beforeCompletion()
- Specified by:
beforeCompletion
in interfacejavax.transaction.Synchronization
-
afterCompletion
public void afterCompletion(int status)
- Specified by:
afterCompletion
in interfacejavax.transaction.Synchronization
-
handleTxRollbacked
protected void handleTxRollbacked()
-
handleTxCommited
protected void handleTxCommited()
-
createDomainEventProducers
public List<DomainEventProducer> createDomainEventProducers()
Description copied from interface:EventService
Creates the registered domain event producers.- Specified by:
createDomainEventProducers
in interfaceEventService
-
initDomainEventStreams
protected void initDomainEventStreams()
-
-