question

Upvotes
Accepted
1 1 2 3

How to know if the trepEmaClient has retrieved the rate file completely?

Currently when we connect with the trep server to retrieve files, we set the thread to sleep one minute to let the treoEmaClient downloads the rate file completely because the rate file is big, around 1-2MB.


Is there any way to avoid the thread sleep, or make the sleep a bit shorter? Such as 15 seconds? See below for our code.


Because we are using the default operation model: API_DISPATCH where EMA manages the dispatching of events within a background thread, we must block and wait on our application thread for a short period to capture our market data events.


Thank you.


public TrepResult retrieveRatesXml(String baseCurrency) throws InterruptedException {

OmmConsumer consumer = getOmmConsumer();
if (consumer == null) {
LOGGER.error("Can not connect to any TREP server.");
return null;
}

try {
ElementList batch = EmaFactory.createElementList();
OmmArray array = EmaFactory.createOmmArray();
for (String currency : TrepCurrency.getTrepRevertCurrencies().get(baseCurrency)) {
//EmaFactory.createOmmArrayEntry() must be inside the loop, otherwise only the last currency will be requested.
array.add(EmaFactory.createOmmArrayEntry().ascii("ky" + currency + baseCurrency + BFIX_CURNCY));
}
for (String currency : TrepCurrency.getTrepCurrencies().get(baseCurrency)) {
array.add(EmaFactory.createOmmArrayEntry().ascii("ky" + baseCurrency + currency + BFIX_CURNCY));
}
batch.add(EmaFactory.createElementEntry().array(EmaRdm.ENAME_BATCH_ITEM_LIST, array));
TrepEmaClient trepEmaClient = new TrepEmaClient(baseCurrency);
consumer.registerClient(EmaFactory.createReqMsg().serviceName(SERVICE_NAME).payload(batch), trepEmaClient);

// sleep for a while in order to let TrepEmaClient get all rate messages
Thread.sleep(EMA_CLIENT_WAITING_TIME.toMillis());
ExchangeRates rates = trepEmaClient.getRates();
String originalRefreshMsg = trepEmaClient.getOriginalRefreshMsg();
String ratesXml = XmlUtil.jaxbMarshallToString(rates);
if (ratesXml == null) {
return null;
}
return new TrepResult(ratesXml, originalRefreshMsg);

} catch (OmmException exception) {
LOGGER.error(exception.getMessage());
} finally {
consumer.uninitialize();
}
return null;
}

trepjavadispatch
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.

1 Answer

Upvotes
Accepted
23.7k 84 10 22

Hi @ning.kang

One way of confirming when you have received a response for all items in your Batch is to count the number of

  • RefreshMsg and
  • StatusMsg with a Closed stream state

that you receive.

For every valid instrument you should get a RefreshMsg callback and for invalid instruments (e.g. invalid RIC, Expired RIC, un-licensed RIC etc.) you would get a StatusMsg callback with a StreamState of Closed.

You could then create a loop that sleeps until the above total matches the number of items in your Batch request.

You may need to speak to whoever developed the trepEmaClient to help you - because that is not one of our Classes - it is a custom implementation.

I should also add that if you are only interested in snapping your instruments (as appears to be the case) then you should be using the snapshot option e.g.

consumer.registerClient(EmaFactory.createReqMsg().serviceName(SERVICE_NAME).payload(batch).interestAfterRefresh(false), trepEmaClient);

This way you only receive Refresh or Status events and not any Update events.

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.