Interface EventService

  • All Superinterfaces:
    All Known Implementing Classes:

    public interface EventService
    extends EventProducer
    The event service manages listener registries and notifies listeners about core events.

    The service is able to run in a transactional mode where all events are recorded and fired after the transaction commits in one step as an event bundle.

    To start a transaction, the framework calls the transactionStarted() method, and at transaction commit the framework calls transactionCommitted() to fire the event bundle. Upon rollback the framework calls transactionRolledback() to clean up recorded events.

    Events are recorded in a thread variable so they are valid only in the current thread.

    An event marked Event.isInline() is dispatched immediately, otherwise it is recorded in a thread-based bundle of current events. If no transaction was started, an event marked Event.isCommitEvent() is used to flush the event bundle to its listeners, otherwise the transaction commit does the flush.

    Listeners are of two types: EventListener notified as the event is raised and PostCommitEventListener notified after the transaction was committed.

    • Method Detail

      • addEventListener

        void addEventListener​(EventListenerDescriptor listener)
        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.

        listener - the listener to add
      • fireEvent

        void fireEvent​(String name,
                       EventContext context)
        Fires an event given its name and a context.
        name - the event name
        context - the event context
      • fireEvent

        void fireEvent​(Event event)
        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 interface EventProducer
        event - the event to fire
      • fireEventBundleSync

        void fireEventBundleSync​(EventBundle event)
        Fires an event bundle in synchronous mode. Used by the framework.

        This means that asynchronous listeners will be run synchronously.

      • getEventListener

        EventListenerDescriptor getEventListener​(String name)
        Gets the event listener descriptor corresponding to the give name.
        name - the event listener name
        the descriptor, or null if not found
      • waitForAsyncCompletion

        void waitForAsyncCompletion​(long timeout)
        Waits until all asynchronous tasks are finished, but waits no longer than the given number of milliseconds.
        timeout - the maximum time to wait for, in milliseconds