Skip to content

Instantly share code, notes, and snippets.

List<Annotation> annotations = Stream.of(m.getDeclaredAnnotations())
.filter(annotation -> annotation.annotationType().isAnnotationPresent(Handler.class))
.collect(Collectors.toList());
// Get the handler type from the @Handler annotation
Class<? extends AnnotationHandler> handlerType = annotation.annotationType().getAnnotation(Handler.class).value();
// Get and invoke the only constructor (which needs to be an empty one, unless you need a more complex behavior)
AnnotationHandler handler = (AnnotationHandler) Stream.of(handlerType.getConstructors())
.findFirst()
.get()
.newInstance(new Object[0]);
// Get a reference to the "handle" method
Method handle = handlerType.getDeclaredMethod("handle",
new Class<?>[] {
ScanContext.class, FrameworkAnnotationContext.class
});
// Create a FrameworkAnnotationContext instance by passing the annotation to process,
// the instance being scanned and the method where the annotation is placed
FrameworkAnnotationContext<Annotation> annotationContext = new FrameworkAnnotationContext<>(annotation, instance, m);
MyFramework framework = MyFramework.builder()
// initialization code here
.build();
framework.init(Executors.newFixedThreadPool(20));
type: micropipe
name: slow-printer
image: "slow-printer:latest"
inputMapping:
baseCmd: java -jar /usr/bin/slow-printer-1.0-SNAPSHOT.jar
parameters:
- name: howMany
internalName: --howMany
- name: millisBetweenNumbers
internalName: --millisBetweenNumbers
type: micropipe
name: simple-consumer
image: "simple-consumer:latest"
inputMapping:
baseCmd: java -jar /usr/bin/simple-consumer-1.0-SNAPSHOT.jar
parameters:
- name: source
internalName: --source
optional: false
repeatable: false
type: flow
name: producer-consumer
input:
- name: howMany
- name: millisBetweenNumbers
output:
- name: double-value
target: ${consumer.output.output}
{
"howMany": 200,
"millisBetweenNumbers": 1000
}