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);
}
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);
}
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));
}
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));
}
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;
}
Aggregations