Java API

Java Library

Include the Streametry Client library in your class path:

./lib/streametry-client.jar

The library is located in the lib folder of the server and requires Java 1.6+. See also: Javadoc

Connect

To connect to a streametry server add:

Streametry sm = Streametry.client.connect("myApp", "host:8181");

Set/Get data

The Streametry interface provides a number of methods for setting and getting data:

.get 
.set
.setAll 
.update
.updateAll
.delete
.size

For example:

// set a value for 'sensor1' in collection 'sensors'
sm.set("sensors", "sensor1", new Json("temp", 30));

Refer to the Javadoc documentation of these methods to see the descriptions.

Queries

The main query api is as follows:

DataStream stream = sm.stream("sensors")
    .query("filter( (sensor) -> sensor.temp > 10 )")
    .to( Handler );

Where the Handler will be called asynchronously with results as they come in. It is also possible to process results synchronously:

DataStream stream = sm.stream("sensors")
    .query("filter( (sensor) -> sensor.temp > 10 )")

for(Json result: stream) 
    System.out.println("new result: " + result);

Historical Queries

Historical queries start with history:

DataStream stream = sm.history("sensors", "temp")

Close and Disconnect

Data streams and the connection have a .close() method.

Example

// Connect 
Streametry sm = Streametry.client.connect("myApp", "host:8181");

// and then call methods on the Streametry interface:

 // push some data       
 sm.set("sensors", "sensor1", new Json("temp", 25));

 // start streaming data
 DataStream stream = sm.stream("sensors")
   .query("filter( (sensor) -> sensor.temp > 10 )")

 for(Json result: stream) // process results synchronously
   System.out.println("new result: " + result);

 // or process results asynchronously:
 stream.to( handler );