Annotation Type LifecycleParticipant


  • @Documented
    @Target(METHOD)
    @Retention(RUNTIME)
    @Inherited
    public @interface LifecycleParticipant
    Annotates the lifecycle participating method.

    This annotation is used in conjunction with LifecycleService annotation. It allows to mark lifecycle service methods and point the phase it participates and the dependencies to other services.
    The requirements for lifecycle participant method:

    • The method may have zero, one or two arguments
    • The method arguments types must be LifecyclePhase type or ILifecycleContext or its succesor
    • The method with two arguments must have arguments with different types
    • The method should be of void type
    In case when method has an argument of ILifecycleContext successor type, it means the method will participate only if the actual type of the lifecycle context to process is of the same type or is assignable from it.
    The method visibility doesn't matter.

    The 'phase' attribute is required and 'dependsOn' has default empty value.

    Example:

    
          @LifecycleService(name = "MyService")
          public class MyService
          {
              @LifecycleParticipant(phase = LifecyclePhase.CHECKING)
              public void check()
              {
                  // ...
              }
    
              @LifecycleParticipant(phase = LifecyclePhase.INITIALIZATION)
              public void init(LifecyclePhase phase)
              {
                  // ...
              }
    
              @LifecycleParticipant(phase = LifecyclePhase.RESOURCE_LOADING)
              public void load(ILifecycleContext context)
              {
                  // ...
              }
    
              @LifecycleParticipant(phase = LifecyclePhase.POST_RESOURCE_LOADING)
              public void postLoad(ILifecycleContext context, LifecyclePhase phase)
              {
                  // empty
              }
    
              @LifecycleParticipant(phase = LifecyclePhase.STORAGE_INITIALIZATION)
              protected void initStorage(LifecyclePhase phase, ILifecycleContext context)
              {
                  // empty
              }
    
              @LifecycleParticipant(phase = LifecyclePhase.STORAGE_CLOSING)
              private void closeStorage(TestContext context)
              {
                  // invoked only for TestContext type.
                  // ...
              }
     

    Since:
    3.0.0
    See Also:
    LifecycleService
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      LifecyclePhase phase
      The participating lifecycle phase.
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      String[] dependsOn
      Returns an array of lifecycle services names that are dependencies for the current participant.
    • Element Detail

      • phase

        LifecyclePhase phase
        The participating lifecycle phase.
        Returns:
        the lifecycle phase, never null.
      • dependsOn

        String[] dependsOn
        Returns an array of lifecycle services names that are dependencies for the current participant.
        Returns:
        the dependencies array, never null.
        Default:
        {}