jBPM 7.0 create custom start timer

269 views
Skip to first unread message

net.han...@gmail.com

unread,
Jul 14, 2017, 2:40:16 AM7/14/17
to jBPM Development
Hi,

does anybody know a tutorial, which describes how to develop a custom start timer for jBPM 7.0 similar to this tutorial for custom work items?

Maciej Swiderski

unread,
Jul 14, 2017, 2:56:28 AM7/14/17
to net.han...@gmail.com, jBPM Development
what do you mean by custom start timer?

Maciej
On 14 Jul 2017, at 08:40, net.han...@gmail.com wrote:

Hi,

does anybody know a tutorial, which describes how to develop a custom start timer for jBPM 7.0 similar to this tutorial for custom work items?

--
You received this message because you are subscribed to the Google Groups "jBPM Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-developme...@googlegroups.com.
To post to this group, send email to jbpm-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jbpm-development/ba0c8545-863d-4efa-a66b-0bab041d3299%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

net.han...@gmail.com

unread,
Jul 14, 2017, 5:08:58 AM7/14/17
to jBPM Development, net.han...@gmail.com
i would like to create a custom module with a start timer event function. My start timer have some depends for detect the start moment.

For example the start moment ist depend from time of day, weekday, official holiday calendar and other parameters.

Maciej Swiderski

unread,
Jul 14, 2017, 5:24:59 AM7/14/17
to net.han...@gmail.com, jBPM Development
then the only thing you need is to call start process from your timer driven “command”. You can use any framework for scheduling tasks e.g. quartz once it fires the job then start the process.

Maciej

net.han...@gmail.com

unread,
Jul 17, 2017, 1:29:46 AM7/17/17
to jBPM Development, net.han...@gmail.com
Hi,

I don't understand what you mean. What do you mean with "any framework for scheduling"? Can you give me an example, please?

net.han...@gmail.com

unread,
Aug 18, 2017, 8:17:08 AM8/18/17
to jBPM Development, net.han...@gmail.com
Hi,

I have try to create a custrom WorkItemHandler to build me a timer.

This is my source:
import java.util.Calendar;
import java.util.Timer;

import org.drools.core.process.instance.WorkItemHandler;
import org.kie.api.runtime.process.WorkItem;
import org.kie.api.runtime.process.WorkItemManager;

public class EnergyTimer implements WorkItemHandler {

   
public EnergyTimer(){
   
}
   
   
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
       
Calendar calendar = Calendar.getInstance();
        calendar
.add(Calendar.MINUTE, 2);
       
       
Timer timer = new Timer();
        timer
.schedule(new EnergyTimerScheduledTask(manager, workItem.getId()), calendar.getTime());
   
}
   
   
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
        manager
.abortWorkItem(workItem.getId());
   
}

}

import java.util.TimerTask;

import org.kie.api.runtime.process.WorkItemManager;

public class EnergyTimerScheduledTask extends TimerTask {

   
private WorkItemManager manager;
   
private long workItemId;
   
   
public EnergyTimerScheduledTask(WorkItemManager manager, long workItemId) {
       
this.manager = manager;
       
this.workItemId = workItemId;
       
System.out.println("EnergyTimerScheduledTask init");
   
}
   
   
@Override
   
public void run() {
       
System.out.println("EnergyTimerScheduledTask run");
       
synchronized (this.manager) {
           
this.manager.completeWorkItem(this.workItemId, null);
       
}
   
}
}

After start a business processes the process wait the 2 minutes and fired a exception.

2017-08-18 14:04:27,369 INFO  [stdout] (Timer-2) EnergyTimerScheduledTask run

2017-08-18 14:04:27,372 WARN  [org.drools.persistence.api.TransactionSynchronizationRegistryHelper] (Timer-2) Unable to put resource org.kie.api.persistence.jpa.CmdScopedEntityManager value org.hibernate.jpa.internal.EntityManagerImpl@1044dd88 due to No transaction is running
2017-08-18 14:04:27,373 ERROR [stderr] (Timer-2) Exception in thread "Timer-2" javax.persistence.TransactionRequiredException: Explicitly joining a JTA transaction requires a JTA transaction be currently active

2017-08-18 14:04:27,373 ERROR [stderr] (Timer-2)     at org.hibernate.jpa.spi.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1545)

2017-08-18 14:04:27,373 ERROR [stderr] (Timer-2)     at org.hibernate.jpa.spi.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1530)

2017-08-18 14:04:27,374 ERROR [stderr] (Timer-2)     at org.drools.persistence.jpa.AbstractPersistenceContextManager.getCommandScopedEntityManager(AbstractPersistenceContextManager.java:107)

2017-08-18 14:04:27,374 ERROR [stderr] (Timer-2)     at org.jbpm.persistence.JpaProcessPersistenceContextManager.getCommandScopedEntityManager(JpaProcessPersistenceContextManager.java:47)

2017-08-18 14:04:27,374 ERROR [stderr] (Timer-2)     at org.drools.persistence.jpa.JpaPersistenceContextManager.getCommandScopedPersistenceContext(JpaPersistenceContextManager.java:59)

2017-08-18 14:04:27,374 ERROR [stderr] (Timer-2)     at org.drools.persistence.jpa.processinstance.JPAWorkItemManager.getPersistenceContext(JPAWorkItemManager.java:137)

2017-08-18 14:04:27,374 ERROR [stderr] (Timer-2)     at org.drools.persistence.jpa.processinstance.JPAWorkItemManager.completeWorkItem(JPAWorkItemManager.java:145)

2017-08-18 14:04:27,375 ERROR [stderr] (Timer-2)     at de.ten.jbpm.EnergyTimerScheduledTask.run(EnergyTimerScheduledTask.java:22)

2017-08-18 14:04:27,375 ERROR [stderr] (Timer-2)     at java.util.TimerThread.mainLoop(Timer.java:555)

2017-08-18 14:04:27,375 ERROR [stderr] (Timer-2)     at java.util.TimerThread.run(Timer.java:505)

Why does the exception is fired

Maciej Swiderski

unread,
Aug 18, 2017, 9:21:31 AM8/18/17
to net.han...@gmail.com, jBPM Development
this is because you attampt to use WorkItemManager outside of transaction - your timer task is executed by another thread.

Use this kind of code to overcome this problem:


Maciej
--
You received this message because you are subscribed to the Google Groups "jBPM Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-developme...@googlegroups.com.
To post to this group, send email to jbpm-dev...@googlegroups.com.

net.han...@gmail.com

unread,
Aug 21, 2017, 1:32:13 AM8/21/17
to jBPM Development, net.han...@gmail.com
Hi Maciej,

thank you for your help. It works great :-)

THX

net.han...@gmail.com

unread,
Aug 22, 2017, 8:30:24 AM8/22/17
to jBPM Development, net.han...@gmail.com
Hi Maciej,

in this post did you tell me, that only timer and async executor will be continue automaticly after restart the jbpm. With your help I've create a custom workitem to insert a waitable in my business process. Now I have the problem, that I have think, that I must start my business process once time and after this the process is mangage itself. But after a restart of my jbpm instance, this process will be stopped at one process step an I must intervene to continue the process.

What must I do to have a custom timer in my process which is continue after jbpm restart automaticly?

Sorry for my bad english, but I have some problems with this language ;-)

Hans

Maciej Swiderski

unread,
Aug 22, 2017, 9:49:58 AM8/22/17
to net.han...@gmail.com, jBPM Development
Hans,

if I go it right, you did create a work item handler that makes a wait state but it expects to be signaled by an external component to move on. There is nothing registered to automatically do it. So you need to have that external trigger somewhere. Easiest will be to create intermediate timer event in your process two wait for given amount of time and then move on. Or create async work see this [1] so the executor will pick up the work when is available.

Maciej


net.han...@gmail.com

unread,
Aug 23, 2017, 2:29:36 AM8/23/17
to jBPM Development, net.han...@gmail.com
My business processes should be started automatically. The start is supposed to happen via a timer based trigger.

I want to achieve that my business process starts at a certain calculated time. This time is, as already described, dependent on many factors.

Since no one could help me to develop a separate start timer, I had the hope that a WorkItem as a timer also works. But this does not seem to be. It is important to me that the solution is as simple as possible for the user. It is best to configure an element that is configured via the GUI and can be easily integrated into the development of the business process.

Maciej Swiderski

unread,
Aug 23, 2017, 3:02:28 AM8/23/17
to net.han...@gmail.com, jBPM Development
jBPM comes with start timer tasks that allows to start a process on predefined dates, though this does not seem to be valid for you. So what I would recommend is building a process that will be responsible for taking into consideration all the factors you have and come up with timer interval (or actual date) when the process should be started. Then use that time expression for intermediate timer event that will wait till the expected time and then start a process via call activity construct. 
That way you should be able to achive all that you need.

Maciej
--
You received this message because you are subscribed to the Google Groups "jBPM Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-developme...@googlegroups.com.
To post to this group, send email to jbpm-dev...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages