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.
- Is there a more direct method to get fields?
- 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 }