Class Lifecycle


  • public class Lifecycle
    extends Object
    Collects objects which were created during the configuration phase and have a lifecycle annotation, and provide functions to execute these lifecycle methods later. Lifecycle annotations recognized are PostConstruct and PreDestroy.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.List<mireka.startup.Lifecycle.ManagedObject> managedObjects  
    • Constructor Summary

      Constructors 
      Constructor Description
      Lifecycle()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addManagedObject​(Object object)
      Registers the object if it has at least one method which is marked with a lifecycle annotation.
      static void callPostConstructMethods()
      Calls the methods of the registered objects which were marked with the PostConstruct annotation in the order of their registration.
      static void callPreDestroyMethods()
      Calls the methods of the successfully initialized registered objects which were marked with the PreDestroy annotation in the opposite order of their registrations.
      • Methods inherited from class java.lang.Object

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

      • managedObjects

        public static final java.util.List<mireka.startup.Lifecycle.ManagedObject> managedObjects
    • Constructor Detail

      • Lifecycle

        public Lifecycle()
    • Method Detail

      • addManagedObject

        public static void addManagedObject​(Object object)
        Registers the object if it has at least one method which is marked with a lifecycle annotation. This function must be called for every object which were created during the configuration.
        Parameters:
        object - the object which may have a lifecycle annotation
      • callPostConstructMethods

        public static void callPostConstructMethods()
                                             throws java.lang.reflect.InvocationTargetException,
                                                    InvalidMethodSignatureException
        Calls the methods of the registered objects which were marked with the PostConstruct annotation in the order of their registration.
        Throws:
        java.lang.reflect.InvocationTargetException - thrown if a called method has thrown an exception
        InvalidMethodSignatureException - thrown if the method could not be called because it has arguments.
      • callPreDestroyMethods

        public static void callPreDestroyMethods()
        Calls the methods of the successfully initialized registered objects which were marked with the PreDestroy annotation in the opposite order of their registrations. The PreDestroy method is not called on an object
        • if it has a PostConstruct method which has thrown an exception during startup
        • another object which was registered earlier than this object has thrown an exception in its PostConstruct method.