Skip to content

Instantly share code, notes, and snippets.

{
"howMany": 200,
"millisBetweenNumbers": 1000
}
type: flow
name: producer-consumer
input:
- name: howMany
- name: millisBetweenNumbers
output:
- name: double-value
target: ${consumer.output.output}
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: 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
MyFramework framework = MyFramework.builder()
// initialization code here
.build();
framework.init(Executors.newFixedThreadPool(20));
// 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);
// 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]);
List<Annotation> annotations = Stream.of(m.getDeclaredAnnotations())
.filter(annotation -> annotation.annotationType().isAnnotationPresent(Handler.class))
.collect(Collectors.toList());
public class GetMappingHandler implements AnnotationHandler<GetMapping> {
@Override
public void handle(ScanContext scanContext, FrameworkAnnotationContext<GetMapping> annotationContext) {
String endpoint = annotationContext.getAnnotation().value();
Method m = (Method) annotationContext.getAnnotatedElement();
Object o = annotationContext.getInstance();
scanContext.createMapping(endpoint, m, o);
}
}
public class MyAnnotationHandler implements AnnotationHandler<MyAnnotation> {
@Override
public void handle(ScanContext scanContext, FrameworkAnnotationContext<MyAnnotation> annotationContext) {
System.out.println("Foo is " + annotationContext.getAnnotation().foo());
System.out.println("Bar is " + annotationContext.getAnnotation().bar());
}
}