Introspection
Overview
To record data in TimeBase you need a stream with a specific schema to match your data model. You can do that manually by creating a RecordClassDescriptor. This method may be error-prone and time-consuming. To automate such routine tasks, we suggest using introspection that allows to automatically create stream schemas based on your data model described as annotated Java or C# classes. You can then take the right schema and use it to create a stream in TimeBase.
Annotations
Use TimeBase Annotations to mark your original Java and C# classes. Introspector creates class descriptor based on your annotations.
On the following example you may look at both original and annotated packageheader
Java class. The best practice is to annotate a class name first and then all the fields, enumerations, arrays, and objects you wish a TimeBase schema to have. In this example we describe the basic annotation principles. Refer to Annotations document to learn more.
Code without Annotations
For example purposes, let's annotate the following code.
- Java
- .NET
public class PackageHeader
{
protected ObjectArrayList<BaseEntryInfo> entries = null;
public ObjectArrayList<BaseEntryInfo> getEntries() {
return entries;
}
public void setEntries(ObjectArrayList<BaseEntryInfo> value) {
this.entries = value;
}
protected PackageType packageType = null;
public PackageType getPackageType() {
return packageType;
}
public void setPackageType(PackageType value) {
this.packageType = value;
}
protected long originalTimestamp;
public long getOriginalTimestamp() {
return originalTimestamp;
}
public void setOriginalTimestamp(long value) {
this.originalTimestamp = value;
}
protected long sourceId;
public long getSourceId() {
return sourceId;
}
public void setSourceId(long value) {
this.sourceId = value;
}
protected AttributeInfo attribute;
public AttributeInfo getAttribute() {
return attribute;
}
public void setAttribute(AttributeInfo info) {
attribute = info;
}
}
// Coming soon
Annotate Classes
Introspector creates classes based on this annotation. Use @SchemaElement
to define a class name and a title.
- Java
- .NET
//Java example
@SchemaElement(
name = "deltix.timebase.api.messages.universal.PackageHeader",
title = "Package Header"
)
//.Net example
Coming soon
Annotate Fields
Annotate getters with @SchemaElement
for introspector to create corresponding fields in a TimeBase class.
- Java
- .NET
//Java example
protected long originalTimestamp;
@SchemaElement(description = "Exchange Time")
@SchemaType(dataType = SchemaDataType.TIMESTAMP)
public long getOriginalTimestamp() {
return originalTimestamp;
}
//Setters are not annotated.
public void setOriginalTimestamp(long value) {
this.originalTimestamp = value;
}
//.Net example
Coming soon
Annotate Data Types
Data types are determined by the default type mappings but you can override those, as well as enumeration elements, using annotations in the example. In this example we use @SchemaType
annotation to completely override the default encoding and data type.
- Java
- .NET
//Java example
protected long sourceId;
@SchemaType(encoding = "ALPHANUMERIC(10)", dataType = SchemaDataType.VARCHAR)
public long getSourceId() {
return sourceId;
}
public void setSourceId(long value) {
this.sourceId = value;
}
//.Net example
Coming soon
Annotate Arrays
Use @SchemaArrayType
to annotate arrays for introspector to create such fields in a corresponding class.
- Java
- .NET
//Java example
protected ObjectArrayList<BaseEntryInfo> entries = null;
@SchemaArrayType(isNullable = false, isElementNullable = false,
elementTypes = {TradeEntry.class, L1Entry.class, L2EntryNew.class}
)
@SchemaElement(title = "Entries")
public ObjectArrayList<BaseEntryInfo> getEntries() {
return entries;
}
public void setEntries(ObjectArrayList<BaseEntryInfo> value) {
this.entries = value;
}
//.Net example
Coming soon
Annotate Objects
Annotate objects with @SchemaElement
to create corresponding objects in a TimeBase class. In this example we annotate a polymorphic object with two nested types defined by @SchemaType
annotation.
- Java
- .NET
//Java example
protected AttributeInfo attribute;
@SchemaElement
@SchemaType(
dataType = SchemaDataType.OBJECT,
nestedTypes = { CustomAttribute.class, BaseAttribute.class}
)
public AttributeInfo getAttribute() {
return attribute;
}
public void setAttribute(AttributeInfo info) {
attribute = info;
}
//.Net example
Coming soon
Annotate ENUMs
Annotate enumerations to add ENUM fields to TimeBase classes. Use @SchemaElement
to define both ENUM name and elements.
- Java
- .NET
//Java example
@SchemaElement(name = "deltix.timebase.api.messages.universal.PackageType",title = "Package Type")
public enum PackageType {
@SchemaElement(name = "VENDOR_SNAPSHOT")
VENDOR_SNAPSHOT,
@SchemaElement(name = "PERIODICAL_SNAPSHOT")
PERIODICAL_SNAPSHOT,
@SchemaElement(name = "INCREMENTAL_UPDATE")
INCREMENTAL_UPDATE
}
//.Net example
Coming soon
Annotated Code
As a result, we get this code with annotations.
- Java
- .NET
@SchemaElement(
name = "deltix.timebase.api.messages.universal.PackageHeader",
title = "Package Header"
)
public class PackageHeader {
protected long originalTimestamp;
@SchemaElement(description = "Exchange Time")
@SchemaType(dataType = SchemaDataType.TIMESTAMP)
public long getOriginalTimestamp() {
return originalTimestamp;
}
public void setOriginalTimestamp(long value) {
this.originalTimestamp = value;
}
protected long sourceId;
@SchemaType(encoding = "ALPHANUMERIC(10)", dataType = SchemaDataType.VARCHAR)
public long getSourceId() {
return sourceId;
}
public void setSourceId(long value) {
this.sourceId = value;
}
protected ObjectArrayList<BaseEntryInfo> entries = null;
@SchemaArrayType(isNullable = false, isElementNullable = false,
elementTypes = {TradeEntry.class, L1Entry.class, L2EntryNew.class}
)
@SchemaElement(title = "Entries")
public ObjectArrayList<BaseEntryInfo> getEntries() {
return entries;
}
public void setEntries(ObjectArrayList<BaseEntryInfo> value) {
this.entries = value;
}
protected AttributeInfo attribute;
@SchemaElement
@SchemaType(
dataType = SchemaDataType.OBJECT,
nestedTypes = { CustomAttribute.class, BaseAttribute.class}
)
public AttributeInfo getAttribute() {
return attribute;
}
public void setAttribute(AttributeInfo info) {
attribute = info;
}
}
@SchemaElement(name = "deltix.timebase.api.messages.universal.PackageType",title = "Package Type")
public enum PackageType {
@SchemaElement(name = "VENDOR_SNAPSHOT")
VENDOR_SNAPSHOT,
@SchemaElement(name = "PERIODICAL_SNAPSHOT")
PERIODICAL_SNAPSHOT,
@SchemaElement(name = "INCREMENTAL_UPDATE")
INCREMENTAL_UPDATE
}
//.Net example
Coming soon
Run Introspector
Call introspector
class to create stream schema based on your annotated code.
- Java
- .NET
//Java example
Introspector introspector = Introspector.createEmptyMessageIntrospector();
RecordClassDescriptor descriptor = introspector.introspectRecordClass(PackageHeader.class);
//.Net example
Coming soon
Stream Schema
We get such stream schema based on the annotated code via introspection.
Coming soon
info
- Refer to Annotations to learn what annotations you can use to create TimeBase stream schemas.
- Refer to Record Class Descriptor to learn more about this class.
- Refer to Solution Generator to learn how to generate classes based on TimeBase streams' schemas.
- Refer to Data Encoding to learn how you can consume data in TimeBase raw and bound to a data model.