Apama Capital Markets Foundation Documentation : Capital Markets Foundation : Order Management : Risk Firewall : Configuring risk firewall factories : Overriding default error handling for risk firewall factories
Overriding default error handling for risk firewall factories
The default error handler is invoked if there is an error related to risk firewall factories. For example, if any of the following happen:
*Risk firewall creation or connection fails.
*You try to remove an error callback and specify an incorrect error callback reference identifier.
*You try to set a parameter and specify an invalid parameter name.
The default error handler sends a message to the correlator log file at the ERROR level. To change this behavior, execute com.apama.firewall.RiskFirewallFactory.addErrorCallback(), which adds the specified callback to the set of callbacks executed if there is an error related to that risk firewall factory instance.
You can execute the addErrorCallback() action multiple times on the same factory instance to implement multiple error handling callbacks for that factory instance. If you add one or more error callbacks to a factory instance then the default error callback is not executed for that factory instance.
The parameters of a user-defined error callback include the risk firewall factory instance and also a com.apama.utils.Error event. An Error event has fields for a message, a dictionary of parameters, and an error type code. The addErrorCallback() action adds the specified callback to the set of callbacks executed if there is an error in the operation of the specified risk firewall factory instance.
The com.apama.firewall.ErrorConstants event defines the following error type codes, which can apply to risk firewall factory instances:
*FAILED_TO_CREATE_RISKFIREWALL_INTERFACE
*FAILED_TO_REMOVE_ERROR_CALLBACK
*INVALID_PARAMETER
When you add an error callback the return value is an integer reference ID that you can specify if you execute RiskFirewallFactory.removeErrorCallback() to discontinue execution of that error callback. To remove all error callbacks, execute the RiskFirewallFactory.clearErrorCallbacks() action. If you remove all previously set error callbacks then error handling behavior reverts to calling the default error callback.
Suppose you add one or more error callbacks to a risk firewall factory instance. A risk firewall instance created by that factory has the same error callbacks as that factory. However, if you use that factory to connect to a remote risk firewall instance, the returned risk firewall uses the same error handling as the risk firewall instance it is connected to.
In the following example, the application adds an error callback to be executed if the risk firewall factory fails to create a new risk firewall instance. For example, perhaps the application needs to send the error to a custom location.
using com.apama.firewall.RiskFirewallFactory;
using com.apama.firewall.RiskFirewall;
using com.apama.utils.Error;
 
monitor RiskFirewallExample7 {
context mainContext := context.current();
 
action onload() {
// Use a risk firewall factory to define an error callback
// that will be called if risk firewall creation fails.
// Then create a new risk firewall instance called "MyFirewall"
// in the current context.
// In this case, use the default configuration parameter settings.
RiskFirewallFactory factory := new RiskFirewallFactory;
 
// Set the error callback action that will be called should an error
// occur when creating the risk firewall.
integer refId := factory.addErrorCallback( onRiskFirewallErrors );
 
// Create a risk firewall.
RiskFirewall rfw := factory.create( mainContext, "MyFirewall" );
}
 
// This action is called if an error occurs creating the risk firewall.
action onRiskFirewallErrors ( RiskFirewall rfw, Error error ) {
// The application can query the Error object to return the error message,
// and to determine the type of error and any extra parameter information
// that is provided, to assist the application to programmatically
// determine the cause of the failure.
...
}
}

In the following example, the application adds an error callback to be executed if an attempt to connect to a remote risk firewall instance fails.
using com.apama.firewall.RiskFirewallFactory;
using com.apama.firewall.RiskFirewall;
using com.apama.utils.Error;
 
monitor RiskFirewallExample8{
context mainContext := context.current();
 
action onload() {
// Use a risk firewall factory to define an error callback that
// will be called if a connection attempt fails.
// Use the same risk firewall factory to connect to a risk firewall
// instance called "MyFirewall".
RiskFirewallFactory factory := new RiskFirewallFactory;
 
// Set the error callback that will be called if an error occurs
// when creating or connection a risk firewall.
integer refId := factory.addErrorCallback( onRiskFirewallErrors );
 
// Connect to a remote risk firewall.
RiskFirewall rfwRemote := factory.connect( mainContext, "MyFirewall" );
}
 
// This action is called if an error occurs while trying to connect
// to the remote risk firewall.
action onRiskFirewallErrors( RiskFirewall rfwRemote, Error error ) {
// The application can query the Error object to return the error message,
// and to determine the type of error and any extra parameter information
// that is provided, to assist the application to programmatically
// determine the cause of the failure.
}
}
Copyright © 2013-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback