Skip to content

Instantly share code, notes, and snippets.

@sriumcp
Last active November 29, 2016 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sriumcp/e331a568775cefd9577ce6636f7b913e to your computer and use it in GitHub Desktop.
Save sriumcp/e331a568775cefd9577ce6636f7b913e to your computer and use it in GitHub Desktop.
SPL Sample Application for Streams Developer getting started on READ
namespace application ;
use com.ibm.streamsx.inet.rest::HTTPTupleView ;
use com.ibm.streamsx.inet.wsserver::WebSocketSend ;
/* This SPL application creates a data stream called 'time', and provides
* three different ways of accessing it via READ */
composite Main
{
graph
/* This view annotation makes it possible to access the time stream RESTfully
* through the Streams view server. We will sample 5 tuples every second, and
* keep the latest 60 samples
*/
@view(name = "waveview", port = time, sampleSize = 5, bufferSize = 60)
stream<uint64 timeStamp, float64 sine, float64 cos> time = Beacon()
{
param
period : 0.1 ;
output
time : timeStamp = IterationCount(), sine = 0.5 * random() - 0.25 +
sin(0.25 * PI() *(float64) IterationCount()), cos = 0.5 * random() - 0.25
+ cos(0.25 * PI() *(float64) IterationCount()) ;
}
/* HTTPTupleView is the recommended way to access Streams data within READ for most
* scenarios. The HTTPTupleView operator below lets you RESTfully access the tuples in the
* 'time' stream. We will simply keep the latest tuple and access
* it through READ, which will internally buffer the tuples.
* Notice the 'headers' param which is necessary to enable CORS access for HTTPTupleView data.
*/
() as currentTime = HTTPTupleView(time)
{
window
time : tumbling, count(1) ;
param
port : 8080 ;
headers : "Access-Control-Allow-Origin: *";
}
/* Websocket is a fast transport for browsers. Here, we define another
* means of transporting tuples from the 'time' Stream to READ using websockets.
*/
() as latestTime = WebSocketSend(time){
param
port : 8081;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment