use of ru.fix.completable.reactor.graph.Graphable in project completable-reactor by ru-fix.
the class CompletableReactor method registerGraphIfAbsent.
// TODO: execute validation during graph registration
/**
* Test graph configuration.
* Check all execution paths.
* Validated that there is no conflicts between merging vertices and all required endpoints exist.
*/
public <GraphConfigType extends Graphable> boolean registerGraphIfAbsent(Class<GraphConfigType> graphConfigClass) {
Objects.requireNonNull(graphConfigClass, "graphConfigClass");
AtomicBoolean isComputed = new AtomicBoolean(false);
glGraphConfigs.computeIfAbsent(graphConfigClass, type -> {
try {
Class payloadType = getPayloadTypeForGraphConfigBasedClass(graphConfigClass);
Graphable graphConfig;
try {
Constructor<GraphConfigType> ctor = graphConfigClass.getDeclaredConstructor();
if (!ctor.isAccessible()) {
ctor.setAccessible(true);
}
graphConfig = ctor.newInstance();
} catch (Exception exc) {
throw new IllegalArgumentException("" + "Failed to instantiate graph config instance of class: " + graphConfigClass + "." + " Graph config class should have default no arg constructor." + " If it is inner class then it sould be static.", exc);
}
GlGraph graph = graphBuilder.buildGraph(graphConfig);
glPayloadGraphs.putIfAbsent(payloadType, graph);
isComputed.set(true);
} catch (Exception exc) {
throw new RuntimeException("Failed to register graph config in ReactorGraph: " + graphConfigClass, exc);
}
return true;
});
return isComputed.get();
}