Search in sources :

Example 1 with OutputPortDeclaration

use of com.ibm.streams.flow.declare.OutputPortDeclaration in project streamsx.topology by IBMStreams.

the class BOperatorInvocation method addOutput.

public BOutputPort addOutput(StreamSchema schema) {
    if (outputs == null)
        outputs = new ArrayList<>();
    final OutputPortDeclaration port = op.addOutput(schema);
    final BOutputPort stream = new BOutputPort(this, port);
    outputs.add(stream);
    return stream;
}
Also used : ArrayList(java.util.ArrayList) OutputPortDeclaration(com.ibm.streams.flow.declare.OutputPortDeclaration)

Example 2 with OutputPortDeclaration

use of com.ibm.streams.flow.declare.OutputPortDeclaration in project streamsx.topology by IBMStreams.

the class EmbeddedGraph method declareOutputs.

private void declareOutputs(OperatorInvocation<? extends Operator> opDecl, JsonArray outputs) {
    if (GsonUtilities.jisEmpty(outputs))
        return;
    // Ensure we deal with them in port order.
    JsonObject[] ports = new JsonObject[outputs.size()];
    for (JsonElement e : outputs) {
        JsonObject output = e.getAsJsonObject();
        ports[output.get("index").getAsInt()] = output;
    }
    for (JsonObject output : ports) {
        String name = jstring(output, "name");
        StreamSchema schema = Type.Factory.getTupleType(jstring(output, "type")).getTupleSchema();
        OutputPortDeclaration port = opDecl.addOutput(name, schema);
        assert !outputPorts.containsKey(name);
        outputPorts.put(name, port);
    }
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) OutputPortDeclaration(com.ibm.streams.flow.declare.OutputPortDeclaration) StreamSchema(com.ibm.streams.operator.StreamSchema)

Example 3 with OutputPortDeclaration

use of com.ibm.streams.flow.declare.OutputPortDeclaration in project streamsx.topology by IBMStreams.

the class EmbeddedGraph method declareOpConnections.

private void declareOpConnections(JsonObject json) {
    JsonArray outputs = json.getAsJsonArray("outputs");
    if (jisEmpty(outputs))
        return;
    for (JsonElement e : outputs) {
        JsonObject output = e.getAsJsonObject();
        String name = jstring(output, "name");
        JsonArray conns = output.getAsJsonArray("connections");
        if (jisEmpty(conns))
            continue;
        OutputPortDeclaration port = requireNonNull(outputPorts.get(name));
        for (JsonElement c : conns) {
            String iname = c.getAsString();
            InputPortDeclaration iport = requireNonNull(inputPorts.get(iname));
            port.connect(iport);
        }
    }
}
Also used : JsonArray(com.google.gson.JsonArray) InputPortDeclaration(com.ibm.streams.flow.declare.InputPortDeclaration) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) OutputPortDeclaration(com.ibm.streams.flow.declare.OutputPortDeclaration)

Example 4 with OutputPortDeclaration

use of com.ibm.streams.flow.declare.OutputPortDeclaration in project streamsx.topology by IBMStreams.

the class EmbeddedTesterRuntime method setupEmbeddedTestHandlers.

private void setupEmbeddedTestHandlers(EmbeddedGraph eg) throws Exception {
    // Embedded does not support a StreamHandler against
    // a connected stream. In that case add a no-op intermediate stream.
    Set<TStream<?>> adds = new HashSet<>();
    // Find all that are connected.
    for (TStream<?> stream : handlers.keySet()) {
        if (stream.output().isConnected())
            adds.add(stream);
    }
    // Insert a filter for the handler.
    for (TStream<?> stream : adds) {
        TStream<?> filter = stream.filter(t -> true);
        Set<StreamHandler<Tuple>> handler = handlers.get(stream);
        handlers.remove(stream);
        handlers.put(filter, handler);
    }
    final JavaTestableGraph tg = eg.getExecutionGraph();
    for (TStream<?> stream : handlers.keySet()) {
        Set<StreamHandler<Tuple>> streamHandlers = handlers.get(stream);
        final BOutput output = stream.output();
        final OutputPortDeclaration portDecl = eg.getOutputPort(output.name());
        for (StreamHandler<Tuple> streamHandler : streamHandlers) {
            tg.registerStreamHandler(portDecl, streamHandler);
        }
    }
}
Also used : TStream(com.ibm.streamsx.topology.TStream) BOutput(com.ibm.streamsx.topology.builder.BOutput) StreamHandler(com.ibm.streams.flow.handlers.StreamHandler) OutputPortDeclaration(com.ibm.streams.flow.declare.OutputPortDeclaration) JavaTestableGraph(com.ibm.streams.flow.javaprimitives.JavaTestableGraph) Tuple(com.ibm.streams.operator.Tuple) HashSet(java.util.HashSet)

Aggregations

OutputPortDeclaration (com.ibm.streams.flow.declare.OutputPortDeclaration)4 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 JsonArray (com.google.gson.JsonArray)1 InputPortDeclaration (com.ibm.streams.flow.declare.InputPortDeclaration)1 StreamHandler (com.ibm.streams.flow.handlers.StreamHandler)1 JavaTestableGraph (com.ibm.streams.flow.javaprimitives.JavaTestableGraph)1 StreamSchema (com.ibm.streams.operator.StreamSchema)1 Tuple (com.ibm.streams.operator.Tuple)1 TStream (com.ibm.streamsx.topology.TStream)1 BOutput (com.ibm.streamsx.topology.builder.BOutput)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1