[jboss-user] [JBoss Seam] - Re: jBPM timer doesnt fire
pbrewer_uk
do-not-reply at jboss.com
Wed Oct 31 11:59:19 EDT 2007
I've discovered that I'm missing a scheduler service. jBPM 3.1.4 provides a SchedulerServlet that I had trouble getting to work out of the box, so I created a Seam component that starts the scheduler instead.
This helps to some extent with Seam 1.2.1.GA integration, but be aware that since there is no interception around timer executions you cannot use seam components in the workflow.
I think I'll wait for Seam 2 GA. For anyone that's interested, here's my seam component:
| package uk.co.iblocks.iflow.jbpm;
|
| import java.util.Date;
| import java.util.LinkedList;
| import java.util.List;
|
| import org.jboss.seam.Component;
| import org.jboss.seam.ScopeType;
| import org.jboss.seam.annotations.Create;
| import org.jboss.seam.annotations.Destroy;
| import org.jboss.seam.annotations.Install;
| import org.jboss.seam.annotations.Logger;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Scope;
| import org.jboss.seam.annotations.Startup;
| import org.jboss.seam.core.Jbpm;
| import org.jboss.seam.log.Log;
| import org.jboss.seam.log.Logging;
| import org.jbpm.scheduler.exe.Timer;
| import org.jbpm.scheduler.impl.SchedulerHistoryLog;
| import org.jbpm.scheduler.impl.SchedulerListener;
| import org.jbpm.scheduler.impl.SchedulerThread;
|
| @Name("jbpmScheduler")
| @Scope(ScopeType.APPLICATION)
| @Startup(depends={"org.jboss.seam.core.jbpm"})
| @Install(dependencies="org.jboss.seam.core.jbpm")
| public class JbpmScheduler {
|
| private class HistoryListener implements SchedulerListener {
|
| private Log executionLog = Logging.getLog(getClass()) ;
|
| public void timerExecuted(Date date, Timer timer) {
| executionLog.debug("Executed timer: id=#0, task=#1", timer.getId(), timer.getName()) ;
| historyLogs.add(new SchedulerHistoryLog(date, timer));
| if (historyLogs.size()>historyMaxSize) {
| historyLogs.removeLast();
| }
| }
| }
|
| private SchedulerThread schedulerThread = null ;
| private LinkedList<SchedulerHistoryLog> historyLogs = new LinkedList<SchedulerHistoryLog>();
| private int interval = 5000;
| private int historyMaxSize = 50 ;
|
| @Logger
| private Log log ;
|
| @Create
| public void startup() {
| log.info("Starting the jBPM scheduler");
| Jbpm jbpm = (Jbpm) Component.getInstance("jbpm") ;
| schedulerThread = new SchedulerThread(jbpm.getJbpmConfiguration());
| schedulerThread.setInterval(interval);
| schedulerThread.addListener(new HistoryListener());
| schedulerThread.start();
| log.info("jBPM scheduler has started.");
| }
|
| @Destroy
| public void shutdown() {
| if (isRunning()) {
| log.info("Stopping the jBPM scheduler.");
| schedulerThread.quit() ;
| schedulerThread = null;
| } else {
| log.debug("jBPM Scheduler can't be stopped because it was not running.");
| }
| }
|
| public boolean isRunning() {
| return ( (schedulerThread!=null)
| && (schedulerThread.isAlive()) );
| }
|
| public List<SchedulerHistoryLog> getSchedulerHistoryLogs() {
| return historyLogs;
| }
|
| public void clearSchedulerHistoryLogs() {
| historyLogs.clear();
| }
|
| public int getHistoryMaxSize() {
| return historyMaxSize;
| }
| public void setHistoryMaxSize(int historyMaxSize) {
| this.historyMaxSize = historyMaxSize;
| }
| public int getInterval() {
| return interval;
| }
| public void setInterval(int interval) {
| this.interval = interval;
| }
|
| public SchedulerThread getSchedulerThread() {
| return schedulerThread;
| }
|
| }
|
Cheers, Pete
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4100731#4100731
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4100731
More information about the jboss-user
mailing list