Timer Event in BPMN 2

Leave a comment

June 18, 2011 by huionn

BPMN 2 provides Timer Event with attributes timeDate, timeCycle and timeDuration. In addition, those attributes accept expression in ISO-8901 format which is very comprehensive for date & time, interval and duration.

Although jBPM 5 does not support those BPMN attributes yet, it does support recurring cycle out of box. But I found that this recurring cycle feature is undocumented and I have to dig it out by reading the codes.

In BPMN 2 Process Editor in Eclipse, for the recurring timer event, set the Timer Delay to follow “initial-delay###cycle-period” syntax (for example, 5000ms###1000ms).  (I edited Timer Period, but the editor seems like ignoring it). Then when running the process, the timer event will be triggered after the initial delay and then every cycle period.

The key class in this implementation is org.drools.time.impl.JDKTimerService$JDKCallableJob which reschedules itself after executing.


On the other hands, I found that error reporting/handling in Timer Event is awkward. For example, I tried with TimerEventProcessTest in https://github.com/esteban-aliverti/JBPM-Samples, the example does not work because of ClassCastException during casting bill+0.10 from Double to Float.

In order to receive the exception from “Future”, I have to use an ugly hack with a lot of casting. I guess this is definitely not a recommended way to handle the exception.

	
	TimerManager timerManager = ((InternalProcessRuntime) ((InternalWorkingMemoryEntryPoint) ksession)
			.getInternalWorkingMemory().getProcessRuntime())
			.getTimerManager();
	Collection timers = timerManager.getTimers();
	for (TimerInstance timer : timers) {
		try {
			((JDKJobHandle) timer.getJobHandle()).getFuture().get();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
	}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: