Search in sources :

Example 1 with Graphable

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();
}
Also used : GlGraph(ru.fix.completable.reactor.graph.runtime.GlGraph) Graphable(ru.fix.completable.reactor.graph.Graphable)

Aggregations

Graphable (ru.fix.completable.reactor.graph.Graphable)1 GlGraph (ru.fix.completable.reactor.graph.runtime.GlGraph)1