-
1. Re: Change a Timer length/period at runtime possible?
rrpeterson Oct 25, 2011 7:34 PM (in response to rrpeterson)I forgot to mention: The first process has the timer as a placeholder of 90 days, with the idea that the process instance will be updated at a later time and more functionality added as needed.
Would it make more sense to implement this differently? Rather than completely replacing the timer with a new node for instance?
-
2. Re: Change a Timer length/period at runtime possible?
rrpeterson Oct 26, 2011 12:59 PM (in response to rrpeterson)I think I've found how to programmatically change a timer's delay/period:
With the NodeInstance reference, it's possible to check if it's an instanceof TimerNodeInstance, and if so it can be cast to a TimerNodeInstance that you can use .getTimer() to then get/set the delay/period/etc.
Even though this would work, I'm still not convinced it's the "best" way.
****Edit****
Nevermind, this doesn't seem to work. Even though I can change the delay (make it 5s for example), it still seems to last the original duration. Is there any way to "trigger" a timer so it thinks its done?
-
3. Re: Change a Timer length/period at runtime possible?
rrpeterson Oct 28, 2011 10:54 AM (in response to rrpeterson)After getting some help from krisv (thanks again btw!) I think I'm closer, but still not quite able to get this to work.
I've tried canceling the old timer (canceling portion works great), but setting up the new timer seems to give issues.
The route I'm trying is:((TimerNodeInstance) nodeInstance).cancel();
// create timerInstance
TimerInstance timerInstance = new TimerInstance();
timerInstance.setDelay(TimeUtils.parseTimeString("5s")); // hard-code to X seconds
timerInstance.setPeriod(0); // hard-code to a period of 0
then I register the new timerInstance with the processInstance:
((InternalProcessRuntime)((WorkflowProcessInstance) nodeInstanceContainer).getKnowledgeRuntime().getProcessRuntime()).getTimerManager().registerTimer(timerInstance, (org.jbpm.process.instance.ProcessInstance) nodeInstanceContainer);
Lastly I set the timerInstanceId into the TimerNodeInstance:
((TimerNodeInstance) nodeInstance).internalSetTimerId(timerInstance.getId());
My trouble is the new timer event never fires. The old one is definitely canceled, if I set it for a short value (like 5 seconds) it doesn't fire after cancellation. But it's like the new timer is missing something, as it never fires either no matter what delay value is set.
I've also tried modifying the IntervalTrigger time of the original timer, but this change doesn't seem to get picked up either.
Both of these I've done while the processInstance.disconnect() was called, and processInstance.reconnect() is called afterwards.
Thanks for any help/suggestions!
-
4. Re: Change a Timer length/period at runtime possible?
rrpeterson Oct 28, 2011 11:57 AM (in response to rrpeterson)A bit more advice from krisv and I was able to get this to work:
After migrating to the new process, I cancel the old timer, then once the node ids are re-mapped (same as happens in the WorkflowProcessInstanceUpgrader), and the processInstance is reconnected, I call the "to" trigger for the original node (I keep a reference to the active timer when mapping the node ids from the old process to the new):
originalTimerNodeInstance.trigger(null, instance.getTimerNode().getTo().getToType());
This "clears" the original process timer, and allows execution to continue in the newly defined nodes in the new process.
Thanks again krisv for your help!