Chapter 9 Working With Rules and Functions : Working With Startup and Shutdown Rule Functions

Working With Startup and Shutdown Rule Functions
Startup and shutdown rule functions are rule functions that are configured to execute during normal system startup and shutdown, respectively. There is more to say about startup rule functions and most of this section focuses on them.
Startup and shutdown rule functions take no argument and their Validity field (see RuleFunction Resource Reference) must be set to Action.
See Engine Startup and Shutdown Sequence for a useful reference that helps you understand what you can do in startup and shutdown actions.
 
Reminder, Cache Only cache mode  If you are using the Cache Only cache mode (advanced option) for one or more entities, you must consider how to handle any cache-only entities used in the functions. See Explicitly Loading Objects into Working Memory, With the Cache Only Mode.
Startup Rule Functions
Startup rule functions are optional and are used to initialize the system. For example they can provide initial values for scorecards. Startup rule functions can be used to perform more "expensive" operations so that the system is more efficient at runtime. For example, in a startup rule function for a query agent, you can create a query definition that you then reference in other rule functions. As another example, in BusinessEvents-ActiveMatrix BusinessWorks integration projects, you can call the BusinessWorks.init() function in a startup action.
Startup rule functions may trigger rule actions. However, note that BusinessEvents executes all startup rule functions before it begins the first RTC cycle, which completes when all rules eligible to execute have executed and no more actions remain.
Shutdown Rule Functions
Shutdown rule functions are optional and are used to perform various actions during a normal shutdown, for example, they can send events to external systems.
How Configured
Add rule functions, in order of desired execution, to the respective sections of the Startup/Shutdown tab of the BusinessEvents archive (BAR) resource:
See Startup and Shutdown for more details.
When Startup Rule Functions Execute
Startup rule functions execute whenever an active node starts  This includes failback to a failed node that has restarted. If you want to execute startup rule functions on only one node in a deployment, use programming logic to do so. For example, first perform a check that determines if the function has already executed using a try catch block.
Startup rule functions do not execute on failover  When an inactive node becomes active, it does not execute startup rule functions (See Inactive Agents and Fault Tolerance Behavior).
Creating Entities With a Startup Action in a Multi-Engine Project
Startup (and shutdown) rule functions execute in all active agents. Startup rule functions can be used to create entities, for example, for static reference data. When multi-engine functionality is used, ensure that multiple agents do not attempt to create the same entity. For example, use a try catch block, as is done BE_HOME/examples/FraudDetectionCache example.
See Designing With Multiple Active Inference Agents for more information.
ActiveMatrix BusinessWorks Containers
In ActiveMatrix BusinessWorks integration projects, if ActiveMatrix BusinessWorks is running as the container, do not specify any startup actions that result in starting or invoking an ActiveMatrix BusinessWorks process. See Design Considerations.
Note that after the ActiveMatrix BusinessWorks engine is initialized, processes that invoke BusinessEvents rule functions will fail if the BusinessEvents engine has not finished starting up. For example, an ActiveMatrix BusinessWorks process that listens to a JMS queue may attempt to invoke a BusinessEvents rule function before the BusinessEvents engine has started up.