The SDK provides several options for subscribing to data in a project.
The sample code provided here is for illustration only; it does not comprise a complete, working example. This example demonstrates subscribing to a stream in direct access mode with default options:
p.connect(60000);
subscriber = p.createSubscriber();
String strName = "WIN1";
subscriber.subscribeStream("WIN1");
subscriber.connect();
// Various data type we will be reading
BigDatetime bigdatetime = null;
Money m = null;
byte[] binary = null;
// Logic to exit loop goes here
while (true) {
SubscriberEvent event = subscriber.getNextEvent();
switch (event.getType()) {
case SYNC_START:
break;
case SYNC_END:
break;
// There is data to read
case DATA:
while ( reader.hasNextRow() ) {
RowReader rr = reader.nextRowReader();
for (int j = 0; j < rr.getSchema().getColumnCount(); ++j) {
if ( rr.isNull(j))
continue;
// This is legal but it is better to cache the data types array
switch ( rr.getSchema().getColumnTypes()[j]) {
case INTEGER:
rr.getInteger(j);
break;
case LONG:
rr.getLong(j);
break;
case STRING:
rr.getString(j);
break;
case TIMESTAMP:
rr.getTimestamp(j));
break;
case MONEY01:
m = rr.getMoney(j);
break;
// ...
// process other data types
// ...
}
}
}
break;
}
}
subscriber.disconnect();