public interface TriggerStrategy
Trigger annotation is handled in order to extract
scheduling meta information and to actually schedule method invocations.
The framework searches for implementations of this class using the Java's
ServiceLoader. In order to implement your own trigger, just follow these steps:
@Trigger
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface CustomTrigger {
// meta information fields
}
public class CustomTriggerStrategy implements TriggerStrategy {
// Field injection is allowed
@Inject
private Injector injector;
// public no-argument constructor required (because of the ServiceLoader)!
@Override
public Class<CustomTrigger> getTriggerType() {
return CustomTrigger.class;
}
@Override
public void schedule(Method method, Object self,
ScheduledExecutorService executor) {
// read trigger annotation from the method
CustomTrigger trigger = method.getAnnotation(getTriggerType());
// use meta information from the trigger to schedule the execution with the
// provided executor (might want to use InjectedMethodInvocation class)
executor.schedule(...);
}
}
| Modifier and Type | Method and Description |
|---|---|
Class<? extends Annotation> |
getTriggerType()
Returns the annotation type that this strategy can handle.
|
ScheduledContext |
schedule(Method method,
Object self,
ScheduledExecutorService executor,
ExceptionHandler handler)
Extracts scheduling information from the provided
Method and then schedules
invocations of that method according to the information. |
Class<? extends Annotation> getTriggerType()
ScheduledContext schedule(Method method, Object self, ScheduledExecutorService executor, ExceptionHandler handler)
Method and then schedules
invocations of that method according to the information.
To support invocation of parameterized methods, implementors can refer to
InjectedMethodInvocation to inject actual parameters of a method.
method - The method to schedule.self - The object to invoke the method on. This will be null in case that the
method is static.executor - The executor to use for scheduling.handler - The exception handler to be used.ScheduledContext.Copyright © 2014–2018. All rights reserved.