Best Practices for WLI Application Lifecycle

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Composing and Developing WLI Applications

There are several best practices for composing and developing WLI applications. They are described in the following sections:

For more information on this section, see Guide to Building Business Processes and Using WebLogic Integration Controls.

Naming Standard for WLI Application Artifacts and Variables

When you develop WLI applications, you should follow a uniform and consistent naming standard for various WLI artifacts such as JPDs, task plans, controls, projects, and files. All controls, processes, methods, variables, and other WLI object names should follow standard object oriented and Java naming standards.

In WLI version 9.2, JPD, control, and data-transformation files have common .java extensions. You should add a suffix to each artifact so that they can be easily identified. Table 4-1 contains an example of naming controls and the related suffix for each artifact.

Table 4-1 Example of Naming Controls 
Type of Artifact
Suffix
Example
JPD projects
EAR, JPD
<Name>earjpd
 
Web, JPD
<Name>webjpd
 
Util, JPD
<Name>utiljpd
Task plan projects
EAR, JPD
<Name>eartp
 
Web, JPD
<Name>webtp
 
Util, JPD
<Name>utiltp
JPD
JPD
<name>jpd.java
Data transformation
DTF
<name>dtf.java
Custom control
None
None
Database control
DBC
<name>DBC.java
Web service
WSC
<name>WSC.java
EJB control
EJBC
<name>EJBC.java
JMS
JMSC
<name>JMSC.java
E-mail
EmailC
<name>EmailC.java
File
FileC
<name>FileC.java
HTTP
HTTPC
<name>HTTPC.java
MQ Series control
MQC
<name>MQC.java
Process control
PControl
<name>PControl.java
Task control
TASKC
<name>TASKC.java
Channels
Channel
<name>Channel.java
Event generators
EG
<name>EG

Modular JPD Design

If you have to define a large process, it is always a good practice to make it modular. A modular JPD meets a specific business objective. A few examples of modular JPDs are:

You can divide a large JPD into number of smaller JPDs or sub-processes. Sub-processes can be invoked using a central or main JPD. You can use process control to communicate between a JPD and a sub-process (another JPD). You can also loosely couple two JPDs using Message Broker or publish and subscribe architecture. See Communication Between JPDs and Core Implementation Patterns for a JPD for more details.

Modular XML Document

Every JPD has a start node and uses a XML document to start. Ensure that the XML document is modular and small for better performance. It is a good practice to have separate XSDs for each type of document. For example, you should have a separate XSDs for a Purchase Order and Invoice, instead of one single large schema for both the Purchase Order and the Invoice.

The modularity of a JPD and its associated document is a relative concept. If a JPD is too modular, it may be counter productive. You should take a balanced decision on modularity depending upon the specific scenario.

Parallel Node

The JPD provides a parallel node. Before you use this node, it is recommended that you understand how this node works. Parallel nodes can be used for managing multiple tasks which are related but not dependent. Parallel nodes are meant for business level parallelism. The actual execution does not take place in parallel.

At any given time, execution can start in one branch without any execution in other branches. For example, the branch executing a task may request for a quote from a partner and wait for a response. While this branch is waiting for a response, execution may start in another branch thus achieving business level parallelism.

There are two forms of parallel nodes - AND and OR mode. In the AND mode, all parallel paths should complete their execution, before the business process can proceed further. In the OR mode, the path that completes execution first is the winner. The processing of other path is stopped and the business process proceeds further.

The branches of a parallel node are isolated by transaction (default behavior). You can override this behavior to improve the performance of parallel nodes. Set the continueTransaction property to true in the source for each parallel element as follows:

<parallel continueTransaction="true">

JPD Exceptions

You can define exceptions and exception handlers in JPDs at nodes, groups, or process-levels. Exception handlers are executed in the following order:

  1. Nodes
  2. Groups
  3. Processes

It is a good practice at the process-level to have a catch all process-level exception handler.

Exceptions that are not handled can cause process failure. You can set a freezeOnfailure property to avoid this scenario. If this property is set, any exceptions that are not handled cause the process to freeze. The process then rolls back to the last committed point and the administrator can restart the process from the last committed state.

Table 4-2 contains a list of high-level design guidelines which you can follow while working on a JPD exception.

Table 4-2 High-Level Design Guidelines 
High-Level Design Guideline
Description
Asynchronous two-way processes should establish a way to pass exceptions or errors back to the caller process, with a separate client response or publication node in the exception handler.
When an error or an exception occurs, it is possible to catch an exception within the process. However, asynchronous processes, by nature cannot immediately respond to the exception. However, the caller should be informed that the process did not complete successfully. Your callback process should have a success or failure path and the result in both cases should be communicated to the caller.
All synchronous stateless processes must throw an exception back to the caller.
If the caller is blocking, it must be notified of the failure, as it is the only component that understands what should be done next.
Process designers should define a process-level exception handler at the start of every process definition. This handler acts as a global exception handler and catches any undefined exceptions.
This is a catch-all process-level exception handler. Exceptions that are not handled cause the process to fail and no recovery is possible from this state. When you define a global exception handler, you can ensure that the process never goes to an aborted state.
Set the freezeOnfailure property to true
If you set the freezeOnfailure property on the process, the process is rolled back to last commit state and persisted. The administrator can then fix the problem and re-activate the process.
Process designers should be especially careful about handling exceptions when processes call sub processes synchronously through the process control.
Exceptions that are not handled in the called sub process can set transactions to roll back. In this case, both the sub-process and caller process can be rolled back. You can define an appropriate exception handler in the sub process to avoid the roll back of the caller process.

Event Handlers for Process Events

Events handlers allow outside events to interrupt the process using OnMessage and OnTimeout event handlers. OnMessage event handlers can accept client requests. When a timer event is fired, control, receive, and message broker subscription message events are invoked.

Figure 4-1 shows an example of an OnMessage and OnTimeout event handler.

Figure 4-1 Example of OnMessage and OnTimeout Event Handler

Example of OnMessage and OnTimeout Event Handler

JPD Transactions and Compensation Management

The following sections describe the best practices for various JPD transactions and compensation management:

Transaction Boundaries

Processes in WLI are transactional in nature. Every step of a process is executed within the context of a Java Transaction API (JTA) transaction. When you are building a process, implicit transaction boundaries are formed based upon the location of blocking elements such as a Control Receive or a Client Send. As you add process nodes, the transaction boundaries within a process keep changing.

You can also create explicit transaction boundaries. To do this, select contiguous nodes and declare them in a separate transaction to distinguish between them and the implicit nodes that the application creates. The transaction may also contain resources accessed by a process, depending on the nature of the resource and the control that provides the access.

Transactions for Synchronous and Asynchronous Processes

A stateless process is executed either in a client transaction or when a new transaction is started. Using JPD proxy, a Java client can invoke a JPD over RMI. In this scenario, the client transactions are propagated to the JPD. The caller transaction is not propagated when a JPD is invoked as a web service. The caller transaction is not propagated to a JPD for asynchronous processes as well.

Transactions and Controls

Transaction controls are of three types:

Transactional and XA Compliant

If all controls used within a process are transactional and XA compliant, then the transaction of the process can be used to commit or terminate the underlying transaction branches. The process needs exception handlers to catch any issues and make the necessary transaction decisions. The developer needs to be aware where the transaction was started as any abort or rollback takes the control back to the starting point and this may not be within the process where the exception occurred.

Transactional and not XA Compliant Controls

XA is a protocol used to manage distributed transactions. WLI extends XA to allow non-XA resources to participate in distributed transactions, with the limitation that in a given transaction, only one transactional resource can be non-XA compliant. Therefore, if more than one transactional non-XA resource needs to be accessed in a process, then the access to these resources should be encapsulated in separate JPD sub-processes, which should be called asynchronously by the original process. Asynchronous invocation is necessary because synchronously called subprocesses run in the same transaction as the calling process. See Using Integration Controls for more details.

Non-transactional Controls

Non-transactional controls such as email controls do not support transactions. In the case of non-transactional controls, you need to have a strategy for exception handling. Use automatic rollback where controls are transactional. Use a caught exception for non-transactional controls to handle the error based on the business problem.

In addition to providing support for Atomicity Consistency Isolation and Durability (ACID) and XA transaction, JPDs also provide support for compensation. You should ensure that the transaction block for which you want to provide compensation, is not marked for rollback only. Define an exception handler path for the transaction block and enable the execute on rollback exception handler property. In such a situation, when a transaction fails, the exception handler path is executed first. You can define your undo or compensation logic in such a path. Figure 4-2 shows an example of non-transactional controls.

Figure 4-2 Non-transactional Controls

Non-transactional Controls

Table 4-3 contains a list of high-level guidelines to decide the transaction characteristic for your JPD.

Table 4-3 High-Level Design Guidelines for JPD Transaction Characteristics 
High-Level Design Guidelines
Description
Implement the automatic execution of compensating transactions only with extreme caution.
At a design level it seems very simple to implement the reverse. The problems arise when the compensation fails, the question being the recovery from the failure. The solution to this situation is often unclear. The default design rule should be to raise an alert and manually decide on a solution.
A process needs to have exception handlers in place to find any issues and make the necessary transaction decisions.
You must not leave anything to default, always identify the exceptions and decide on a solution. This is applicable to transactional and non-transactional resources.
When more than one transactional non-XA resource has to be accessed in a process, the access to these resources should be encapsulated in separate JPD sub-processes.
The original process should call the sub-processes asynchronously. In this way, the sub-process runs in a separate transaction and is able to access the non-transactional resource.

JPD State Management

A stateless JPD is a process executed in memory only. Its state does not persist. All stateless processes are compiled into a stateless session bean. Stateless processes are intended to support business scenarios that involve short-running logic and have high performance requirements.

As the JPD does not persist its state to a database, it is optimized for lower-latency and higher-performance execution.

Table 4-4 contains a list of high-level guidelines that you should follow, when working on stateless processes.

Table 4-4 High-Level Guidelines for Stateless Processes 
High-Level Design Guidelines
Description
Do not use default values in global variables, unless the variable is either declared static or final. Initialize all global variables before use.
Stateless processes are implemented as stateless session beans. After a process is complete, subsequent process instances reuse the same stateless session bean instances, and therefore inherit the last known value of the global variables.
Set the on sync failure property on the process to re-throw for synchronously called processes where the requestor needs to handle transaction demarcation.
This property only applies to your process if it is configured to be a synchronous sub-process; it is ignored for any other business processes. If a synchronous sub-process fails, the default behavior is to mark it as rollback, which causes both the sub-process and the parent process to rollback. However, if the on sync failure property is set to re-throw, only the sub-process is rolled back.

A stateful process is a process that runs within the scope of more than one transaction. The process persists its state in the database. The state of the JPD survives even if the server crashes. The stateful JPD process is compiled into an entity bean. Stateful processes are intended to support business scenarios that involve complex, and long-running logic.

Stateful processes, in general, are slower than stateless processes. Use stateless processes, especially in scenarios where a state does not need to persist. In certain situations, you can split a stateful process into several stateless processes. Figure 4-3 shows how you can split a stateful process into a stateless process.

Figure 4-3 Splitting a Stateful Process Into a Stateless Processes

Splitting a Stateful Process Into a Stateless Processes

JPD Versioning

WLI has a version feature that helps you change your business process without interrupting any instances of the process that are currently running. When you create a version of a business process, you are actually creating a child version of a business process that shares the same public interface as the parent business process. At runtime, the version of the process that is marked active, is the process that external clients access using the public URI. Through the regular development cycle, new process versions are deployed with new versions of the application.

When the new version of a JPD is deployed, the existing instances run to completion on the same version of the JPD that they started with. You can version business processes, but not the individual controls associated with that process, or other business process related components such as schemas and transformations. When you version a business process, you must also version the sub-processes of that process, as they are not assigned a version automatically along with their parent process.

Table 4-5 contains a list of high-level guidelines that you can follow to set versions for JPDs.

Table 4-5 High-Level Guidelines to Version JPDs
High-Level Design Guidelines
Description
If you have to deploy a new version of a business process, you must set a version for your existing process before deploying the new version.
If you do not follow that process, you must let non-versioned instances run to completion before deploying the new versioned process.
Set the process version strategy according to the parent-child relationship of the business process.
This describes how you can invoke sub-processes when different versions of the parent process exist. From the strategy drop-down menu:
  • Select loosely-coupled if you want the sub-process version to be set when the sub-process is invoked.
  • Select tightly-coupled if you want the sub-process version to be set at the time the parent process is invoked.

Singleton JPD

A JPD can subscribe to a message broker channel in two ways: Static or Dynamic.

If a process subscribes to a channel at the start node, this is called a static subscription. The subscription is known at the time the application is compiled and remains through the life time of the application.

When a process subscribes to a message broker channel during its flow using the message broker control, this is known as a dynamic subscription. The subscription starts and ends at runtime. A static subscription to a message broker channel can be specified as suppressible if you set the suppressible attribute for the subscription in the business process. The accepted values for the suppressible attribute are true and false (false is the default value).

A singleton JPD has only one instance of the JPD running at any time. To create a singleton JPD, first define a JPD with a static subscription and set the suppressible attribute to True. In this situation, the first message on the channel invokes the JPD and creates an instance of the JPD. Subsequent messages on the static channel do not lead to the creation of a new JPD instance. Singleton JPDs created in this way can continue to receive messages using dynamic subscription.

Race Condition With Dynamic Subscription

A race condition is possible when you use the message broker with a dynamic subscription. A message is lost if it is sent before the subscription is complete. This problem is evident when processes start waiting indefinitely for a response, coupled with messages appearing in the dead-letter channel.

If the request message is non-transactional, for example, in the case of a web service call, the message is sent immediately, whereas the subscription to the response occurs only when the transaction is committed. If the subscription appears before the message is sent in the process flow, it might occur later. In this case, ensure that the transaction is committed (for example, add an empty explicit transaction) after the subscription node and before the request message is sent.

Dead Letter Channel Subscription

If a message is sent to a channel without a subscriber after the filtering process is complete, the message goes to the dead-letter channel. Subscribe to the dead-letter channel to check if messages are published there, because in most cases, this is not a desired behavior.

High Quality of Service JPD

You need to take special steps to implement at-least-once or once-only Quality of Service. If these steps are not taken, the default is the at-least-once Quality of Service. The steps for the different process types are as follows:

Note: You cannot ensure the successful completion of every computer program, but a high Quality of Service means that the error is always recoverable.

SLA Threshold for JPDs

A service level agreement (SLA) specifies the performance target for a JPD. An internal or external commitment shows that a JPD is executed within a specified period of time. To help you achieve the SLA for a process, the WLI Administration Console allows you to set the following thresholds (Figure 4-4):

The process status that is relative to these thresholds is tracked for each process instance as follows:

When the elapsed time for a process instance reaches the warning threshold, a warning is displayed on the Process Instance Summary and Detail pages. The amount of time remaining until the SLA threshold is reached is also displayed. When the elapsed time exceeds the SLA, a red flag is displayed. The time limit by which the SLA threshold has been exceeded is also displayed. This ability to set SLA thresholds allows you to easily identify processes that do not execute within the target time frame. You can then make the required changes to meet agreements between suppliers and customers, or to achieve your own performance goals.

Monitor JPDs

You can track a process at various levels. The system contains a default tracking level and then each process can override this. The WLI Administration Console and underlying MBeans provide a monitoring interface to running instances and their variable values. Although variable values cannot be changed, it is possible to query the process using the instance ID or process label. You can set the process label in the instance by calling the JPD context setProcessLabel. Table 4-6 contains a list of high-level design guidelines to monitor JPDs.

Table 4-6 High-Level Design Guidelines for Monitoring JPDs
High-Level Design Guidelines
Description
Use tracking data only for operational support, and not for business or audit logging.
You need to purge tracking data regularly. Tracking can be set on and off dynamically for each process at runtime using the WLI Administration Console.
Disable process tracking for processes that require high performance.
Process tracking involves information that is written into the database several times. For performance reasons, tracking must be eliminated.
WLI system data should only be used for support and not business level audit.
The WLI system data should not be used for business level audit. A designed audit or logging framework must be implemented outside the WLI system data capture area.
Log every InstanceID.
You must record the InstanceID for any error, log, and audit message.
Schedule regular archiving of WLI data.
Archiver is a process that runs a Select query on the database, so it must be scheduled to run regularly on small amounts of data. Avoid scheduling the archiving process at peak hours.
Set the process label to relevant query values.
The process label is a preferred query string to design the values, rather than depending on the person who implements the values. For example, a support person finds an order number easily if it is represented on the process label.

Security Policy for JPDs

You can define the security policy for a JPD. The security policy controls the identity that the JPD uses to access external or backend systems. It allows the administrator to configure whether a JPD accesses an external system as the invoking application, or as an application that calls into the process later. For example, if a process subscribes to a channel and then waits for a client request, the administrator can set the execution policy and use the identity from the client request while accessing backend resources.

The JPD security policy has four main components:

Interoperable JPDs

You can expose a JPD as a Java Web Service (JWS). There are limitations to developing interoperable JPDs, which include:

Figure 4-5 shows the recommended architecture, keeping the interoperability limitations in mind.

Figure 4-5 Front-end JWS with SC and JPD with a JWS and Process Control

Front-end JWS with SC and JPD with a JWS and Process Control

Communication Between JPDs

A WLI application contains several JPDs that communicate with each other. A JPD that is invoked by other JPDs is called a sub-process. Table 4-7 lists the high-level guidelines that you can follow for JPD to JPD communication.

Table 4-7 High-Level Design Guidelines for JPD Communication 
High-Level Design Guideline
Description
For asynchronous communications between processes in different domains, the use of JMS and the messaging bridge is recommended, together with the JMS event generator or web services over JMS.
The messaging bridge supports all of the QoS options for asynchronous messaging between domains. The store-and-forward capabilities of the messaging bridge insulate local processes from problems and provide access to remote providers.
For asynchronous two-way communications between processes in the same domain, it is recommended that you use process control rather than the message broker.
You get approximately the same performance when you start a process using process control or message broker, but it is significantly faster to receive a process control callback than a message broker subscription. The message broker subscription filter mechanism uses a database to map the filter values to process instances. Process control callbacks are routed directly to process instances.
Use raw JMS where the message size is large.
JMS is more efficient than marshalling large messages in web services.
Use the process control, not service or service broker control for synchronous communications between processes in the same domain, if a transaction must be propagated between processes, or performance is an issue.
Process control is transactional and avoids SOAP marshalling. Service and service broker controls are not transactional.
For synchronous communications between processes in different domains, use service and service broker controls or the JPD proxy.
Process control can only be used within a domain. The JPD proxy provides transactional propagation at the cost of tight coupling. Service and service broker control do not provide transaction propagation but enable loose coupling.
Use the service broker control rather than the service or process control, if the data-dependent routing facilities are required.
The service broker control allows for configurable routing of service calls to different service implementations depending on data, but this facility is not transactional.

Using Controls

Controls are an integral part of a JPD. WLI 9.2 controls are based upon open Apache Beehive standards. They support annotations based on JSR-175 standards. Controls are reusable and provide easy access to enterprise resources. Controls can be used within a process definition to make calls to a backend system. For example, the database control allows a process to send SQL to an RDBMS using a JDBC connection pool. Table 4-8 lists the high-level guidelines that you can follow for using controls.

Table 4-8 High-Level Guidelines for Using Controls 
High-Level Design Guideline
Description
Control reuse
All controls should be written so that they can be reused across process definitions.
You should develop custom controls keeping in mind native WLI 9.2 controls.
Use the controls available in WLI 9.2 as much as possible. Write custom controls only when absolutely necessary.
Use custom controls instead of custom Java code if reuse of the code is a consideration.
A control that is created for custom Java code means that the code can be reused across different process definitions.
Controls should be versioned in source code control.
Controls should be treated as Java code and versioned appropriately.
Each application project in BEA Workshop for WebLogic should have a separate control project.
Import controls from the component library into this project so that they become available to all the applications.

Using Dynamic Properties and Annotation for Controls

In many cases, control attributes are statically defined using annotations. However, some controls provide a Java API to dynamically change attributes. Dynamic controls, such as service broker and process controls provide the means to dynamically set control attributes. A dynamic or late binding process is used where attributes are determined at runtime using a combination of lookup rules and values. Controls that support dynamic binding are called dynamic controls.

Look-up rules are defined during design time. Look-up values can be defined in the DynamicProperties.XML file by changes during runtime. This file is a domain-wide file shared by all WLI applications in the domain. This feature allows the complete de-coupling of control attributes from the application. This file can be re-configured while an application is running, and you do not need to redeploy the application for the changes to take effect.

To achieve the dynamic binding of properties, use:

Use the getProperties() method to retrieve the current property settings.

Buffering Service Control Methods During Asynchronous Calls

When you call web service controls asynchronously from business processes, it is recommended that you buffer the asynchronous call to ensure that the message sent from the business process to the web service is enqueued. An asynchronous call to a resource marks the boundary of a transaction in your business process. A call to a resource is not enqueued until the transaction is committed.

By buffering the call to the resource, you ensure that the transaction is committed before there is any response from the resource. If you do not buffer the call, your business process must wait for the HTTP acknowledgement before the transaction is committed. In this situation, the resource may attempt to respond to the business process before the HTTP acknowledgement.

Using Control Factory to Manage Multiple Instances of a Control

The control factory feature of a control enables a JPD to interact with a multiple instances of the same JPD. You can implement File, e-mail, WLI JMS, Trading Partner Management, Service, and Worklist controls as control factories. For example, if a JPD is required to send a document, such as loan application, to multiple service providers, it can use a control factory to create multiple instances of the service control, and dispatch requests to the service control instances in parallel. If the control uses callbacks, a single parameterized callback handler in the calling JPD, can manage the callbacks received from all the control instances.

Data Transformation

Data transformation and manipulation is an integrated part of a business process. Service consumers and providers require varied data format and types. WLI provides the following tools for data transformation:

Note: WLI 9.2 supports the runtime execution of XQuery 2002 for the purpose of backward compatibility with WLI 8.1.

Canonical Data Model

It is recommended that you create a canonical data model for your application. A canonical data model maps the data to an agreed standard form. If correctly implemented, such a data model provides the services with an Enterprise Information System (EIS) neutral interface. It specifies how you can map the reference, static, and identifier data from an EIS data format to a standard format, de-coupling the data model of the host and the data model of the recipient. You should first create standards for the service interface, that in turn, enforces a common representation of data types and entities within the enterprise. You must maintain a consistent method of representing dates, numbers, post codes, and addresses.

Runtime Selection of a Transformation

A dynamic transformation control enables a business process to dynamically select and execute a transformation during runtime. It allows you to choose the XQuery, XSLT, or MFL file that is invoked at runtime. For example, if you have an integration hub that receives documents from various regional offices, you can use the dynamic transformation control to perform different transformations based on the area code of each regional office. Table 4-9 lists the high-level design guidelines for data transformation.

Table 4-9 High-Level Design Guidelines for Data Transformations
High-Level Design Guideline
Description
Create new data transformations using XQuery rather than XSLT.
XQuery has several advantages over XSLT, including additional functionality, and better performance.
Use a data model (Enterprise Data Model (EDM)) only where there are clear benefits that offset the additional cost and complexity.
An enterprise requires a large amount of resources to use a data model. A data model should be used only when an organization is willing to commit the required resources.
Implementing a data model involves high cost and social challenges. You can implement standards at the interface to ensure a quick return on investment.
This is to ensure that data is represented consistently across all service interfaces. For example, dates, post codes, and addresses are always represented in a specific style.
Ensure that you represent information such as message headers in a standard format.
The origin of the message should not be disclosed to the recipient.
If a data model or standard service interface is appropriately implemented, the recipient of a message is not aware of the data format of the message despatching system.
Wrap any re-usable transformation as a stateless process.
If a re-usable transformation is wrapped as a stateless process, other components can call it a service. This includes direct calls from a front-end system.

 


Developing a Task Plan

WLI 9.2 worklist has several enhanced features as follows:

Task Plan for Exception Management

You can use the task plan to manage exceptions in a JPD. Users can work on a task plan that is invoked when an exception occurs.

Integrating Custom Logic With a Task Plan

Use the task plan event service to integrate your custom logic with the task plan.

To subscribe to task plan events, write your own custom event listeners and register them with the task plan. You can write custom code in your listener class. This custom code is executed when task plan events invoke the respective event listeners associated with the task.

You can use a custom assignment handler in the custom logic to change the default task assignment at runtime.

See Using the Worklist for detailed information.


  Back to Top       Previous  Next