Best practice for accessing known fields

I am migrating from TibMsg to OMM. Our application just needs numerical data (e.g. BID, ASK). So being new to
OMM I would like you advice.

  1. Is there a more direct method to get fields?
  2. Considering that I know the field and data type in advance, is the code below too defensive? Not defensive
    enough?
public void processEvent(Event event) { 
if (event.getType() == Event.COMPLETION_EVENT) {
log.info("Receive a COMPLETION_EVENT, "+ event.getHandle());
return;
}
if (event.getType() != Event.OMM_ITEM_EVENT) {
log.warning("Received an unsupported Event type.");
mainApp.disconnect();
return;
}
OMMItemEvent ie = (OMMItemEvent) event;
OMMMsg respMsg = ie.getMsg();

if (respMsg.getDataType() != OMMTypes.NO_DATA) {
OMMData ommPayload = respMsg.getPayload();

if (ommPayload.getType() == OMMTypes.FIELD_LIST) {
OMMFieldList ommFieldList = (OMMFieldList) ommPayload;
int dictId = ommFieldList.getDictId();
FieldDictionary fd = GenericOMMParser.getDictionary(dictId);

for (Iterator<OMMEntry> it = ommFieldList.iterator(); it.hasNext(); ) {
OMMEntry ommEntry = it.next();

if (ommEntry.getType() == OMMTypes.FIELD_ENTRY) {
OMMFieldEntry ommFieldEntry = (OMMFieldEntry) ommEntry;
FidDef fidDef = fd.getFidDef(ommFieldEntry.getFieldId());
String field = fidDef.getName();

if (field.equals("BID") || field.equals("ASK")) {
OMMData actualData = ommFieldEntry.getData(fidDef.getOMMType());
double d = ((OMMNumeric) actualData).toDouble();
System.out.printf("Field [%1$s] Value [%2$f]\n", field, d); }
} // field_entry
} // iterator
} // field list
} // no_data
}
Tagged:

Best Answer

  • I've tried the code and it worked well. This is a typical and direct way to retrieve fields in OMM so I don't think there is a more direct way for this. And, I don't see any need to perform further defensive type checking - it was sufficient for the task.

Answers

  • If not using a "dynamic view" one can see a performance improvement by breaking out from the field enumeration once all desired fields have been extracted.