Set a StreamBase Timestamp value from Java

Set a StreamBase Timestamp value from Java

book

Article ID: KB0074825

calendar_today

Updated On:

Products Versions
TIBCO Streaming 10

Description

What Java type and statement can be used to set a StreamBase EventFlow Timestamp value in a custom Java operator or adapter?

Resolution

Within a TIBCO Streaming Java custom operator or adapter a tuple Timestamp field may be set using a millisecond Long value, such as that returned by System.currentTimeMillis().

First the tuple field needs to be present in the tuple. This can be achieved by creating the tuple schema in the adapter typecheck() method. 

Example code for creating a schema:
  ArrayList<Schema.Field> fields = new ArrayList<Schema.Field>(); 
  fields.add(new Schema.Field("Time",CompleteDataType.forTimestamp()));
  schema0 = new Schema("", fields);
  setOutputSchema(0, schema0);

Second the tuple needs to have that schema. This is most frequently needed in the fillAndOutputTuple() method.

Example code:
  Tuple tuple = getOutputSchema(0).createTuple();

Finally, set the Timestamp field value.

Example code, as an absolute timestamp (with date information):
tuple.setTimestamp("Time", Timestamp.msecs( Timestamp.TIMESTAMP, System.currentTimeMillis()) );
or as an interval timestamp (with no date information):
tuple.setTimestamp("Time", Timestamp.msecs( Timestamp.INTERVAL, 2000l ); // two seconds, long

Additional static Timestamp creation methods are available in the Java API, including variations of .fromString(), .now(), and .secs().


 

Issue/Introduction

Configuration guidance

Additional Information

TIBCO Streaming > API Guide > API Guide Contents, "Java Client API"