public class SPLStreams
extends java.lang.Object
Constructor and Description |
---|
SPLStreams() |
Modifier and Type | Method and Description |
---|---|
static <T> SPLStream |
convertStream(TStream<T> stream,
BiFunction<T,com.ibm.streams.operator.OutputTuple,com.ibm.streams.operator.OutputTuple> converter,
com.ibm.streams.operator.StreamSchema schema)
Convert a
Stream to an SPLStream . |
static SPLStream |
stringToSPLStream(TStream<java.lang.String> stream)
|
static SPLStream |
subscribe(TopologyElement te,
java.lang.String topic,
com.ibm.streams.operator.StreamSchema schema)
Subscribe to an
SPLStream published by topic. |
static SPLStream |
subscribe(TopologyElement te,
Supplier<java.lang.String> topic,
com.ibm.streams.operator.StreamSchema schema)
Subscribe to an
SPLStream published by topic. |
static TStream<java.lang.String> |
toStringStream(SPLStream stream,
java.lang.String attributeName)
Convert an
SPLStream to a TStream<String>
by taking a specific attribute. |
static TStream<java.lang.String> |
toStringStream(SPLStream stream)
Convert an
SPLStream to a TStream<String>
by taking its first attribute. |
static SPLWindow |
triggerCount(TWindow<com.ibm.streams.operator.Tuple,?> window,
int count)
Convert window to an SPL window with a count based trigger policy.
|
static SPLWindow |
triggerTime(TWindow<com.ibm.streams.operator.Tuple,?> window,
long time,
java.util.concurrent.TimeUnit unit)
Convert window to an SPL window with a time based trigger policy.
|
public static SPLStream subscribe(TopologyElement te, java.lang.String topic, com.ibm.streams.operator.StreamSchema schema)
SPLStream
published by topic.te
- Topology the stream will be contained in.topic
- Topic to subscribe to.schema
- SPL Schema of the published stream.public static SPLStream subscribe(TopologyElement te, Supplier<java.lang.String> topic, com.ibm.streams.operator.StreamSchema schema)
SPLStream
published by topic.
Supports topic
as a submission time parameter, for example
using the topic defined by the submission parameter eventTopic
.:
Supplier topicParam = topology.createSubmissionParameter("eventTopic", String.class);
SPLStream events = SPLStreams.subscribe(topology, topicParam, schema);
te
- Topology the stream will be contained in.topic
- Topic to subscribe to.schema
- SPL Schema of the published stream.Topology.createSubmissionParameter(String, Class)
,
Topology.createSubmissionParameter(String, Object)
public static <T> SPLStream convertStream(TStream<T> stream, BiFunction<T,com.ibm.streams.operator.OutputTuple,com.ibm.streams.operator.OutputTuple> converter, com.ibm.streams.operator.StreamSchema schema)
Stream
to an SPLStream
. For each tuple
t
on stream
, the returned stream will contain a tuple
that is the result of converter.apply(t, outTuple)
when the
return is not null
. outTuple
is a newly created, empty,
OutputTuple
, the converter.apply()
method populates
outTuple
from t
.
Example of converting a stream containing a Sensor
object to an
SPL schema of tuple<rstring id, float64 reading>
.
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);
stream
- Stream to be converted.converter
- Converter used to populate the SPL tuple.schema
- Schema of returned SPLStream.SPLStream.convert(com.ibm.streamsx.topology.function.Function)
public static TStream<java.lang.String> toStringStream(SPLStream stream)
SPLStream
to a TStream<String>
by taking its first attribute.
The returned stream will contain a String
tuple for
each tuple T
on stream
, the value of the
String
tuple is T.getString(0)
.
A runtime error will occur if the first attribute (index 0)
can not be converted using Tuple.getString(0)
.stream
- Stream to be converted to a TStream<String>.stream
public static TStream<java.lang.String> toStringStream(SPLStream stream, java.lang.String attributeName)
SPLStream
to a TStream<String>
by taking a specific attribute.
The returned stream will contain a String
tuple for
each tuple T
on stream
, the value of the
String
tuple is T.getString(attributeName)
.
A runtime error will occur if the attribute
can not be converted using Tuple.getString(attributeName)
.stream
- Stream to be converted to a TStream<String>.stream
public static SPLStream stringToSPLStream(TStream<java.lang.String> stream)
stream
- Stream to be represented as an SPLStream
.SPLStream
representation of stream
.public static SPLWindow triggerCount(TWindow<com.ibm.streams.operator.Tuple,?> window, int count)
window
- Window to be converted.count
- Count trigger policy valuecount
tuples.public static SPLWindow triggerTime(TWindow<com.ibm.streams.operator.Tuple,?> window, long time, java.util.concurrent.TimeUnit unit)
window
- Window to be converted.time
- TIme trigger policy value.unit
- Unit for time
.time
.