Friday 14 October 2011

BPEL Scheduling Processes

BPEL: Scheduling Processes

Introduction

All we know that, Oracle BPEL process instance can be initiate in number of ways. Like
Passive: BPEL engine receives a call (BPEL console or some other web service)
Active: BPEL engine looks for events to be occur that should trigger new instance of process.( Polling for file in particular folder and polling for new record in database table)
There is intermediate option where BPEL engine will start process instance at specific time (schedule).
This document talks more about scheduling BPEL process using various methods like Quartz scheduler and Wait activity.

Quartz : Scheduling Endpoint Activation      

Quartz is full featured, open source job scheduling system, that can integrated with any J2EE and J2SE applications.
 In BPEL Process Manager,  quartz is implemented as part of java class called DefaultSchedulerCalloutImpl .
To understand scheduling process, we will take a sample business scenario.
Sample Business Case : Consider the case where process need to poll for a file at every day 7PM to 7:30PM.
Actual Solution : Create a BPEL process in such way that it has to poll for particular file at some location of server by using file adaptor configuration wizard.
Consider an example where BPEL process named ScheduleBPELProcess is created to poll for particular file (File Adaptor Inbound Service)  and write the file information into database table.(In this example we have used oracle database 10g).  Process contains receive activity( to receive payload from file adaptor), Invoke activity ( To write payload to database) and Transform activity to map source data and destination data.
This BPEL process will be keep on polling for particular file every time (24X7) as per polling frequency defined in configuring file adaptor wizard at design time.
But our requirement is to schedule the above BPEL process in such way that , the process should poll only at specific time like 7PM to 7:30 PM. To achieve this functionality we need to add below piece of code in bpel.xml file of the BPEL process.
Open bpel.xml file and add the below code. You can check below screen shot for your reference. We will understand each and every component of below piece of code in subsequent manner 
 
 
<activationAgents>
     <activationAgent className="oracle.tip.adapter.fw.agent.jca.JCAActivationAgent"
                         partnerLink="readFileService" heartBeatInterval="10">
           <property name="schedulerCallout">DefaultSchedulerCalloutImpl</property>
           <property name="endpointScheduleOn">0 0 19 * * ?</property>
           <property name="endpointScheduleOff">0 30 19 * * ?</property>
    </activationAgent
</activationAgents>
 
 
Activation Agent is one which makes endpoint of adaptors active. Always you should have input for adaptor endpoints to start your process. In the above example readFileService partner link is active end point of BPEL process.
 
The activation agent called “ heartbeat” that does scheduling action.
The heartBeatInterval is measured in seconds, it specify that how frequently the schedule is checked.
 
Quartz is implemented as part of java class named DefaultSchedulerCalloutImpl. The quartz scheduler turns heartbeat on and off.
 
 
The next properties in scheduler code is endpointScheduleOn and endpointScheduleOff. Through these properties we will set the scheduling time for polling mechanism. The attribute for endpointScheduleOn and endpointScheduleoff element is cron sequence.
 
Cron sequence is unix utility that allow tasks to be automatically run in the background at regular intervals.
This cron
Sequence follows the specified set of syntax. In the above code cron sequence is as follows.
 
           <property name="endpointScheduleOn">0 0 19 * * ?</property>
           <property name="endpointScheduleOff">0 30 19 * * ?</property>
 
 
Here 0 0 19 * * ? and 0 30 19 * * ? specify that process should fire everyday between 7PM and 7:30PM.
 
Cron sequence is a string comprised of 6 or 7 fields separated by whitespace. The 7th field is optional.
 
Field Name
 
Allowed Values
 
Allowed Special Characters
Seconds
 
0-59
 
, - * /
Minutes
 
0-59
 
, - * /
Hours
 
0-23
 
, - * /
Day-of-month
 
1-31
 
, - * ? / L W C
Month
 
1-12 or JAN-DEC
 
, - * /
Day-of-Week
 
1-7 or SUN-SAT
 
, - * ? / L C #
Year (Optional)
 
empty, 1970-2099
 
, - * /
 
 
 
Here are the some examples for cron sequence.
Expression
 
Meaning
"0 0 12 * * ?"
 
Fire at 12pm (noon) every day
"0 15 10 ? * *"
 
Fire at 10:15am every day
"0 15 10 * * ?"
 
Fire at 10:15am every day
"0 15 10 * * ? *"
 
Fire at 10:15am every day
"0 15 10 * * ? 2005"
 
Fire at 10:15am every day during the year 2005
"0 * 14 * * ?"
 
Fire every minute starting at 2pm and ending at 2:59pm, every day
"0 0/5 14 * * ?"
 
Fire every 5 minutes starting at 2pm and ending at 2:55pm, every day
"0 0/5 14,18 * * ?"
 
Fire every 5 minutes starting at 2pm and ending at 2:55pm, AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day
"0 0-5 14 * * ?"
 
Fire every minute starting at 2pm and ending at 2:05pm, every day
"0 10,44 14 ? 3 WED"
 
Fire at 2:10pm and at 2:44pm every Wednesday in the month of March.
"0 15 10 ? * MON-FRI"
 
Fire at 10:15am every Monday, Tuesday, Wednesday, Thursday and Friday
"0 15 10 15 * ?"
 
Fire at 10:15am on the 15th day of every month
"0 15 10 L * ?"
 
Fire at 10:15am on the last day of every month
"0 15 10 ? * 6L"
 
Fire at 10:15am on the last Friday of every month
"0 15 10 ? * 6L"
 
Fire at 10:15am on the last Friday of every month
"0 15 10 ? * 6L 2002-2005"
 
Fire at 10:15am on every last friday of every month during the years 2002, 2003, 2004 and 2005
 
 
 
For more details on cron sequence locate the below URL.
 
http://quartz.sourceforge.net/javadoc/org/quartz/CronTrigger.html

1 comment:

  1. Rubicon Red provide an out of the box scheduler for the Oracle SOA Suite, enabling you to schedule:
    - Execution of a synchronous web service
    - Execution of one way or two way asynchronous web service
    - Publication of an EDN event to the SOA Suite Event Delivery Network
    It provides full cluster support (it uses Coherence to manage this)
    See http://www.rubiconred.com/scheduler for further details.
    There is an interesting blog on how to use this to Dynamically schedule Web Services from within a composite or a BPEL Process.

    ReplyDelete

xslt padding with characters call template for left pad and right pad

  Could a call-template be written that took two parameters ?   a string, and a   number) return the string with empty spaces appended t...