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.
|
void |
schedule(Method method,
Object self,
ScheduledExecutorService executor)
Extracts scheduling information from the provided
Method and then
schedules invocations of that method according to the information. |
Class<? extends Annotation> getTriggerType()
void schedule(Method method, Object self, ScheduledExecutorService executor)
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.executor - The executor to use for scheduling.Copyright © 2014–2016. All rights reserved.