Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved


Chapter 7 Working With Variables : Shared Variables

Shared Variables
A shared variable is a shared configuration resource in the General Activities palette. There are two types of shared variables:
Shared Variable
A Shared Variable resource allows you to share data across process instances. All process instances can read and update the data stored in a shared variable. This type of shared variable is useful if you wish to pass data across process instances or if you wish to make a common set of information available to all process instances. For example, you may have a set of approval codes for incoming orders that change daily for security purposes. You can create a shared variable to hold the approval codes and create one process definition for setting the codes. You can then retrieve the shared variable in all processes that require the current approval codes.
Job Shared Variable
A Job Shared Variable resource is similar to a Shared Variable, but its scope is limited to the current job. A copy of the variable is created for each new process instance. This type of shared variable is useful for passing data to and from sub-processes without creating an input or output schema for the called process.
You can use the Get Shared Variable and Set Shared Variable activities to access the data instead of mapping data to a called processes input or output schemas. New process instances receive a copy of the Job Shared Variable, so data cannot be shared across process instances. Therefore, if a called process has the Spawn configuration field checked, a new process instance is created and the process instance receives a new copy of the Job Shared Variable.
Configuring Shared Variables
You configure a shared variable by providing the following:
Setting the Schema of the Shared Variable
The Schema tab allows you to specify a complex schema for shared variable data. See Editor for more information about specifying data schema.
Setting the Initial Value of the Variable
While configuring the shared variable, you can specify an initial value for the variable on the Initial Value tab. You can choose either None (no initial value), Select Value, or Build Value.
When you choose None, no initial value is set and the variable value must be set in a process definition before it can be retrieved. When you choose Select Value, you can choose a stored XML Instance resource containing data that matches the specified schema. When you choose Build Value, an Edit button appears that allows you to bring up a dialog to construct the initial value of the variable.
Making the Variable Persistent
The current value of the shared variable is stored in memory for efficient access by process instances. However, if a process engine crashes, the current state of the shared variable may be lost. To preserve the current state of a Shared Variable resource, you can check the Persistent field on the Configuration tab.
When a shared variable is persistent, its current state is written to the process engine storage location (either the file system or a database depending upon how the process engine was deployed). The current state of the shared variable is only updated in the process engine persistent storage when the value of the variable changes.
Sharing the Variable Across Multiple Process Engines
If you wish to make the value of a Shared Variable resource available to process instances across multiple process engines, you can check the Multi-Engine field on the Configuration tab. This field is not available on Job Shared Variable resources.
If you choose this option, a database must be used to store process engine data. Also, only engines that are in the same deployment and part of the same load-balancing group can share variables. See TIBCO ActiveMatrix BusinessWorks Administration for more information on specifying load balancing groups and specifying a database for process engine storage during deployment. See Loading Processes to Test for more information about configuring a database for process engine storage within the testing environment.
Because multiple process engines access the shared variable, the current value of the variable is not stored in memory. Both retrieving the current value of the variable and assigning a new value to the variable requires I/O to the process engine database storage.
Assigning and Retrieving the Variable’s Value
You can retrieve the current value of a shared variable by using the Get Shared Variable activity. You can assign a value to the shared variable by using the Set Shared Variable activity. Both of these activities can be found in the General Activities palette.
Before you retrieve the value of a shared variable, you must either set an initial value in the variable’s configuration or use the Set Shared Variable activity to set the variable value. You can also configure the Set Shared Variable activity to include the current value of the variable as output for the activity. This provides access to the variable’s current value in subsequent activities in the process definition.
Synchronizing Access to Shared Variables
Because multiple process instances can potentially access and assign values to Shared Variable resources, the Lock shared configuration object and critical section group allow you to synchronize access to Shared Variable resources. Without a mechanism for locking, a process instance could update the value of a variable while another process instance is attempting to read the value. This would result in an unpredictable value for the variable.
You should use critical section groups to contain the Set Shared Variable and Get Shared Variable activities.This ensures that only one process instance attempts to assign a value to the variable and ensures that no process assigns a value to the variable when the current process attempts to read the value.
See Critical Section Groups for more information about using the critical section group.

Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved