Annotation Interface SubscribingAnnotation
@Subscribe does, and has the bus
deliver their events through an executor, such as on a given thread.
@SubscribingAnnotation(executor = EdtExecutor.class)
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.METHOD)
public @interface OnEdt {}
public final class EdtExecutor implements Executor {
@Override
public void execute(Runnable task) {
EventQueue.invokeLater(task);
}
}
class Window {
@OnEdt
void onPlaced(OrderPlaced event) {
...
}
}
The bus creates the executor the first time it registers a listener with such methods, with its constructor without parameters, and shares it among all the listeners it registers with them, unless it was built with another executor for the annotation. During the delivery of an event, the bus hands such a method a task that calls it, and goes on to the other subscribers without waiting for it.
The bus never shuts the executor down: a bus has no end of its own, and keeps its executors as long as it is reachable. Each bus creates its own executor, so an executor that owns threads, which keep it and its class loader reachable, is meant for a bus that lives as long as its application, or for an executor that ends its threads once idle. To shut an executor down, build the bus with it and shut it down once the bus is no longer used.
gaia-processor checks such methods as it checks @Subscribe ones, and reports an error for a method
with more than one subscribing annotation, @Subscribe included. The generated code refers to the annotation,
and creates the executor: it reports an error for an annotation or an executor that it cannot access from the package
of the listener, and for an executor that is abstract, an inner class, or without an accessible constructor without
parameters, or whose constructor without parameters declares checked exceptions. On the declaration of the
annotation, it reports the same problems for any package the annotation can be used from: a public annotation needs a
public executor, with a public constructor without parameters. It reports a retention of SOURCE too: the
processor needs to see the annotation on the methods of classes compiled before, to report the methods that override
them.
The processor only finds the methods annotated with an annotation that has this meta-annotation itself, not through other annotations.
- Since:
- 0.1.2
-
Required Element Summary
Required Elements
-
Element Details
-
executor
-