Feeds

Programming constructs in BPEL

Part 3: BPELJ and Compensation

7 Elements of Radically Simple OS Migration

What compensation is not

So having indicated that compensation is essentially like an undo facility for BPEL, let us now consider what it is not. It is not an exception handling or fault handling mechanism. It is also not an exception handling mechanism (this is worth saying, as a scope looks a bit like a try block within Java - at least conceptually). A suitable analogy might be that if you are using an editor and undo some operations; this is because you have decided to take a different course of action - not because the editor has generated an error.

Indeed, you'll find that BPEL also includes the ability to catch and handle errors at different levels of activity nesting. A fault handler can be defined on any scope and either bound to a particular kind of fault (defined by the fault's qualified name - a bit like an exception, or its message type) or to any faults not caught by a more specific handler. A handler simply contains an activity that will run in case an error occurs. For example, it might contain a reply activity that notifies a partner that an error has occurred.

This makes it clear that Compensation is not error handling - it is what should happen when I want to roll back some activities within the overall business process. I use the term roll-back here - but also do not want to imply that this is some form of distributed transaction rollback - instead, you have to decide what happens to undo any effects of what has gone before. There is nothing automatic in this, there is no DBMS handling the rollback.

Compensation example

In the overview of compensation, I introduced the idea of a holiday booking BPEL script that allowed hotel, hire car and flight bookings to be made. The following BPEL extracts illustrate how these scopes might be defined with compensation being provided to facilitate undoing some element of the booking process if one element fails. For example, the following scope defines a sequence for booking a hotel room and a compensation handler that can be invoked if required:

<scope name="BookHotel">

    <!-- define a compensation handler -->

    <compensationHandler>

      <!-- call cancel ticked -->

        <invoke name="Invoke_CancelBooking" 

                partnerLink="HotelBookingService"

                portType="hotel:hotelBooking"

                operation="cancelRoom"/>

    </compensationHandler>

    <sequence name="Sequence_1">

        <invoke name="Invoke_BookRoom" 

                partnerLink="HotelBookingService"

                portType="hotel:hotelBooking"

                operation="reserveRoom"/>

    </sequence>

  </scope>

The compensation handler in the above cancels a hotel room that has previously been booked by the service called by this step in the BPEL script.

The following scope defines what happens when we try to book seats on a flight to go along with the hotel room bookings. In this case, a sequence is defined to book the seats, but associated with it is a fault handler that is invoked when no seats are available for the selected dates.

  <scope name="BookFLight">

    <faultHandlers>

      <catch faultName="flight:NoSeatsAvailfault"

        <throw name="cancelBooking" 

               faultName="client:cancelBooking"/>

      </catch>

    </faultHandlers>

    <sequence name="Sequence_2"

      <invoke name="Invoke_BookFLight" 

              partnerLink="airline" 

              portType="ReservationSystem" 

              operation="bookSeats"/>

    </sequence>

  </scope>

In the above code, a catch block is defined to catch the specific fault and throws itself a cancelBooking fault to the parent scope. That will trigger the compensation we have defined earlier.

The last part is to define a catch block on the parent scope, that triggers in case of a cancelBooking fault and fires the compensation defined on the BookHotel scope.

<faultHandlers>

    <!-- catch the rollback fault and call -->

    <catch faultName="client:cancelBooking">

      <compensate name="CompensateBoookings" 

                  scope="BookHotel"/>

    </catch>

  </faultHandlers>

Endpoint data privacy in the cloud is easier than you think

Next page: Summary

More from The Register

next story
PEAK LANDFILL: Why tablet gloom is good news for Windows users
Sinofsky's hybrid strategy looks dafter than ever
Leaked Windows Phone 8.1 Update specs tease details of Nokia's next mobes
New screen sizes, dual SIMs, voice over LTE, and more
Fiendishly complex password app extension ships for iOS 8
Just slip it in, won't hurt a bit, 1Password makers urge devs
Mozilla keeps its Beard, hopes anti-gay marriage troubles are now over
Plenty on new CEO's todo list – starting with Firefox's slipping grasp
Apple: We'll unleash OS X Yosemite beta on the MASSES on 24 July
Starting today, regular fanbois will be guinea pigs, it tells Reg
Another day, another Firefox: Version 31 is upon us ALREADY
Web devs, Mozilla really wants you to like this one
Secure microkernel that uses maths to be 'bug free' goes open source
Hacker-repelling, drone-protecting code will soon be yours to tweak as you see fit
Cloudy CoreOS Linux distro declares itself production-ready
Lightweight, container-happy Linux gets first Stable release
prev story

Whitepapers

7 Elements of Radically Simple OS Migration
Avoid the typical headaches of OS migration during your next project by learning about 7 elements of radically simple OS migration.
Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Consolidation: The Foundation for IT Business Transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.
Solving today's distributed Big Data backup challenges
Enable IT efficiency and allow a firm to access and reuse corporate information for competitive advantage, ultimately changing business outcomes.
A new approach to endpoint data protection
What is the best way to ensure comprehensive visibility, management, and control of information on both company-owned and employee-owned devices?