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 AsyncEventExecutorasyncExecprotected List<AsyncWaitHook>asyncWaitHooksprotected booleanblockAsyncProcessingprotected booleanblockSyncPostCommitProcessingprotected booleanbulkModeEnabledprotected EventDispatcherRegistrydispatchersprotected DescriptorRegistrydomainEventProducersprotected EventListenerListlistenerDescriptorsprotected EventBundleDispatcherpipeDispatcherprotected PostCommitEventExecutorpostCommitExecprotected EventPipeRegistryregisteredPipesprotected static StringREGISTRY_TARGET_NAMEprotected static ThreadLocal<org.nuxeo.ecm.core.event.impl.EventServiceImpl.CompositeEventBundle>threadBundlesstatic VMIDVMID
-
Constructor Summary
Constructors Constructor Description EventServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDomainEventProducer(DomainEventProducerDescriptor descriptor)voidaddEventDispatcher(EventDispatcherDescriptor dispatcherDescriptor)voidaddEventListener(EventListenerDescriptor listener)Adds a new event listener.voidaddEventPipe(EventPipeDescriptor pipeDescriptor)voidafterCompletion(int status)voidbeforeCompletion()List<DomainEventProducer>createDomainEventProducers()Creates the registered domain event producers.voidfireEvent(String name, EventContext context)Fires an event given its name and a context.voidfireEvent(Event event)Fires an event.voidfireEventBundle(EventBundle event)Fires all recorded events in a transaction.voidfireEventBundleSync(EventBundle event)Fires an event bundle in synchronous mode.intgetActiveThreadsCount()EventBundleDispatchergetEventBundleDispatcher()EventListenerDescriptorgetEventListener(String name)Gets the event listener descriptor corresponding to the give name.EventListenerListgetEventListenerList()List<EventListener>getEventListeners()Gets the list of the registered event listeners.intgetEventsInQueueCount()EventListenerListgetListenerList()List<PostCommitEventListener>getPostCommitEventListeners()Get the list of the registered post commit event listeners.protected voidhandleTxCommited()protected voidhandleTxRollbacked()voidinit()protected voidinitDomainEventStreams()booleanisBlockAsyncHandlers()booleanisBlockSyncPostCommitHandlers()booleanisBulkModeEnabled()protected voidrecordEvent(Event event)voidregisterForAsyncWait(AsyncWaitHook callback)voidremoveDomainEventProducer(DomainEventProducerDescriptor descriptor)voidremoveEventDispatcher(EventDispatcherDescriptor dispatcherDescriptor)voidremoveEventListener(EventListenerDescriptor listener)Removes an event listener.voidremoveEventPipe(EventPipeDescriptor pipeDescriptor)voidsetBlockAsyncHandlers(boolean blockAsyncHandlers)voidsetBlockSyncPostCommitHandlers(boolean blockSyncPostComitHandlers)voidsetBulkModeEnabled(boolean bulkModeEnabled)voidsetListenerEnabledFlag(String listenerName, boolean enabled)voidshutdown(long timeoutMillis)protected voidtraceAddAnnotation(Event event, io.opencensus.trace.Tracer tracer, long elapsed, String listener)voidunregisterForAsyncWait(AsyncWaitHook callback)voidwaitForAsyncCompletion()Waits until all asynchronous tasks are finished.voidwaitForAsyncCompletion(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:EventServiceWaits until all asynchronous tasks are finished.- Specified by:
waitForAsyncCompletionin interfaceEventService
-
waitForAsyncCompletion
public void waitForAsyncCompletion(long timeout)
Description copied from interface:EventServiceWaits until all asynchronous tasks are finished, but waits no longer than the given number of milliseconds.- Specified by:
waitForAsyncCompletionin interfaceEventService- Parameters:
timeout- the maximum time to wait for, in milliseconds
-
addEventListener
public void addEventListener(EventListenerDescriptor listener)
Description copied from interface:EventServiceAdds a new event listener. Used by the framework.The event listener is described by a
EventListenerDescriptorthat may specify a priority. Both types of listeners (immediate and post-commit) are registered.- Specified by:
addEventListenerin 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:EventServiceRemoves an event listener. Used by the framework.- Specified by:
removeEventListenerin 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:EventServiceFires an event given its name and a context.- Specified by:
fireEventin interfaceEventService- Parameters:
name- the event namecontext- the event context
-
fireEvent
public void fireEvent(Event event)
Description copied from interface:EventServiceFires an event.If a transaction was started, the event is registered if needed to be sent after the transaction commit.
- Specified by:
fireEventin interfaceEventProducer- Specified by:
fireEventin 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:EventServiceFires all recorded events in a transaction. Used by the framework.The events are fired to
PostCommitEventListenerlisteners. Events are fired in the form of an event bundle.- Specified by:
fireEventBundlein interfaceEventProducer- Specified by:
fireEventBundlein interfaceEventService- Parameters:
event- the event bundle
-
fireEventBundleSync
public void fireEventBundleSync(EventBundle event)
Description copied from interface:EventServiceFires an event bundle in synchronous mode. Used by the framework.This means that asynchronous listeners will be run synchronously.
- Specified by:
fireEventBundleSyncin interfaceEventService
-
getEventListeners
public List<EventListener> getEventListeners()
Description copied from interface:EventServiceGets the list of the registered event listeners.Modification on this list will not modify the internal lists in this
EventService.- Specified by:
getEventListenersin interfaceEventService- Returns:
- the event listeners
-
getPostCommitEventListeners
public List<PostCommitEventListener> getPostCommitEventListeners()
Description copied from interface:EventServiceGet the list of the registered post commit event listeners.Modification on this list will not modify the internal lists in this
EventService.- Specified by:
getPostCommitEventListenersin interfaceEventService- Returns:
- the post commit event listeners
-
getEventListenerList
public EventListenerList getEventListenerList()
-
getEventListener
public EventListenerDescriptor getEventListener(String name)
Description copied from interface:EventServiceGets the event listener descriptor corresponding to the give name.- Specified by:
getEventListenerin interfaceEventService- Parameters:
name- the event listener name- Returns:
- the descriptor, or
nullif not found
-
getListenerList
public EventListenerList getListenerList()
- Specified by:
getListenerListin interfaceEventServiceAdmin
-
setListenerEnabledFlag
public void setListenerEnabledFlag(String listenerName, boolean enabled)
- Specified by:
setListenerEnabledFlagin interfaceEventServiceAdmin
-
getActiveThreadsCount
public int getActiveThreadsCount()
- Specified by:
getActiveThreadsCountin interfaceEventServiceAdmin
-
getEventsInQueueCount
public int getEventsInQueueCount()
- Specified by:
getEventsInQueueCountin interfaceEventServiceAdmin
-
isBlockAsyncHandlers
public boolean isBlockAsyncHandlers()
- Specified by:
isBlockAsyncHandlersin interfaceEventServiceAdmin
-
isBlockSyncPostCommitHandlers
public boolean isBlockSyncPostCommitHandlers()
- Specified by:
isBlockSyncPostCommitHandlersin interfaceEventServiceAdmin
-
setBlockAsyncHandlers
public void setBlockAsyncHandlers(boolean blockAsyncHandlers)
- Specified by:
setBlockAsyncHandlersin interfaceEventServiceAdmin
-
setBlockSyncPostCommitHandlers
public void setBlockSyncPostCommitHandlers(boolean blockSyncPostComitHandlers)
- Specified by:
setBlockSyncPostCommitHandlersin interfaceEventServiceAdmin
-
isBulkModeEnabled
public boolean isBulkModeEnabled()
- Specified by:
isBulkModeEnabledin interfaceEventServiceAdmin
-
setBulkModeEnabled
public void setBulkModeEnabled(boolean bulkModeEnabled)
- Specified by:
setBulkModeEnabledin interfaceEventServiceAdmin
-
recordEvent
protected void recordEvent(Event event)
-
beforeCompletion
public void beforeCompletion()
- Specified by:
beforeCompletionin interfacejavax.transaction.Synchronization
-
afterCompletion
public void afterCompletion(int status)
- Specified by:
afterCompletionin interfacejavax.transaction.Synchronization
-
handleTxRollbacked
protected void handleTxRollbacked()
-
handleTxCommited
protected void handleTxCommited()
-
createDomainEventProducers
public List<DomainEventProducer> createDomainEventProducers()
Description copied from interface:EventServiceCreates the registered domain event producers.- Specified by:
createDomainEventProducersin interfaceEventService
-
initDomainEventStreams
protected void initDomainEventStreams()
-
-