Search in sources :

Example 1 with VisitController

use of com.ibm.streamsx.topology.generator.spl.GraphUtilities.VisitController in project streamsx.topology by IBMStreams.

the class GraphBuilder method isInLowLatencyRegion.

public boolean isInLowLatencyRegion(BOperator... operators) {
    // handle nested low latency regions
    JSONObject graph = complete();
    final VisitController visitController = new VisitController(Direction.UPSTREAM);
    final int[] openRegionCount = { 0 };
    for (BOperator operator : operators) {
        JSONObject jop = operator.complete();
        GraphUtilities.visitOnce(visitController, Collections.singleton(JSON4JUtilities.gson(jop)), JSON4JUtilities.gson(graph), new Consumer<JsonObject>() {

            private static final long serialVersionUID = 1L;

            @Override
            public void accept(JsonObject jo) {
                String kind = GsonUtilities.jstring(jo, "kind");
                if (LOW_LATENCY.kind().equals(kind)) {
                    if (openRegionCount[0] <= 0)
                        visitController.setStop();
                    else
                        openRegionCount[0]--;
                } else if (END_LOW_LATENCY.kind().equals(kind))
                    openRegionCount[0]++;
            }
        });
        if (visitController.stopped() || openRegionCount[0] > 0)
            return true;
    }
    return false;
}
Also used : VisitController(com.ibm.streamsx.topology.generator.spl.GraphUtilities.VisitController) OrderedJSONObject(com.ibm.json.java.OrderedJSONObject) JSONObject(com.ibm.json.java.JSONObject) JsonObject(com.google.gson.JsonObject)

Aggregations

JsonObject (com.google.gson.JsonObject)1 JSONObject (com.ibm.json.java.JSONObject)1 OrderedJSONObject (com.ibm.json.java.OrderedJSONObject)1 VisitController (com.ibm.streamsx.topology.generator.spl.GraphUtilities.VisitController)1