WF exception capture and resource compensation

Source: Internet
Author: User
Document directory
  • 1. Capture FaultHandlersActivity and FaultHandlerActivity
  • 2. CompensatableSequence, CompensationHandlerActivity, and CompensateActivity are compensated.
  • 3 Application description of exception capture and compensation

Some friends mentioned that they wanted to know "error handling and node rollback"

Here we will clarify several concepts:

1. Error Handling: it is also called exception capture. It usually refers to a solution to prevent the crash after an exception occurs in the current logical unit block.

2. Transaction Processing: usually refers to a processing solution that restores the previous operations to the original state after an exception occurs in the current logical unit block.

3. node rollback

I am not sure what this friend actually means.

Many people who are new to workflow will always mention the word "process rollback". I don't know the source of this word,

However, the business process cannot be rolled back, and the concept of "transaction" does not exist in the real business field.

The check is written incorrectly. It cannot be erased with the image or torn off. It can only be marked as void.

The business data is added incorrectly. You cannot delete or update the data, but you can only insert one charge.

Similarly, there is also a famous saying in the circulation of documents, "one piece of paper into the public door, 9 Niu pulled back ",

If there is no rollback, then what is "correction" and "retrial"? It is not a rollback, it is a legal exception, it is an Else branch of the real business process

So, "error handling and node rollback", I usually think of "Node rollback" as "resource compensation"

4. Resource Compensation: It usually refers to the normal completion of the current logical unit. After an exception occurs to other logical units, what else should the original logical unit do to adapt to the new situation caused by exceptions?

The difference between compensation, transaction processing, and exception Capture: transaction processing and exception capture are all remedial actions for exceptions in the current logical unit block, the compensation is caused by exceptions of other logical units.

Example:

The event was held. Zhang San was responsible for notifying the guests and Li Si was responsible for preparing the venue.

When Zhang San called the guest, he found that the phone number was incorrect and told the activity owner that this was an exception handling.

On the third day, Michael Jacob called the guest and told him that he had a problem with the venue and that the event could not be completed as scheduled. Michael again called to inform the guest. This is compensation.

Zhang San called the guests to inform them that they could participate on schedule and told them to call back on the 4th evening to confirm each other.

Note: When Zhang San calls the guest, he should not put the wrong call behavior into exception handling. The object should be sentenced to a non-empty sentence before use, rather than directly put in Try, this is what I often say.

Note: Do not write compensation into a transaction. The transaction must be restored to its original state, and the compensation can be remedied flexibly. On the 4th, Li Si told Zhang San that there was a problem with the venue and the event could not be completed as scheduled. Zhang San could send a notification of cancellation, which is a bit like a transaction, but pay attention to it, zhang San can also send an activity extension notification

Okay, no nonsense. I have already written more than 20 things. I will not mention this article. The exception capture and resource compensation WF applications will be introduced below.

1. FaultHandlersActivity and FaultHandlerActivity1.1

1. The FaultHandlersActivity exception capture container provides an interface for the Activity component to capture and process exceptions.

2. Only the implemented Activity component can have the FaultHandlersActivity exception capture container.

3. Use the FaultHandlerActivity exception Capture Component in the exception capture container to capture and handle exceptions of the current Activity component.

4. You can add multiple FaultHandlerActivity exception capture components in the exception capture container.

5. to specify the exception type for the FaultHandlerActivity exception Capture Component, use the FaultTyp attribute to set

6. FaultHandlerActivity exception Capture component, which provides a container where you can add Exception Handling

7. There is a FaultHandlersActivity exception capture container. You can switch to the FaultHandlersActivity container design interface in the designer.

In visual design, you can switch to the container by sending it down.

Custom System. Exception derived class. To participate in instance persistence, you must add the [Serializable] flag during the definition.

If no exception is caught and an exception occurs, the process is terminated. if an exception is caught, the next container continues to run after the exception is handled. Note that the next container is not the next node of the current container.

1.2 use of the exception Capture Component FaultHandlerActivity

1. Multiple faultHandlersActivity can be added to a faultHandlersActivity container.

2. The FaultTyp attribute of each faultHandlerActivity is bound to a specific System. Exception derived class.

Each faultHandlerActivity has a corresponding sub-container, in which you can add other function-class Activity controls

3. When an exception occurs at the node, if the exception type is bound to faultHandlersActivity in the faultHandlersActivity container, the content in the sub-container corresponding to faultHandlerActivity will be executed.

4. when the Fault Handlers container is used to capture a common event, the content of the faultHandlerActivity sub-container corresponding to the Fault Handlers container is executed. The exception does not trigger the OnWorkflowTerminated event of the engine, but is tracked and monitored.

5. Use the ThrowActivity component to capture throw statements and code errors.

2. CompensatableSequence, CompensationHandlerActivity, and CompensateActivity2.1 CompensationHandlerActivity are compensated.

1. It is a container that can provide the capacity compensation function.

2. This container is available only when the Activity component implementing the ICompensatableActivity interface is available. You can switch to the Compensation processor View by right-clicking the View Compensation Handler in the menu.

3. CompensatableSequenceActivity and CompensatableTransactionScopeActivity implement this interface.

2.2 CompensatableSequenceActivity

1. CompensatableSequenceActivity implements the ICompensatableActivity interface. Therefore, the CompensationHandlerActivity container can be provided. You can switch to the Compensation processor View by right-clicking the View Compensation Handler in the menu (see figure)

2. The function is equivalent to appending the Sequence component of the Compensation Handler.

2.3 CompensateActivity

1. Specify the activity to be compensated for the TargetActivityName attribute of the Compensate component, and the Runtime will execute the target compensation process.

2. The Compensate component can only exist in abnormal containers and compensation containers.

Abnormal container

Compensation container CompensationHandlerActivity

2.4 basic use

Add the CompensatableSequence control and add normal operations.

Switch to the CompensationHandler container of the CompensatableSequence control and add the compensation operation if an error occurs.

Execute: If no throwActivity occurs, the process is completed normally and the operations in the compensation container are not executed. If throwActivity or other exceptions occur, the process will execute the CompensationHandler of the CompensatableSequence control to compensate the code in the container before termination, terminate the instance after the execution is complete.

2.5 when there are multiple serial CompensatableSequence, if an error occurs, the compensation is executed from the back to the back.

3 Application description of exception capture and compensation 3.1 No handling

3.2 handle exceptions

3.3 If there is a compensation container in the container and the compensation settings are made

3.4 If the container has an exception, it will not be executed even if there is compensation

3.5 if the container has an exception, you still want to perform compensation

3.6 if there are multiple compensation containers in the container, you can set the order in which compensation is executed in exception capture.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.