Delays

Sometimes in loops, but also on other occasions, we may want to program delays into BPEL processes. To do this we can specify durations or deadlines. Typically, we could specify delays to invoke an operation at a specific time, or wait for some time and then invoke an operation. For example, we could choose to wait a few seconds before invoking the BookWarehousing process, or before we pool the results of a previously initiated operation, or to wait between other iterations of a loop.

The simplest way to specify the delays is to use the <wait> activity. The <wait> activity can be:

  • for: Using this, we can specify duration; we specify a period of time. Consider the following code snippet:
    <wait>
      <for> duration-expression </for>
    </wait>
  • until: Using this, we can specify a deadline; we specify a certain date and time.
    <wait>
      <until> deadline-expression </until>
    </wait>

Deadline and duration expressions

To specify deadline and duration expressions, BPEL uses lexical representations of corresponding XML Schema data types. For deadlines, these data types are either dateTime or date. For duration, we use the duration data type. The lexical representation of expressions should conform to the XPath 1.0 expressions. The evaluation of such expressions should result in values that are of corresponding XML Schema types: dateTime and date for deadline and duration for duration expressions.

All three data types use lexical representation inspired by the ISO 8601 standard, which can be obtained from the ISO web page http://www.iso.ch. ISO 8601 lexical format uses characters within the date and time information. Characters are appended to the numbers and have the following meaning:

  • C represents centuries.
  • Y represents years.
  • M represents months.
  • D represents days.
  • h represents hours.
  • m represents minutes.
  • s represents seconds. Seconds can be represented in the format ss.sss to increase precision.
  • Z is used to designate Coordinated Universal Time (UTC). It should immediately follow the time of day element.

For the dateTime expressions, there is another designator:

  • T is used as time designator to indicate the start of the representation of the time.

Examples of deadline expressions are shown in the following code excerpts:

<wait>
  <until>'2014-03-18T21:00:00+01:00'</until>
</wait>
<wait>
  <until>'18:05:30Z'</until>
</wait>

For duration expressions, the following characters can also be used:

  • P is used as the time duration designator. Duration expressions always start with P.
  • Y follows the number of years.
  • M follows the number of months or minutes.
  • D follows the number of days.
  • H follows the number of hours.
  • S follows the number of seconds.

To specify a duration of 4 hours and 10 minutes, we use the following expression:

<wait>
  <for>'PT4H10M'</for>
</wait>

To specify a duration of 1 month, 3 days, 4 hours, and 10 minutes, we need to use the following expression:

<wait>
  <for>'P1M3DT4H10M'</for>
</wait>

The following expression specifies the duration of 1 year, 11 months, 14 days, 4 hours, 10 minutes, and 30 seconds:

<wait>
  <for>'P1Y11M14DT4H10M30S'</for>
</wait>

Adding delay to our book order management process

In the previous section of this chapter, we implemented the BookOrderManagementBPEL process. In the first example, we used the <while> loop to iterate through the books and invoke the BookWarehousingBPEL process for each book.

If we were expecting a long list of books to be processed, and if we did not want to put too much load on the BookWarehousingBPEL process, we could add a delay in the loop. This way, we will wait for a specific period of time each time we invoke the BookWarehousingBPEL process. Let's assume that we would like to wait for 2 seconds.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset