com.devexperts.qd.kit
Class DefaultScheme

java.lang.Object
  extended by com.devexperts.qd.kit.DefaultScheme
All Implemented Interfaces:
DataScheme

public class DefaultScheme
extends java.lang.Object
implements DataScheme

The DefaultScheme is a basic implementation of data scheme. It uses record identifier and CompactInt format for record identity serialization.


Field Summary
protected  SymbolCodec codec
           
protected  DataRecord[] records
           
 
Constructor Summary
DefaultScheme(SymbolCodec codec, DataRecord[] records)
           
 
Method Summary
static DataScheme createFromProperties(java.util.Map properties, java.lang.String prefix)
          Deprecated. This method shall be moved to PropertyConfigurator or equivalent.
 DataIntField findIntFieldByName(java.lang.String name)
          Returns Int-field by its name.
 DataObjField findObjFieldByName(java.lang.String name)
          Returns Obj-field by its name.
 DataRecord findRecordByName(java.lang.String name)
          Returns data record by its name.
 SymbolCodec getCodec()
          Returns symbol codec used in this scheme.
 DataRecord getRecord(int index)
          Returns data record by its index within this scheme.
 int getRecordCount()
          Returns number of records in this scheme.
<T> T
getService(java.lang.Class<T> service_class)
          Extension point for additional scheme-specific services.
 DataRecord readRecordIdentity(java.io.DataInput in)
          Reads data record identity from specified data intput and returns it to the caller.
static void setParentReferences(DataScheme scheme)
          Sets references to corresponding parent entities in the specified scheme.
static void verifyScheme(DataScheme scheme)
          Verifies that specified scheme is correct from the QD standpoint.
 void writeRecordIdentity(java.io.DataOutput out, DataRecord record)
          Writes specified data record identity into specified data output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

codec

protected final SymbolCodec codec

records

protected final DataRecord[] records
Constructor Detail

DefaultScheme

public DefaultScheme(SymbolCodec codec,
                     DataRecord[] records)
Method Detail

getCodec

public SymbolCodec getCodec()
Description copied from interface: DataScheme
Returns symbol codec used in this scheme.

Specified by:
getCodec in interface DataScheme

getRecordCount

public int getRecordCount()
Description copied from interface: DataScheme
Returns number of records in this scheme.

Specified by:
getRecordCount in interface DataScheme

getRecord

public DataRecord getRecord(int index)
Description copied from interface: DataScheme
Returns data record by its index within this scheme. The record index in the scheme coincides with its identifier and is also used for identification of data record in serialized form.

Specified by:
getRecord in interface DataScheme

findRecordByName

public DataRecord findRecordByName(java.lang.String name)
Description copied from interface: DataScheme
Returns data record by its name. Returns null if no such records exists.

Specified by:
findRecordByName in interface DataScheme

findIntFieldByName

public DataIntField findIntFieldByName(java.lang.String name)
Description copied from interface: DataScheme
Returns Int-field by its name. Returns null if no such fields exists.

Specified by:
findIntFieldByName in interface DataScheme

findObjFieldByName

public DataObjField findObjFieldByName(java.lang.String name)
Description copied from interface: DataScheme
Returns Obj-field by its name. Returns null if no such fields exists.

Specified by:
findObjFieldByName in interface DataScheme

writeRecordIdentity

public void writeRecordIdentity(java.io.DataOutput out,
                                DataRecord record)
                         throws java.io.IOException
Description copied from interface: DataScheme
Writes specified data record identity into specified data output.

Specified by:
writeRecordIdentity in interface DataScheme
Throws:
java.io.IOException - as specified data output does.

readRecordIdentity

public DataRecord readRecordIdentity(java.io.DataInput in)
                              throws java.io.IOException
Description copied from interface: DataScheme
Reads data record identity from specified data intput and returns it to the caller.

Specified by:
readRecordIdentity in interface DataScheme
Throws:
java.io.InvalidObjectException - if required data record is not found in this data scheme.
java.io.IOException - as specified data input does.

getService

public <T> T getService(java.lang.Class<T> service_class)
Description copied from interface: DataScheme
Extension point for additional scheme-specific services. The following services are now supported: This method returns null if no scheme-specific override for the corresponding service is found.

Default implementation in DefaultScheme is to use Services.createService(java.lang.Class, java.lang.ClassLoader, java.lang.String) with this scheme's class loader.

Specified by:
getService in interface DataScheme

setParentReferences

public static void setParentReferences(DataScheme scheme)
Sets references to corresponding parent entities in the specified scheme. Requires that all data records are DefaultRecord, all Int-fields are PlainIntField and all Obj-fields are PlainObjField.

Throws:
java.lang.ClassCastException - if some record or field does not extend expected class.
java.lang.IllegalStateException - if some parent reference already set to different instance.

verifyScheme

public static void verifyScheme(DataScheme scheme)
Verifies that specified scheme is correct from the QD standpoint.

Throws:
java.lang.RuntimeException - if specified scheme is incorrect.

createFromProperties

public static DataScheme createFromProperties(java.util.Map properties,
                                              java.lang.String prefix)
Deprecated. This method shall be moved to PropertyConfigurator or equivalent.

Creates data scheme from specified properties filtered with specified prefix. The sample properties (to be used with prefix "myscheme."):
 myscheme.codec.class=com.devexperts.qd.kit.PentaCodec

 myscheme.10.id=1
 myscheme.10.name=Fundamental
 myscheme.10.0.class=com.devexperts.qd.kit.CompactIntField
 myscheme.10.0.name=Fundamental.High
 myscheme.10.1.class=com.devexperts.qd.kit.CompactIntField
 myscheme.10.1.name=Fundamental.Low

 myscheme.22.id=6
 myscheme.22.name=Quote&A
 myscheme.22.time=true
 myscheme.22.0.class=com.devexperts.qd.kit.CompactIntField
 myscheme.22.0.name=Quote&A.Bid.Price
 myscheme.22.1.class=com.devexperts.qd.kit.CompactIntField
 myscheme.22.1.name=Quote&A.Bid.Size
 
The numbers in the property key define relative index of record (first number) and field within the record (second number). These numbers must be small non-negative numbers, but they need not be consecutive.