Class LifecycleEventManager

  • All Implemented Interfaces:
    java.io.Serializable, CallbackModes
    Direct Known Subclasses:
    ValidatingLifecycleEventManager

    public class LifecycleEventManager
    extends java.lang.Object
    implements CallbackModes, java.io.Serializable
    Manager that can be used to track and notify listeners on lifecycle events. This class is optimized for event firing rather than for adding and removing listeners, which are O(n) operations. This class also does not maintain perfect set semantics for listeners; it is possible to wind up having the same listener invoked multiple times for a single event if it is added to this manager multiple times with different classes, or with a base class and its subclass.
    Since:
    0.3.3
    Author:
    Steve Kim, Abe White
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  LifecycleEventManager.ListenerAdapter
      Interface that facades to other lifecycle listener interfaces can implement to choose which events to respond to based on their delegate.
      static class  LifecycleEventManager.ListenerList
      Extended list that tracks what event types its elements care about.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addListener​(java.lang.Object listener, java.lang.Class<?>[] classes)
      Register a lifecycle listener for the given classes.
      java.lang.Exception[] fireEvent​(java.lang.Object source, java.lang.Object related, ClassMetaData meta, int type)
      Fire lifecycle event to all registered listeners.
      java.lang.Exception[] fireEvent​(java.lang.Object source, ClassMetaData meta, int type)
      Fire lifecycle event to all registered listeners without an argument.
      boolean hasAttachListeners​(java.lang.Object source, ClassMetaData meta)
      Return whether there are listeners or callbacks for the given source.
      boolean hasClearListeners​(java.lang.Object source, ClassMetaData meta)
      Return whether there are listeners or callbacks for the given source.
      boolean hasDeleteListeners​(java.lang.Object source, ClassMetaData meta)
      Return whether there are listeners or callbacks for the given source.
      boolean hasDetachListeners​(java.lang.Object source, ClassMetaData meta)
      Return whether there are listeners or callbacks for the given source.
      boolean hasDirtyListeners​(java.lang.Object source, ClassMetaData meta)
      Return whether there are listeners or callbacks for the given source.
      boolean hasLoadListeners​(java.lang.Object source, ClassMetaData meta)
      Return whether there are listeners or callbacks for the given source.
      boolean hasPersistListeners​(java.lang.Object source, ClassMetaData meta)
      Return whether there are listeners or callbacks for the given source.
      boolean hasStoreListeners​(java.lang.Object source, ClassMetaData meta)
      Return whether there are listeners or callbacks for the given source.
      boolean hasUpdateListeners​(java.lang.Object source, ClassMetaData meta)
      Return whether there are listeners or callbacks for the given source.
      boolean isActive​(ClassMetaData meta)
      Whether this LifeCycleEventManager has had at least one listener or callback registered.
      boolean isFailFast()
      Whether to fail after first exception when firing events to listeners.
      void removeListener​(java.lang.Object listener)
      Remove the given listener.
      void setFailFast​(boolean failFast)
      Whether to fail after first exception when firing events to listeners.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LifecycleEventManager

        public LifecycleEventManager()
    • Method Detail

      • isActive

        public boolean isActive​(ClassMetaData meta)
        Whether this LifeCycleEventManager has had at least one listener or callback registered. Used for a quick test when firing events.
        Returns:
        boolean
      • isFailFast

        public boolean isFailFast()
        Whether to fail after first exception when firing events to listeners.
      • setFailFast

        public void setFailFast​(boolean failFast)
        Whether to fail after first exception when firing events to listeners.
      • addListener

        public void addListener​(java.lang.Object listener,
                                java.lang.Class<?>[] classes)
        Register a lifecycle listener for the given classes. If the classes array is null, register for all classes.
      • removeListener

        public void removeListener​(java.lang.Object listener)
        Remove the given listener.
      • hasPersistListeners

        public boolean hasPersistListeners​(java.lang.Object source,
                                           ClassMetaData meta)
        Return whether there are listeners or callbacks for the given source.
      • hasDeleteListeners

        public boolean hasDeleteListeners​(java.lang.Object source,
                                          ClassMetaData meta)
        Return whether there are listeners or callbacks for the given source.
      • hasClearListeners

        public boolean hasClearListeners​(java.lang.Object source,
                                         ClassMetaData meta)
        Return whether there are listeners or callbacks for the given source.
      • hasLoadListeners

        public boolean hasLoadListeners​(java.lang.Object source,
                                        ClassMetaData meta)
        Return whether there are listeners or callbacks for the given source.
      • hasStoreListeners

        public boolean hasStoreListeners​(java.lang.Object source,
                                         ClassMetaData meta)
        Return whether there are listeners or callbacks for the given source.
      • hasUpdateListeners

        public boolean hasUpdateListeners​(java.lang.Object source,
                                          ClassMetaData meta)
        Return whether there are listeners or callbacks for the given source.
      • hasDirtyListeners

        public boolean hasDirtyListeners​(java.lang.Object source,
                                         ClassMetaData meta)
        Return whether there are listeners or callbacks for the given source.
      • hasDetachListeners

        public boolean hasDetachListeners​(java.lang.Object source,
                                          ClassMetaData meta)
        Return whether there are listeners or callbacks for the given source.
      • hasAttachListeners

        public boolean hasAttachListeners​(java.lang.Object source,
                                          ClassMetaData meta)
        Return whether there are listeners or callbacks for the given source.
      • fireEvent

        public java.lang.Exception[] fireEvent​(java.lang.Object source,
                                               ClassMetaData meta,
                                               int type)
        Fire lifecycle event to all registered listeners without an argument.
      • fireEvent

        public java.lang.Exception[] fireEvent​(java.lang.Object source,
                                               java.lang.Object related,
                                               ClassMetaData meta,
                                               int type)
        Fire lifecycle event to all registered listeners.