Starting a BPEL process instance according to a timed schedule in Oracle BPEL PM

Process instances in the Oracle BPEL PM can be initiated in a number of ways. Some are passive – the BPEL engine receives a call and as a result starts a new instance of the referenced process – while others are more active – the BPEL engine looks for events that it knows should trigger a new process instance. I am wondering if there is sort of an intermediate option, where the BPEL PM will start process instances according to a specific schedule, like every week on Sunday evening or every 5 minutes or so. In this article I will briefly go over the different ways to get a process instance started and some approaches todo it in a scheduled way. However, I am still looking for perhaps a built-in scheduler.....

Actively invoking a BPEL Process according to a schedule 

A BPEL process is published by the Oracle BPEL PM as a WebService. Anyone who can a webservice therefore can start a BPEL Process instance. Invoking WebServices can be done from many programming languages and run-time environments, including Java and PL/SQL. Both Java and PL/SQL have various options of scheduling jobs, for example using Java Timers or the Quartz framework, possibly in combination with Spring, or the DBMS_JOB or DBMS_SCHEDULER functionality in the Oracle database. The scheduled Java or PL/SQL program can make the call to the WebService end-point for the BPEL Process. In the resources you will find articles that describe how to set up ‘timed triggers’ in both Java containers and the Oracle database.

Oracle BPEL PM also provides an EJB style interfaces for many operations, including the call to a BPEL process. So instead of calling the BPEL process as WebService, we could invoke it as a Java method on a Session Bean. See for example: Calling into the Oracle BPEL Engine from Java.

Indirectly activating a BPEL Process from events – that occur according to a schedule

Oracle BPEL PM is more than a passive consumer of requests for process instantiation. It also can go out and actively look for reasons for creating a new process instance. The events that can cause a process instance to be instantiated by Oracle BPEL PM include:

  • reception of an Email
  • arrival of a file – on a file system or an FTP server
  • creation of a new or update of an existing database record

Each of these channels can be polled by the Oracle BPEL PM for specific occurrences. Using the respective adapter wizards in the BPEL Designer in JDeveloper 10.1.3.1, we can specify the polling interval as well as the configuration details (which emailserver and email-account, which directory, which table etc.). Thus we can for example have a BPEL process that is instantiated whenever a database record is found in certain table satisfying a certain query-condition.

It is very simple for a PL/SQL developer to create a job that is to run say every 5 minutes (or every other week on Saturday morning or whatever simple or complex scheduling logic you desire) that creates (or updates) a record in a table. If we then configure the BPEL process to poll every 5 minutes (or 5 seconds or 7 days) looking in that particular table for that record, we have scheduled our BPEL process by using a database job schedule without going to the trouble of calling the BPEL PM from the database.

Come to think of it: if we configure the BPEL process to poll for a record in DUAL, we probably do not need the database job at all!

Along the same lines, we can create external scheduling logic that provides events to trigger a BPEL Process instance by sending emails or creating files.

Note that the BPEL Process we set up to poll for database records, emails or files could in fact be a dispatcher that inspects the contents of the database record, email or file and the decides to invoke a specific BPEL Process. Of course it is tricky to pass meaningful input into these processes as the events that trigger them are generic and only different in terms of the time they get started.

Using a long-running BPEL Process with WAIT step to trigger other BPEL processes according to a schedule

One other approach, following from the last train of thought of having a Dispatcher type of BPEL process is the following – also described by Clemens Utschig I just found out -: create a BPEL Process with no other purpose than to start instances of one (or more) other BPEL Processes. This BPEL Process has no input parameters, no output and but a single instance. It has a single WHILE loop that has two steps:

  • wait – for as long as the interval between two scheduled process instances
  • invoke – the BPEL process you want to have instantiated

We  can probably make this a more advanced scheduling implementation by having a way to dynamically derive the wait time – using embedded or external logic – or adding conditions for invoking the BPEL process.

Conclusion

As a database programmer at heart, I think the quickest way to get a BPEL process started according to a potentially complex schedule with minimum coding effort would be using a database job (Schedule) that updates a database record in conjunction with a BPEL process that polls the database. The big disadvantage, apart from the slight overhead of regularly polling the database by the BPEL PM, is the split of process logic between the database and the BPEL PM. For simple schedules, I would probably use the option of creating a BPEL Process Dispatcher process with the WHILE-WAIT-INVOKE logic.

Resources

Job Scheduling in Java by Dejan Bosanac  http://www.onjava.com/pub/a/onjava/2004/03/10/quartz.html

Scheduling and Thread Pooling using Spring  (the Spring Framework documentation) http://www.springframework.org/docs/reference/scheduling.html

How-To: Use a container-managed Timer service in EJB – an Oracle OC4J 10.1.3 How To http://www.oracle.com/technology/tech/java/oc4j/1003/how_to/how-to-ejb-timer.html

Using Timers in J2EE Applications by Debu Panda http://www.onjava.com/pub/a/onjava/2004/10/13/j2ee-timers.html

Running BPEL service as a scheduled process… OTN Discussion Forum thread http://forums.oracle.com/forums/thread.jspa?threadID=373045

BPEL: Scheduling reoccuring processes from Clement Utschig’s blog – http://clemensblog.blogspot.com/2006/04/bpel-scheduling-reoccuring-processes.html (found round the time I had completed my own article)

Job Scheduling from Oracle 10g with DBMS_SCHEDULER – http://www.oradev.com/dbms_scheduler.jsp

Oracle 10gR2 Database Administrator’s Guide – Moving from DBMS_JOB to DBMS_SCHEDULER http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14231/jobtosched.htm#ADMIN037

 

5 Comments

  1. Maarten Smeets February 19, 2012
  2. soa February 18, 2010
  3. Peter Lorenzen February 27, 2007
  4. Eric Elzinga February 26, 2007
  5. Peter Lorenzen February 23, 2007