Class ScheduleBeanPostProcessor

java.lang.Object
com.bobocode.bring.core.bpp.impl.ScheduleBeanPostProcessor
All Implemented Interfaces:
BeanPostProcessor

public class ScheduleBeanPostProcessor extends Object implements BeanPostProcessor
A BeanProcessor responsible for processing beans and registering methods annotated with @ScheduledTask for scheduling via a CustomScheduler.

This class scans for methods annotated with @ScheduledTask in Bring-managed beans and schedules them for execution using the provided CustomScheduler.

Example usage: This processor can be registered in a Bring context to automatically schedule methods annotated with @ScheduledTask at specified intervals.

Usage example:



 import com.bobocode.bring.core.annotation.Component;
 import com.bobocode.bring.core.anotation.ScheduledTask;

 import java.time.LocalDateTime;

 @Component
 public class MyScheduledTasks {

     @ScheduledTask(value = "myTask", period = 10000)
     public void scheduledMethod1() {
         System.out.println(Thread.currentThread().getName() + " scheduledMethod1 " + LocalDateTime.now());
     }
 }

 
Since:
1.0
Author:
Blyzhnytsia Team
See Also:
  • Field Details

    • customScheduler

      private final CustomScheduler customScheduler
      The CustomScheduler used for scheduling tasks.
  • Constructor Details

    • ScheduleBeanPostProcessor

      public ScheduleBeanPostProcessor(CustomScheduler customScheduler)
  • Method Details

    • postProcessInitialization

      public Object postProcessInitialization(Object bean, String beanName)
      Processes bean initialization and schedules methods annotated with @ScheduledTask.
      Specified by:
      postProcessInitialization in interface BeanPostProcessor
      Parameters:
      bean - the bean instance
      beanName - the name of the bean
      Returns:
      the processed bean
    • invokeTaskMethod

      private void invokeTaskMethod(Object bean, Method method, String taskName)
      Invokes the method annotated with @ScheduledTask on the provided bean instance.
      Parameters:
      bean - the bean instance
      method - the method to be invoked
      taskName - the name of the scheduled task