Package com.bobocode.bring.core.bpp.impl
Class ScheduleBeanPostProcessor
java.lang.Object
com.bobocode.bring.core.bpp.impl.ScheduleBeanPostProcessor
- All Implemented Interfaces:
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 Summary
Modifier and TypeFieldDescriptionprivate final CustomScheduler
The CustomScheduler used for scheduling tasks. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate void
invokeTaskMethod
(Object bean, Method method, String taskName) Invokes the method annotated with @ScheduledTask on the provided bean instance.postProcessInitialization
(Object bean, String beanName) Processes bean initialization and schedules methods annotated with @ScheduledTask.
-
Field Details
-
customScheduler
The CustomScheduler used for scheduling tasks.
-
-
Constructor Details
-
ScheduleBeanPostProcessor
-
-
Method Details
-
postProcessInitialization
Processes bean initialization and schedules methods annotated with @ScheduledTask.- Specified by:
postProcessInitialization
in interfaceBeanPostProcessor
- Parameters:
bean
- the bean instancebeanName
- the name of the bean- Returns:
- the processed bean
-
invokeTaskMethod
Invokes the method annotated with @ScheduledTask on the provided bean instance.- Parameters:
bean
- the bean instancemethod
- the method to be invokedtaskName
- the name of the scheduled task
-