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;
}