use of com.ibm.streamsx.topology.builder.BOutputPort in project streamsx.topology by IBMStreams.
the class StreamImpl method asType.
/**
* Get a stream that is typed to tupleClass,
* adds a dependency on the type.
*/
@Override
public TStream<T> asType(Class<T> tupleClass) {
if (tupleClass.equals(getTupleClass()))
return this;
// Is a schema change needed?
if (Schemas.usesDirectSchema(tupleClass) && !Schemas.getSPLMappingSchema(tupleClass).equals(output().schema())) {
return fixDirectSchema(tupleClass);
}
if (output() instanceof BOutputPort) {
BOutputPort boutput = (BOutputPort) output();
BOperatorInvocation bop = (BOperatorInvocation) boutput.operator();
return JavaFunctional.getJavaTStream(this, bop, boutput, tupleClass);
}
// TODO
throw new UnsupportedOperationException();
}
use of com.ibm.streamsx.topology.builder.BOutputPort in project streamsx.topology by IBMStreams.
the class JavaFunctional method addJavaOutput.
/**
* Add an output port to an operator that uses a Java class as its object
* type.
*/
public static <T> TStream<T> addJavaOutput(TopologyElement te, BOperatorInvocation bop, Type tupleType) {
StreamSchema mappingSchema = Schemas.getSPLMappingSchema(tupleType);
BOutputPort bstream = bop.addOutput(mappingSchema);
return getJavaTStream(te, bop, bstream, tupleType);
}
use of com.ibm.streamsx.topology.builder.BOutputPort in project streamsx.topology by IBMStreams.
the class TupleCollection method setupEmbeddedTestHandlers.
public void setupEmbeddedTestHandlers(JavaTestableGraph tg) throws Exception {
for (TStream<?> stream : handlers.keySet()) {
Set<StreamHandler<Tuple>> streamHandlers = handlers.get(stream);
for (StreamHandler<Tuple> streamHandler : streamHandlers) {
BOutput output = stream.output();
if (output instanceof BOutputPort) {
BOutputPort outputPort = (BOutputPort) output;
tg.registerStreamHandler(outputPort.port(), streamHandler);
}
// tg.registerStreamHandler(stream.getPort(), streamHandler);
}
}
}
use of com.ibm.streamsx.topology.builder.BOutputPort in project streamsx.topology by IBMStreams.
the class SPL method invokeSource.
/**
* Invocation an SPL source operator to produce a Stream.
*
* @param te
* Reference to Topology the operator will be in.
* @param kind
* SPL kind of the operator to be invoked.
* @param params
* Parameters for the SPL operator.
* @param schema
* Schema of the output port.
* @return SPLStream the represents the output of the operator.
*/
public static SPLStream invokeSource(TopologyElement te, String kind, Map<String, Object> params, StreamSchema schema) {
BOperatorInvocation splSource = te.builder().addSPLOperator(opNameFromKind(kind), kind, params);
SourceInfo.setSourceInfo(splSource, SPL.class);
BOutputPort stream = splSource.addOutput(schema);
return new SPLStreamImpl(te, stream);
}
use of com.ibm.streamsx.topology.builder.BOutputPort in project streamsx.topology by IBMStreams.
the class SPLStreams method convertStream.
/**
* Convert a {@code Stream} to an {@code SPLStream}. For each tuple
* {@code t} on {@code stream}, the returned stream will contain a tuple
* that is the result of {@code converter.apply(t, outTuple)} when the
* return is not {@code null}. {@code outTuple} is a newly created, empty,
* {@code OutputTuple}, the {@code converter.apply()} method populates
* {@code outTuple} from {@code t}.
*
* <P>
* Example of converting a stream containing a {@code Sensor} object to an
* SPL schema of {@code tuple<rstring id, float64 reading>}.
*
* <pre>
* <code>
* Stream<Sensor> sensors = ...
* StreamSchema schema = Type.Factory.getStreamSchema("tuple<rstring id, float64 reading>");
* SPLStream splSensors = SPLStreams.convertStream(sensors,
* new BiFunction<Sensor, OutputTuple, OutputTuple>() {
* @Override
* public OutputTuple apply(Sensor sensor, OutputTuple outTuple) {
* outTuple.setString("id", sensor.getId());
* outTuple.setDouble("reading", sensor.getReading());
* return outTuple;
* }}, schema);
* </code>
* </pre>
*
* </P>
*
* @param stream
* Stream to be converted.
* @param converter
* Converter used to populate the SPL tuple.
* @param schema
* Schema of returned SPLStream.
* @return SPLStream containing the converted tuples.
*
* @see SPLStream#convert(com.ibm.streamsx.topology.function.Function)
*/
public static <T> SPLStream convertStream(TStream<T> stream, BiFunction<T, OutputTuple, OutputTuple> converter, StreamSchema schema) {
String opName = converter.getClass().getSimpleName();
if (opName.isEmpty()) {
opName = "SPLConvert" + TypeDiscoverer.getTupleName(stream.getTupleType());
}
BOperatorInvocation convOp = JavaFunctional.addFunctionalOperator(stream, opName, FunctionConvertToSPL.class, converter);
@SuppressWarnings("unused") BInputPort inputPort = stream.connectTo(convOp, true, null);
BOutputPort convertedTuples = convOp.addOutput(schema);
return new SPLStreamImpl(stream, convertedTuples);
}
Aggregations