Package mireka.startup
Class Lifecycle
- Object
-
- mireka.startup.Lifecycle
-
public class Lifecycle extends ObjectCollects 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 arePostConstructandPreDestroy.
-
-
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 voidaddManagedObject(Object object)Registers the object if it has at least one method which is marked with a lifecycle annotation.static voidcallPostConstructMethods()Calls the methods of the registered objects which were marked with thePostConstructannotation in the order of their registration.static voidcallPreDestroyMethods()Calls the methods of the successfully initialized registered objects which were marked with thePreDestroyannotation in the opposite order of their registrations.
-
-
-
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, InvalidMethodSignatureExceptionCalls the methods of the registered objects which were marked with thePostConstructannotation in the order of their registration.- Throws:
java.lang.reflect.InvocationTargetException- thrown if a called method has thrown an exceptionInvalidMethodSignatureException- 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 thePreDestroyannotation 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.
-
-