Sign in

System and method for performing compensation work

 Alexandre de Castro Alves
In accordance with embodiments, there are provided mechanisms and methods for performing compensation work. These mechanisms and methods can enable embodiments to provide design patterns for implementing compensation work. The ability of embodiments to provide design patterns for implementing...
Inventor: Alexandre de Castro Alves

U.S. Classification
705008000

Claims

What is claimed is:

1. A method for performing compensation work, the method comprising:

receiving a definition of at least one compensation function as a closure data structure, wherein the compensation function implements compensation work for at least one event that can be encountered during execution of forward work;

detecting during execution of forward work, an event triggering the at least one compensation work; and

retrieving a process state associated with the compensation function based upon the closure; wherein the process state contains data needed to execute compensating work at a different runtime than the runtime of execution of the forward work.

2. The method of claim 1, further comprising:

performing compensation work of the compensation function based upon a current state of the forward work that is to be undone at a different runtime than the runtime of execution of the forward work.

3. The method of claim 1, wherein receiving a definition of at least one compensation function as a closure data structure includes:

implementing the compensation function as a data structure comprising: (1) a pointer to the compensation function's code to be executed; and (2) a pointer to stack frame of closest lexically enclosing scope of the compensation function's declaration in a computer program text; and

associating the data structure with the at least one event that can be encountered during execution of forward work

4. The method of claim 1, wherein detecting during execution of forward work, an event triggering the at least one compensation work includes:

receiving an indication that at least one activity in a set of activities of forward work is to be undone by performing compensation work.

5. The method of claim 4, wherein receiving an indication that at least one activity in a set of activities of forward work is to be undone by performing compensation work includes:

detecting an event initiated by a user, the event indicating that the user desires that the forward work be undone.

6. The method of claim 4, wherein receiving an indication that at least one activity in a set of activities of forward work is to be undone by performing compensation work includes:

detecting an event initiated by a program, the event indicating that an error has occurred that requires that the forward work be undone.

7. The method of claim 1, wherein retrieving a process state associated with the compensation function based upon the closure includes:

retrieving, based upon a closure associated with the at least one event, a process state comprising variables from a stack frame associated with the compensation function.

8. The method of claim 1, wherein retrieving a process state associated with the compensation function based upon the closure includes:

retrieving, based upon a closure associated with the at least one event, a process state comprising code from a computer program text associated with the compensation function.

9. A machine-readable medium carrying one or more sequences of instructions for performing compensation work, which instructions, when executed by one or more processors, cause the one or more processors to carry out the steps of:

receiving a definition of at least one compensation function as a closure data structure, wherein the compensation function implements compensation work for at least one event that can be encountered during execution of forward work;

detecting during execution of forward work, an event triggering the at least one compensation work; and

retrieving a process state associated with the compensation function based upon the closure; wherein the process state contains data needed to execute compensating work at a different runtime than the runtime of execution of the forward work.

10. The machine-readable medium as recited in claim 9, further comprising instructions for carrying out the step of:

performing compensation work of the compensation function based upon a current state of the forward work that is to be undone at a different runtime than the runtime of execution of the forward work.

11. The machine-readable medium as recited in claim 9, wherein the instructions for carrying out the step of receiving a definition of at least one compensation function as a closure data structure include instructions for carrying out the steps of:

implementing the compensation function as a data structure comprising: (1) a pointer to the compensation function's code to be executed; and (2) a pointer to stack frame of closest lexically enclosing scope of the compensation function's declaration in a computer program text; and

associating the data structure with the at least one event that can be encountered during execution of forward work

12. The machine-readable medium as recited in claim 9, wherein the instructions for carrying out the step of detecting during execution of forward work, an event triggering the at least one compensation work include instructions for carrying out the step of:

receiving an indication that at least one activity in a set of activities of forward work is to be undone by performing compensation work.

13. The machine-readable medium as recited in claim 12, wherein the instructions for carrying out the step of receiving an indication that at least one activity in a set of activities of forward work is to be undone by performing compensation work include instructions for carrying out the step of:

detecting an event initiated by a user, the event indicating that the user desires that the forward work be undone.

14. The machine-readable medium as recited in claim 12, wherein the instructions for carrying out the step of receiving an indication that at least one activity in a set of activities of forward work is to be undone by performing compensation work include instructions for carrying out the step of:

detecting an event initiated by a program, the event indicating that an error has occurred that requires that the forward work be undone.

15. The machine-readable medium as recited in claim 9, wherein the instructions for carrying out the step of retrieving a process state associated with the compensation function based upon the closure include instructions for carrying out the step of:

retrieving, based upon a closure associated with the at least one event, a process state comprising variables from a stack frame associated with the compensation function.

16. The machine-readable medium as recited in claim 9, wherein the instructions for carrying out the step of retrieving a process state associated with the compensation function based upon the closure include instructions for carrying out the step of:

retrieving, based upon a closure associated with the at least one event, a process state comprising code from a computer program text associated with the compensation function.

17. An apparatus for performing compensation work, the apparatus comprising:

a processor; and

one or more stored sequences of instructions which, when executed by the processor, cause the processor to carry out the steps of:
receiving a definition of at least one compensation function as a closure data structure, wherein the compensation function implements compensation work for at least one event that can be encountered during execution of forward work;
detecting during execution of forward work, an event triggering the at least one compensation work; and
retrieving a process state associated with the compensation function based upon the closure; wherein the process state contains data needed to execute compensating work at a different runtime than the runtime of execution of the forward work.