Search in sources :

Example 11 with BOperatorInvocation

use of com.ibm.streamsx.topology.builder.BOperatorInvocation in project streamsx.topology by IBMStreams.

the class Topology method _periodicMultiSource.

private <T> TStream<T> _periodicMultiSource(Supplier<Iterable<T>> data, long period, TimeUnit unit, Type tupleType) {
    String opName = LogicUtils.functionName(data);
    if (opName.isEmpty()) {
        opName = TypeDiscoverer.getTupleName(tupleType) + "PeriodicMultiSource";
    } else if (data instanceof Constants) {
        opName = TypeDiscoverer.getTupleName(tupleType) + opName;
    }
    double dperiod = ((double) unit.toMillis(period)) / 1000.0;
    Map<String, Object> params = new HashMap<>();
    params.put("period", dperiod);
    BOperatorInvocation bop = JavaFunctional.addFunctionalOperator(this, opName, FunctionPeriodicSource.class, data, params);
    SourceInfo.setSourceInfo(bop, getClass());
    return JavaFunctional.addJavaOutput(this, bop, tupleType);
}
Also used : HashMap(java.util.HashMap) Constants(com.ibm.streamsx.topology.internal.logic.Constants) BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation) JSONObject(com.ibm.json.java.JSONObject)

Example 12 with BOperatorInvocation

use of com.ibm.streamsx.topology.builder.BOperatorInvocation in project streamsx.topology by IBMStreams.

the class DependencyResolver method resolveDependencies.

/**
     * Resolve the dependencies.
     * Creates entries in the graph config that will
     * result in files being copied into the toolkit.
     */
public void resolveDependencies() throws IOException, URISyntaxException {
    JSONObject graphConfig = topology.builder().getConfig();
    JSONArray includes = (JSONArray) graphConfig.get("includes");
    if (includes == null)
        graphConfig.put("includes", includes = new JSONArray());
    for (BOperatorInvocation op : operatorToJarDependencies.keySet()) {
        ArrayList<String> jars = new ArrayList<String>();
        for (Path source : operatorToJarDependencies.get(op)) {
            String jarName = resolveDependency(source, includes);
            jars.add("impl/lib/" + jarName);
        }
        String[] jarPaths = jars.toArray(new String[jars.size()]);
        op.setParameter("jar", jarPaths);
    }
    ArrayList<String> jars = new ArrayList<String>();
    for (Path source : globalDependencies) {
        String jarName = resolveDependency(source, includes);
        jars.add("impl/lib/" + jarName);
    }
    List<BOperator> ops = topology.builder().getOps();
    if (jars.size() != 0) {
        for (BOperator op : ops) {
            if (op instanceof BOperatorInvocation) {
                BOperatorInvocation bop = (BOperatorInvocation) op;
                if (Functional.class.isAssignableFrom(bop.op().getOperatorClass())) {
                    JSONObject params = (JSONObject) bop.json().get("parameters");
                    JSONObject op_jars = (JSONObject) params.get("jar");
                    if (null == op_jars) {
                        JSONObject val = new JSONObject();
                        val.put("value", new JSONArray());
                        params.put("jar", val);
                        op_jars = val;
                    }
                    JSONArray value = (JSONArray) op_jars.get("value");
                    for (String jar : jars) {
                        value.add(jar);
                    }
                }
            }
        }
    }
    for (Artifact dep : globalFileDependencies) resolveFileDependency(dep, includes);
}
Also used : Path(java.nio.file.Path) JSONObject(com.ibm.json.java.JSONObject) JSONArray(com.ibm.json.java.JSONArray) ArrayList(java.util.ArrayList) BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation) BOperator(com.ibm.streamsx.topology.builder.BOperator)

Example 13 with BOperatorInvocation

use of com.ibm.streamsx.topology.builder.BOperatorInvocation in project streamsx.topology by IBMStreams.

the class JavaPrimitive method invokeJavaPrimitive.

/**
     * Create an SPLStream from the invocation of an SPL Java primitive
     * operator with a single input port & output port.
     * The Java class {@code opClass} must be annotated with {@code PrimitiveOperator}.
     * 
     * @param opClass
     *            Class of the operator to be invoked.
     * @param input
     *            Stream that will be connected to the only input port of the
     *            operator
     * @param outputSchema
     *            SPL schema of the operator's only output port.
     * @param params
     *            Parameters for the SPL Java Primitive operator, ignored if {@code null}.
     * @return SPLStream the represents the output of the operator.
     */
public static SPLStream invokeJavaPrimitive(Class<? extends Operator> opClass, SPLInput input, StreamSchema outputSchema, Map<String, ? extends Object> params) {
    BOperatorInvocation op = input.builder().addOperator(getInvocationName(opClass), opClass, params);
    SourceInfo.setSourceInfo(op, JavaPrimitive.class);
    SPL.connectInputToOperator(input, op);
    return new SPLStreamImpl(input, op.addOutput(outputSchema));
}
Also used : BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation)

Example 14 with BOperatorInvocation

use of com.ibm.streamsx.topology.builder.BOperatorInvocation in project streamsx.topology by IBMStreams.

the class JavaPrimitive method invokeJavaPrimitiveSource.

/**
     * Invocation of a Java primitive source operator to produce a SPL Stream.
     * 
     * @param te
     *            Reference to Topology the operator will be in.
     * @param opClass
     *            Class of the operator to be invoked.
     * @param schema
     *            Schema of the output port.
     * @param params
     *            Parameters for the SPL Java Primitive operator, ignored if {@code null}.
     * @return SPLStream the represents the output of the operator.
     */
public static SPLStream invokeJavaPrimitiveSource(TopologyElement te, Class<? extends Operator> opClass, StreamSchema schema, Map<String, ? extends Object> params) {
    BOperatorInvocation source = te.builder().addOperator(getInvocationName(opClass), opClass, params);
    SourceInfo.setSourceInfo(source, JavaPrimitive.class);
    return new SPLStreamImpl(te, source.addOutput(schema));
}
Also used : BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation)

Example 15 with BOperatorInvocation

use of com.ibm.streamsx.topology.builder.BOperatorInvocation in project streamsx.topology by IBMStreams.

the class JavaPrimitive method invokeJavaPrimitive.

/**
     * Invoke an SPL Java primitive operator with an arbitrary number
     * of input and output ports.
     * <BR>
     * Each input stream or window in {@code inputs} results in
     * a input port for the operator with the input port index
     * matching the position of the input in {@code inputs}.
     * If {@code inputs} is {@code null} or empty then the operator will not
     * have any input ports.
     * <BR>
     * Each SPL schema in {@code outputSchemas} an output port
     * for the operator with the output port index
     * matching the position of the schema in {@code outputSchemas}.
     * If {@code outputSchemas} is {@code null} or empty then the operator will not
     * have any output ports.
     * 
     * @param te Reference to Topology the operator will be in.
     * @param opClass Class of the operator to be invoked.
     * @param inputs Input streams to be connected to the operator. May be {@code null} if no input  streams are required.
     * @param outputSchemas Schemas of the output streams. May be {@code null} if no output streams are required.
     * @param params
     *            Parameters for the SPL Java Primitive operator, ignored if {@code null}.
     * @return List of {@code SPLStream} instances that represent the outputs of the operator.
     */
public static List<SPLStream> invokeJavaPrimitive(TopologyElement te, Class<? extends Operator> opClass, List<? extends SPLInput> inputs, List<StreamSchema> outputSchemas, Map<String, ? extends Object> params) {
    BOperatorInvocation op = te.builder().addOperator(getInvocationName(opClass), opClass, params);
    SourceInfo.setSourceInfo(op, JavaPrimitive.class);
    if (inputs != null && !inputs.isEmpty()) {
        for (SPLInput input : inputs) SPL.connectInputToOperator(input, op);
    }
    if (outputSchemas == null || outputSchemas.isEmpty())
        return Collections.emptyList();
    List<SPLStream> streams = new ArrayList<>(outputSchemas.size());
    for (StreamSchema outputSchema : outputSchemas) streams.add(new SPLStreamImpl(te, op.addOutput(outputSchema)));
    return streams;
}
Also used : ArrayList(java.util.ArrayList) BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation) StreamSchema(com.ibm.streams.operator.StreamSchema)

Aggregations

BOperatorInvocation (com.ibm.streamsx.topology.builder.BOperatorInvocation)26 BInputPort (com.ibm.streamsx.topology.builder.BInputPort)6 BOutputPort (com.ibm.streamsx.topology.builder.BOutputPort)4 ArrayList (java.util.ArrayList)4 JSONObject (com.ibm.json.java.JSONObject)3 StreamSchema (com.ibm.streams.operator.StreamSchema)3 HashMap (java.util.HashMap)3 JSONArray (com.ibm.json.java.JSONArray)2 TStream (com.ibm.streamsx.topology.TStream)2 TSinkImpl (com.ibm.streamsx.topology.internal.core.TSinkImpl)2 Constants (com.ibm.streamsx.topology.internal.logic.Constants)2 Type (java.lang.reflect.Type)2 BOperator (com.ibm.streamsx.topology.builder.BOperator)1 BOutput (com.ibm.streamsx.topology.builder.BOutput)1 Predicate (com.ibm.streamsx.topology.function.Predicate)1 KeyFunctionHasher (com.ibm.streamsx.topology.internal.logic.KeyFunctionHasher)1 Print (com.ibm.streamsx.topology.internal.logic.Print)1 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)1 Path (java.nio.file.Path)1 Map (java.util.Map)1