Creating a currency converter
When you create a currency converter the new currency converter does the following:
Registers itself with the Service Framework.
Uses the specified parameters to construct all possible symbols it should obtain values for. For example, suppose the
CONFIG_SYMBOLS parameter specifies
"GBP/EUR". The currency converter would subscribe to receive information for converting from
GBP to
EUR and also for converting from
EUR to
GBP. If you specify a currency pair for which there is no direct exchange rate, the currency converter automatically subscribes to a third currency that it can use to calculate the conversion.
Provides its own interface to the specified extension.
Provides the constructed list of symbols to the extension.
Regularly notifies the extension to obtain updated values.
Creates a listener for remote connections.
To create a currency converter, execute either of the following actions:
com.apama.ccyconverter.CurrencyConverterFactory.create() constructs a new currency converter instance in the current context.
com.apama.ccyconverter.CurrencyConverterFactory.createCb() constructs a new currency converter instance in the current context and then executes the specified callback.
Both actions take these parameters:
serviceManagerCtx is a reference to the context that the Service Framework manager has been created in. Currently, this is always the main context.
name is a string that contains the name for the currency converter. In an application, two currency converters cannot have the same name.
In addition, the createCb() action takes a callback action as its last parameter.
Creation of a currency converter is asynchronous. If your application requires notification when the currency converter has been constructed, execute the createCb() action. After the CMF is activated and the currency converter is constructed, the specified callback will be executed. For example:
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 CurrencyConverterSample {
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) {
// Currency converter created.
}
}
You may perform actions immediately after the call to create the currency converter, for example you can connect to a the new currency converter. In this case, the create callback will be executed after the connections from remote contexts or monitors are set up. After execution of this callback, you can of course connect from additional contexts and monitors.
If any parameters are set on a
CurrencyConverterFactory, these parameters have the same settings in a currency converter instance created by that factory. If default error handling is changed for a
CurrencyConverterFactory instance and then you use it to create a currency converter, if there is an error in the creation of the currency converter then the updated error handling behavior is followed. Also, a currency converter instance created by this factory handles errors in the same way as the factory. See
Configuring a currency converter factory.
Any parameters you set for a currency converter factory instance and any error handling behavior you update for that factory apply to only subsequently created currency converters.