use of com.ibm.streamsx.topology.spi.runtime.TupleSerializer in project streamsx.topology by IBMStreams.
the class Invoker method invokePrimitive.
/**
* Invoke a functional operator consuming an arbitrary number of
* input streams and producing an arbitrary number of output streams.
*
* @param te Topology element.
* @param kind Java functional operator kind.
* @param streams Input streams.
* @param invokeInfo Operator invocation information.
* @param logic Logic to invoke for each input tuple.
* @param tupleTypes Tuple types for the output stream.
* @param inputSerializers How input tuples are serialized.
* @param outputSerializers How output tuples are serialized.
* @param parameters Parameters for the operator invocation.
*
* @return Streams produced by the primitive operator.
*/
static List<TStream<?>> invokePrimitive(TopologyElement te, String kind, List<TStream<?>> streams, JsonObject invokeInfo, ObjIntConsumer<Object> logic, List<Type> tupleTypes, List<TupleSerializer> inputSerializers, List<TupleSerializer> outputSerializers, Map<String, Object> parameters) {
parameters = copyParameters(parameters);
if (inputSerializers != null && !inputSerializers.isEmpty()) {
assert streams.size() == inputSerializers.size();
String[] serializers = new String[inputSerializers.size()];
for (int i = 0; i < serializers.length; i++) {
TupleSerializer serializer = inputSerializers.get(i);
if (serializer == null)
serializers[i] = "";
else
serializers[i] = serializeLogic(serializer);
}
parameters.put("inputSerializer", serializers);
}
if (outputSerializers != null && !outputSerializers.isEmpty()) {
assert tupleTypes.size() == outputSerializers.size();
String[] serializers = new String[outputSerializers.size()];
for (int i = 0; i < serializers.length; i++) {
TupleSerializer serializer = outputSerializers.get(i);
if (serializer == null)
serializers[i] = "";
else
serializers[i] = serializeLogic(serializer);
}
parameters.put("outputSerializer", serializers);
}
BOperatorInvocation primitive = JavaFunctional.addFunctionalOperator(te, jstring(invokeInfo, "name"), kind, logic, parameters);
if (inputSerializers != null) {
for (TupleSerializer serializer : inputSerializers) if (serializer != null)
JavaFunctional.addDependency(te, primitive, serializer.getClass());
}
// Extract any source location information from the config.
SourceInfo.setInvocationInfo(primitive, invokeInfo);
for (TStream<?> stream : streams) stream.connectTo(primitive, true, null);
List<TStream<?>> outputs = null;
if (tupleTypes != null) {
outputs = new ArrayList<>(tupleTypes.size());
for (int i = 0; i < tupleTypes.size(); i++) {
Type tupleType = tupleTypes.get(i);
outputs.add(JavaFunctional.addJavaOutput(te, primitive, tupleType, outputSerializers == null ? empty() : ofNullable(outputSerializers.get(i)), tupleTypes.size() == 1));
}
}
return outputs;
}
Aggregations