-
Notifications
You must be signed in to change notification settings - Fork 7
/
DistributedTaskExecutorLoadAction.java
56 lines (48 loc) · 1.92 KB
/
DistributedTaskExecutorLoadAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Made with all the love in the world
* by scireum in Remshalden, Germany
*
* Copyright by scireum GmbH
* http://www.scireum.de - [email protected]
*/
package sirius.biz.cluster.work;
import sirius.kernel.di.ClassLoadAction;
import sirius.kernel.di.Injector;
import sirius.kernel.di.MutableGlobalContext;
import sirius.kernel.di.std.Register;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Modifier;
/**
* Automatically registers all sublcasses of {@link DistributedTaskExecutor} with the class name as name.
*/
public class DistributedTaskExecutorLoadAction implements ClassLoadAction {
@Nullable
@Override
public Class<? extends Annotation> getTrigger() {
return null;
}
@Override
public void handle(@Nonnull MutableGlobalContext mutableGlobalContext, @Nonnull Class<?> aClass) throws Exception {
if (!DistributedTaskExecutor.class.isAssignableFrom(aClass) || Modifier.isAbstract(aClass.getModifiers())) {
return;
}
if (aClass.isAnnotationPresent(Register.class)) {
Injector.LOG.WARN(
"%s should not wear an @Registered, as subclasses of DistributedTaskExecutor are automatically loaded.",
aClass.getName());
}
try {
Object anInstance = aClass.getDeclaredConstructor().newInstance();
mutableGlobalContext.registerPart(anInstance.getClass().getName(),
anInstance,
DistributedTaskExecutor.class);
} catch (Exception exception) {
Injector.LOG.WARN("Cannot register %s as DistributedTaskExecutor: %s (%s)",
aClass.getName(),
exception.getMessage(),
exception.getClass().getName());
}
}
}