Apama 10.3.1 | Apama Capital Markets Foundation Documentation | Capital Markets Foundation | Analytics | Creating and configuring a currency converter | Configuring currency converter instances | Adding update callbacks to currency converters
 
Adding update callbacks to currency converters
The currency converter configuration parameter CONFIG_UPDATE_TIMEOUT specifies how often the currency converter obtains conversion values from its extension. The default is 5 seconds. If you want, you can add one or more callbacks to be executed each time the currency converter obtains values from its extension.
To set an update callback, execute com.apama.ccyconverter.CurrencyConverter.addUpdateCallback(). This action registers the specified callback with the currency converter instance it is executed on. The currency converter calls the registered callback each time the CONFIG_UPDATE_TIMEOUT is reached, which indicates that the values from the extension might have been updated. The addUpdateCallback() action returns a unique integer reference Id that you can use to remove the callback at a later date if required.
To remove a previously-added update callback, execute CurrencyConverter.removeUpdateCallback() and specify the integer reference Id that was returned when you added the callback.
The following code sample shows the addition of an update callback as well as the update callback itself.
using com.apama.session.SessionHandlerFactory;
using com.apama.session.SessionHandler;
using com.apama.ccyconverter.CurrencyConverterFactory;
using com.apama.ccyconverter.CurrencyConverter;
using com.apama.cmf.sample.BBAMidPriceExtension;
 
monitor CurrencyConverterSample2 {
  
context mainContext := context.current();
  
action onload() {
  
SessionHandler sHandler := (new SessionHandlerFactory).connect(
mainContext, "MySession", "MyTransport");

CurrencyConverter cc1 := (new CurrencyConverterFactory).createCb(
mainContext,
"MyCurrencyConverter1",
(new BBAMidPriceExtension).create(sHandler),
onCurrencyConverterCreated);
}
  
action onCurrencyConverterCreated (CurrencyConverter iface) {
integer callback := iface.addUpdateCallback(cbUpdateCC1);
}
  
action cbUpdateCC1( CurrencyConverter iface ) {
log "UPDATE: "+ iface.getCurrencyConverterName() +
" EUR/USD, Mid Price: " + iface.getValue("EUR", "USD" ).toString() +
" GBP/EUR, Mid Price: " + iface.getValue("GBP", "EUR" ).toString() +
" DKK/USD, Mid Price: " + iface.getValue("DKK", "USD" ).toString() +
" in context : " + context.current().getName() ;
}
 
}

Copyright © 2013-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.