kz.greetgo.scheduling.AbstractTaskCollector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of greetgo.scheduling Show documentation
Show all versions of greetgo.scheduling Show documentation
Scheduler using in greetgo!
package kz.greetgo.scheduling;
import kz.greetgo.scheduling.context.SchedulerContext;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import static java.util.Collections.unmodifiableList;
public abstract class AbstractTaskCollector {
public String defaultPoolName = "default";
private final List tasks = new ArrayList<>();
protected abstract SchedulerContext getSchedulerContext(Class> controllerClass);
public List getTasks() {
return unmodifiableList(tasks);
}
public void collect(Object controller) {
final Class> controllerClass = controller.getClass();
String topPoolName = defaultPoolName;
final UsePool classUsePool = controllerClass.getAnnotation(UsePool.class);
if (classUsePool != null) topPoolName = classUsePool.value().trim();
SchedulerContext schedulerContext = getSchedulerContext(controllerClass);
for (Method method : controllerClass.getMethods()) {
final SchedulerMatcherTrigger smt = SchedulerMatcherTrigger.create(method, controller, schedulerContext);
if (smt == null) continue;
String poolName = topPoolName;
final UsePool usePool = controllerClass.getAnnotation(UsePool.class);
if (usePool != null) poolName = usePool.value();
tasks.add(new Task(poolName, smt.job, smt, schedulerContext.throwableCatcher()));
}
}
}