Connecting to a currency converter
After you create a currency converter, you can use that currency converter instance from other contexts and from other monitors. For example, you might want to create the currency converter in one context and use it for multiple realized profit and loss trackers that are in other contexts or monitors. When you want to use a currency converter that was created in another context or monitor you connect to that currency converter.
To connect to a currency converter, execute either of the following actions:
com.apama.ccyconverter.CurrencyConverterFactory.connect() connects to a currency converter instance in another context or monitor and returns a
com.apama.ccyconverter.CurrencyConverter instance for use in the current context.
com.apama.ccyconverter.CurrencyConverterFactory.connectCb() connects to a currency converter instance in another context or monitor, returns a
com.apama.ccyconverter.CurrencyConverter instance for use in the current context, and executes the specified callback.
Both actions take these two parameters:
serviceManagerCtx is a reference to the context in which the Service Framework manager was created. Currently, this is always the main context.
name is a string that contains the name of the currency converter you want to connect to. The name of the currency converter must be available in the context or monitor from which you are connecting. Note that in the context that contains the currency converter you want to connect to, to obtain the name of that currency converter, you can call
com.apama.ccyconverter.CurrencyConverter.getCurrencyConverterName().
In addition, the connectCb() action takes a callback action as its third parameter. This callback is invoked after connection to the remote currency converter.
The CurrencyConverter instance returned by the connect() or connectCb() action allows you to execute all currency converter actions except the CurrencyConverter.setParams() action. You can change configuration parameters only in a local currency converter.
To determine whether the currency converter in the current context is connected to a remote currency converter instance, execute the CurrencyConverter.isRemote() action.
Connection to a remote currency converter is asynchronous. Consequently, some currency converter actions that are normally available on a currency converter that is connected to a remote currency converter might not be available until the connection is completely in place. If your application requires notification when the connection to the remote currency converter is in place, execute connectCb()and specify a callback.
You can execute connect() or connectCb() to connect to a remote currency converter that has not yet been created. However, a currency converter you connect to must be created before the configurable timeout period has expired, otherwise an error will be returned. The configuration parameter that specifies the timeout period is CONFIG_TIMEOUT_DURATION and the default value is 5.0 seconds.
There can be any number of connections to a currency converter instance.
Any error callbacks that were set on the CurrencyConverterFactory prior to using it to connect to the remote currency converter are used if there is an error when connecting to the currency converter.
However, any parameters that were set on the CurrencyConverterFactory prior to using it to connect to the remote currency converter are ignored. The only exception to this is the CONFIG_TIMEOUT_DURATION parameter. You can set this on a factory and its value is used for the connection to the remote currency converter.
A currency converter that is connected to a remote currency converter instance has the same configuration parameter settings as the currency converter instance it is connected to. You cannot set parameters on a currency converter that is connected to a remote currency converter. This protects remote currency converter instances from modifications by currency converter connections. To change the configuration parameters for a currency converter that is connected to a remote currency converter you must change the configuration parameters directly on the remote currency converter instance itself. When you update the configuration parameters for a currency converter instance any currency converters connected to that remote instance inherit the updated settings.
Connecting to a currency converter instance in the same context is useful when you have two or more EPL monitors in the same context. For example, you can create a currency converter instance in monitorA and in monitorB you can connect to the currency converter in monitorA. You can then track realized profit and loss positions from monitorB. A connected currency converter takes care of the communication between the two monitors.