[jboss-user] [JBoss jBPM] - Timer Problem

colsona do-not-reply at jboss.com
Mon Jan 29 12:55:54 EST 2007


I deployed the attached process definition an ran it usin the attached JobQueueBean. The process executes to the wait state and appears to create the timer. I found that the timer never fired. In step tracing the timer creation I found the following methid in the Jboss source:

 public void createTimer(Timer timer) {
    // this wont work cause the process instance is not yet saved
    schedulerSession.saveTimer(timer);
  }

I also found the timer service wasn't deployed by default. I changed our app startup bean to create the timer service and confirmed it was running. It was unable to find any timers in the database which is needed for proper timer operation. We checked the DB tables ourselves and found that it was empty. We need to know if this is a defect which we need to get resolved immediately or if we have configured wrong and need to reconfigure.


The process definition:

  | <?xml version="1.0" encoding="UTF-8"?>
  | <process-definition
  |   xmlns="urn:jbpm.org:jpdl-3.1"  name="FileEvent">
  |    <start-state name="start">
  |       <transition name="" to="Is file complete"></transition>
  |    </start-state>
  |    <decision name="Is file complete">
  |       <handler class="com.spss.batch.queue.handlers.CheckFileComplete"/>
  |       <transition name="true" to="Start job process"/>
  |       <transition name="false" to="false"></transition>
  |    </decision>
  |    <state name="false">
  |     	<timer duedate="10 seconds" name="Wait For File" repeat="false" transition="Is file complete">	
  |     		<action class="com.spss.batch.queue.actions.FileEventTimerAction"/>
  |     	</timer>
  |       	<transition name="File isn't complete" to="Is file complete"></transition>
  |    </state>
  |    <node name="Start job process">
  |       <event type="node-enter">
  |       	<action class="com.spss.batch.queue.actions.StartJobProcess"></action>
  |       </event>
  |       <transition name="end" to="end1"></transition>
  |    </node>
  |       <end-state name="end1">
  |       <event type="node-enter">
  |          <action name="doTask"></action>
  |       </event>
  |    </end-state>
  | </process-definition>
  | 

The calling bean:

  | package com.spss.batch.queue;
  | 
  | import java.io.File;
  | 
  | import javax.ejb.EJB;
  | import javax.ejb.Stateless;
  | 
  | import org.apache.log4j.Logger;
  | import org.jbpm.JbpmConfiguration;
  | import org.jbpm.JbpmContext;
  | import org.jbpm.db.GraphSession;
  | import org.jbpm.graph.def.ProcessDefinition;
  | import org.jbpm.graph.exe.ProcessInstance;
  | import org.jbpm.graph.exe.Token;
  | 
  | @Stateless(name="BatchJobQueue", description="Job Queue Session Bean",mappedName="BatchJobQueue")
  | public class BatchJobQueueBean implements BatchJobQueue{
  | 	Logger log = Logger.getLogger(BatchJobQueue.class);
  | 
  | 	@EJB
  | 	ProcessController controller;
  | 	
  | 	JbpmContext context = null;
  | 	GraphSession graphSession = null;
  | 	
  | 	public void addJob(File watchFile, File fileID){
  | 		//JobTask task = JobTaskFactory.createJobTask(watchFile);
  | 		//JobQueue.getInstance().addJob(task);
  | 		try{
  | 			createBusinessProcess(watchFile, fileID);
  | //			controller.createBusinessProcessDefinition();
  | //			controller.createProcessInstance();
  | //			controller.signalProcess();
  | 		}catch(Exception ex){
  | 			log.error("Unable to start process!",ex);
  | 			throw new RuntimeException("Error starting job prcoess instance!",ex);
  | 		}
  | 	}
  | 	private void initContext(){
  | 		log.info("Getting jBPM context..");
  | 		context = JbpmConfiguration.getInstance().createJbpmContext();
  | 		log.info("Getting Graph Session..");
  | 		graphSession = context.getGraphSession();
  | 	}
  | 	public long createBusinessProcess(File watch, File fileID) throws Exception {
  | 		initContext();
  | 		//JbpmContext context = ManagedJbpmContext.instance();
  | 		log.info("Looking up process definition...");
  | 		//ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("HelloWorld");
  | 		ProcessDefinition processDefinition = null;
  | 		if(processDefinition==null){
  | 			log.info("Creating process definition...");
  | 			String helloWorldName = "PROCESS_DEFINITIONS/FileEvent/processdefinition.xml";
  | 			processDefinition = ProcessDefinition.parseXmlResource(helloWorldName);
  | 			log.info("Saving process definition...");
  | 			//context.deployProcessDefinition(processDefinition);
  | 			graphSession.saveProcessDefinition(processDefinition);
  | 		}
  | 		log.info("Creating process instance...");
  | 		ProcessInstance processInstance = processDefinition.createProcessInstance();
  | 		long processID = processInstance.getId();
  | 		JobTask task = JobTaskFactory.createJobTask(watch,fileID);
  | 		processInstance.getContextInstance().createVariable(JobTask.JOB_TASK, task);
  | 		log.info("Saving process instance..");
  | 		context.save(processInstance);
  | 		log.info("Closing context..");
  | 		context.close();
  | 		log.info("Process created!");
  | 		return processID;
  | 	}
  | 	public void signalBusinessProcess(long processID){
  | 		initContext();
  | 		log.info("Looking up process instance...");
  | 		ProcessInstance processInstance = context.loadProcessInstance(processID);
  | 		log.info("Getting root token");
  | 		Token token = processInstance.getRootToken();
  | 		log.info("Signaling root token..");
  | 		token.signal();
  | 		//log.info("Ending root token..");
  | 		//token.end();		
  | 	}
  | 
  | }
  | 

Action listener:

  | package com.spss.batch.queue.actions;
  | 
  | import org.jbpm.graph.def.ActionHandler;
  | import org.jbpm.graph.exe.ExecutionContext;
  | 
  | public class FileEventTimerAction implements ActionHandler {
  | 
  | 	public void execute(ExecutionContext executionContext) throws Exception {
  | 		executionContext.getNode().leave(executionContext);
  | 	}
  | 
  | }
  | 

  | package com.spss.batch.queue.handlers;
  | 
  | import org.jbpm.graph.exe.ExecutionContext;
  | import org.jbpm.graph.node.DecisionHandler;
  | 
  | import com.spss.batch.queue.JobTask;
  | 
  | public class CheckFileComplete implements DecisionHandler {
  | 
  | 	public String decide(ExecutionContext executionContext) throws Exception {
  | 		JobTask task = (JobTask)executionContext.getProcessInstance().getContextInstance().getVariable(JobTask.JOB_TASK);
  | 		System.out.println("CheckFileComplete: Processing task: "+task);
  | 		if(task.isReady()){
  | 			return Boolean.TRUE.toString();
  | 		}else{
  | 			return Boolean.FALSE.toString();
  | 		}
  | 	}
  | 
  | }
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4007922#4007922

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4007922



More information about the jboss-user mailing list