Improved process for custom extended operators and service callouts
When you are creating business rules, you sometimes need to perform operations that are not built natively into Corticon. For example you may need a complex mathematical formula or to retrieve data from an external web service. Corticon provides the ability to add custom extensions for just such purposes. This has been present in previous releases but has been made easier to use in Corticon 5.6.
Extensions are written as custom Java code that you package into one or more JAR files. In earlier releases, you had to modify Corticon’s Java classpath and perform other configuration steps to use an extension in your Decision Services. In Corticon 5.6, you simply add extension jar files to your rule project and Corticon bundles them into the EDS file for your Decision Service.
This ease of adding extensions makes it easier to develop extensions yourself or to use open source extensions that you download from the Corticon community.
By bundling extensions with EDS files, the EDS file becomes self-contained. You can deploy it to a Corticon Server without modifying the server’s classpath. It also allows you to have different Decision Services, or versions of Decisions Services, running that use different versions of an extension.
When developing an extension, it needs to implement one or more Java interfaces that Corticon has defined. These interfaces have not changed in Corticon 5.6. What is new is the addition of Java annotations to describe the extension. The use of annotations eliminates the need for additional configuration files.
When developing a project in Corticon Studio you can add extensions to your project through the project's Properties dialog box, so that they are available for development and running rule tests. The Package and Deploy wizard in Corticon Studio will include any extensions used by the project into the EDS file it generates or deploys. If you want to script the building of your EDS files, you can also use the Corticon ANT scripts to package extensions into EDS files.
For compatibility with previous releases you can still place extension JAR files on the Corticon classpath so that they are available to all Decision Services.
Extensions can be created in the Java development environment included in Corticon Studio, or you can use another IDE.
There are two types of Corticon extensions:
Extended operators - Operators are used when defining conditions and actions in a Rulesheet. While Corticon has a large built-in set of operators, you can expand this set by adding custom operators. Operators can operate on individual attributes, collections or sequences. Examples include:
Financial functions, such as net present value, and loan amortization
Statistical functions, such as standard deviation, and permutations
Engineering functions, such as pi, sine, and cosine
Service callouts - Callouts can be used in a ruleflow to retrieve, modify, or store data that is being processed by the rules. The most common use is to access data in a database or external web service. For example, if your Ruleflow needs to look up an applicant's credit rating, the service callout can have a step in the Rulflow processing that calls out to a trusted realtime ratings provider, and then adds the response back into the decision processing.
For details on creating extended operators and service callouts, see Overview of Corticon
extensions You can also examine the sample extensions bundled with Corticon Studio in the Advanced section of the Help > Samples page:
Once your extended operator and service callout .java files are ready, you compile them into classes, package them into JARs, and then stage the JARs for access by projects.
A look at using extensions in a project
Using extended operators in a Rulesheet
To add an extension JAR to a project, open the project, select Project > Properties, and then click Corticon Extensions. Click Add to navigate to the JAR you want, and then click Open to add it into the list, as shown: Click OK. The JAR is added to the project's folder and listed in the Project Explorer.
When a Rulesheet in this project is opened, any custom operator extensions in the JAR are added to the Rule Operators section, so that you can drag and drop a custom operator to the Rulesheet, as shown:
Using a Service Callout in a Ruleflow
Add a service callout JAR file to a project using the same procedure as an extension JAR -- open the project, select Project > Properties, and then click Corticon Extensions. Click Add to navigate to the JAR you want, and then click Open to add it into the list, as shown:
Because the JAR file contains a service callout extension, the callout is available when creating a Ruleflow, as shown:
The description and comments that you add to a service callout's source files provide modelers with key information about the service callout.
A look at creating extensions in Corticon Studio
Both the Extended Operator and Service Callout samples contain Java projects demonstrating how to create a Java extension. These are standard Java projects. Each has the CorticonCorticon JAR file that defines the API for Corticon extensions, CcExtensionApi.jar on its build path.
When developing extensions in Corticon Studio, add this JAR to the Java Build Path using the predefined Eclipse variable CORTICON_HOME. For example: