Search in sources :

Example 1 with BOutputPort

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();
}
Also used : BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation) BOutputPort(com.ibm.streamsx.topology.builder.BOutputPort)

Example 2 with BOutputPort

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);
}
Also used : StreamSchema(com.ibm.streams.operator.StreamSchema) BOutputPort(com.ibm.streamsx.topology.builder.BOutputPort)

Example 3 with BOutputPort

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);
        }
    }
}
Also used : BOutput(com.ibm.streamsx.topology.builder.BOutput) StreamHandler(com.ibm.streams.flow.handlers.StreamHandler) BOutputPort(com.ibm.streamsx.topology.builder.BOutputPort) OutputTuple(com.ibm.streams.operator.OutputTuple) Tuple(com.ibm.streams.operator.Tuple)

Example 4 with BOutputPort

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);
}
Also used : BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation) BOutputPort(com.ibm.streamsx.topology.builder.BOutputPort)

Example 5 with BOutputPort

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&lt;Sensor> sensors = ...
     * StreamSchema schema = Type.Factory.getStreamSchema("tuple&lt;rstring id, float64 reading>");
     * SPLStream splSensors = SPLStreams.convertStream(sensors,
     *   new BiFunction&lt;Sensor, OutputTuple, OutputTuple>() {
     *             &#64;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);
}
Also used : BInputPort(com.ibm.streamsx.topology.builder.BInputPort) BOperatorInvocation(com.ibm.streamsx.topology.builder.BOperatorInvocation) BOutputPort(com.ibm.streamsx.topology.builder.BOutputPort)

Aggregations

BOutputPort (com.ibm.streamsx.topology.builder.BOutputPort)6 BOperatorInvocation (com.ibm.streamsx.topology.builder.BOperatorInvocation)4 StreamHandler (com.ibm.streams.flow.handlers.StreamHandler)1 OutputTuple (com.ibm.streams.operator.OutputTuple)1 StreamSchema (com.ibm.streams.operator.StreamSchema)1 Tuple (com.ibm.streams.operator.Tuple)1 BInputPort (com.ibm.streamsx.topology.builder.BInputPort)1 BOutput (com.ibm.streamsx.topology.builder.BOutput)1