How to cache received EMA data for later use?

In an application that subscribes to MarketPrice instruments
using EMA Java, I would like to preserve for a later use the Data I receive via
Refresh and Update messages. My current understanding is that the Data I
receive for each field is only valid in the context of the onRefresh and onUpdate
callback methods. For example if in an onRefresh method I preserve the Data of
a FieldEntry by calling fieldData = fieldEntry.load(), I cannot use this fieldData
variable later after onRefresh returned.

  1. Can you please confirm if my understanding is correct?
  2. If yes, is there an easy way to clone the received data
    for later reuse, out of the onRefresh/onUpdate callback methods? By easy way I mean
    something like fieldData = fieldEntry.load().clone(). In order to avoid being
    too much coupled with the EMA Data types, I would like to avoid a big switch
    that deals with every possible data type.

Best Answer

  • wasin.w
    wasin.w admin
    Answer ✓

    Hi @Olivier DAVANT

    Based on EMA Java API dev guide section 3.2.3, the Data class and all classes that inherit from it are designed as temporary and short-lived objects. For this reason, do not use them as storage or caching devices.

    If the application just needs the content for the
    business logic use case, the application can store the FieldEntry’s content as
    string or manual copy content from incoming FieldEntry object (A) to the local FieldEntry object (B).

    image

    Based on your "For example if in an onRefresh method I preserve the Data of a FieldEntry by calling fieldData = fieldEntry.load(), I cannot use this fieldData variable later after onRefresh returned." statement, your fieldData is declared under the onRefresh() function scope. You cannot use it outside the onRefresh() function. You need to declare the local FieldEntry object in the class scope, so it can be used in any class's functions.

Answers

  • Hi Wasin,

    Thank you very much for this answer.

    Given what the doc says, I'm not even sure that what you proposed in your last sentence will work.