question

Upvotes
Accepted
5 3 2 6

FieldEntry copy

In EMA Java, is it possible to get and keep a copy of a FieldEntry ?

At the moment when i retrieve a message, i decode it and populate my own object.
My domain object has 2 hashtables, both indexed by the FieldID.
The first one contains the FieldEntry.load().toString(), while the second one contains the FieldEntry directly, in order to parse it later on depending on the type.

However, there are some issues when i retrieve multiple items successively, the map of FieldEntry always contain the fields of the last item requested.

Is it possible somehow to retain a copy of a FieldEntry for later use ?

elektronrefinitiv-realtimeelektron-sdkrrtema-apielektron-message-apijava
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
14.3k 23 8 12

Hi @GAUTHIER.ROEBROECK

It is by designed of the EMA API that it currently currently does not support cloning of the Data objects and it internally reuses the FieldEntry and RefreshMsg objects. This information has been described in the warning section of section 3.2.3 “Data Class” in the EMA Java Development guide document.

If the application just needs the content for the business logic use case, the application can store the FieldEntry’s content as string (like your value hashtable).Otherwise, the application can create the local FieldEntry object to cache data via the EmaFactory.createFieldEntry() function by setting each information from the incoming FieldEntry to the new local FieldEntry object.


data-class.png (43.5 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
14.3k 23 8 12

Hi @GAUTHIER.ROEBROECK

Could you please share the code that initiate and keeps data into the Hashtable?

Do you have separate hashtable for each item or only hashtable for all items? Basically, if you put new value with the same key (FID) to the hashtable, it will update the current value to be the new one.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I have a domain object called ItemResult, which contains 2 hashmaps:

private final Map<Integer, String> values;
private final Map<Integer, FieldEntry> fieldEntries;

An ItemResult represent one Record on TREP.
When i receive a RefreshMsg, i create a new ItemResult, and populate both hashtables with the fieldId as the Key, and either the FieldEntry.load().toString() for values or FieldEntry for fieldEntries.

I suspect that internally EMA reuses the RefreshMsg object, as well as the FieldEntry objects.

Upvotes
33 0 1 4

(Assuming similar behavior with EMA c++)

Every time you call .forth() on FieldList, private object (of type FieldEntry) within FieldList is being overwritten with a new value. And when you call .getEntry() -- reference to this internal object is returned.

So all your references to FieldEntries that you stored will be pointing to same internal object. That means you should manually clone state of FieldEntry and put it in your hashtable, because otherwise this FieldEntry will be overwritten after next .forth() call.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

That was my guess indeed, hence my question asking about how to properly clone the FieldEntry object, since it doesn't implement Cloneable.

Upvotes
14.3k 23 8 12

Hi @GAUTHIER.ROEBROECK I modified EMA example based on your application logic as following steps:

  1. subscribe two items
  2. the first items (EUR=) subscribes for FIDs 114 and 372
  3. the second items (VOD.L) subscribes for FIDs 22 and 25
  4. create two instances of itemresult objects for EUR= and VOD.L based on your logic
  5. when each subscription receives refresh data, put incoming FID and FieldEntry to the itemresult's hashtable
  6. when each subscription receives update data, print out the refresh's FieldEntry in the itemresult's hashtable

I found that sometime, the hashtable's FieldEntry returns FID and data of the recent another item incoming data, not the it's refresh data. The values hashtable (string) does not encounter the same problem.

Example:

----- EUR= got update -----
onUpdateMsg: Item Name: EUR=
incoming data Fid: 114 Name = BID_NET_CH DataType: Real Value: 0.0027
incoming data Fid: 372 Name = IRGPRC DataType: Real Value: 0.25
----- VOD.L got update -----
onUpdateMsg: Item Name: VOD.L
----- Print out VOD.L refresh that should has only 22 and 25 FIDs -----
The Refresh message is
Data for: = VOD.L
Fid: 372 Name = IRGPRC DataType: Real
0.25
Fid: 114 Name = BID_NET_CH DataType: Real
0.0027
----- VOD.L hashtable's FieldEntry shows recently EUR= FIDs instead -----

Is it the similar behavior as your problem?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Actually on my side I am only doing snapshot requests, so i only receive Refresh messages.

Also, all the items i request usually have the same fields, and i request all the fields for each item.

But i think you experience kind of the same behavior as me, basically the FieldEntry may be reused internally by EMA.

Upvotes
37 3 4 14

Hi @GAUTHIER.ROEBROECK,
did you manage to achieve your aim? If so, could you please explain your approach?
I have the very same requirement: caching the payload of an OMM (MarketPrice) update for later use, but I can't find any clear way to copy a FieldEntry instance using directly EMA (C++).

@GAUTHIER.ROEBROECK, @Wasin Waeosri, in case a custom solution is needed, could please share any recommendations, best practices or snippets to do it in the right way?
It would be very much appreciated.

Thanks

Kind Regards,

Paolo

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

In the meantime, I've found some useful information here.
Regards,

Paolo