[jbpm-commits] JBoss JBPM SVN: r6671 - in projects/jbpm-ejb3/jbpm-ejb3: .settings and 19 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Sep 24 17:23:26 EDT 2010


Author: bradsdavis
Date: 2010-09-24 17:23:25 -0400 (Fri, 24 Sep 2010)
New Revision: 6671

Added:
   projects/jbpm-ejb3/jbpm-ejb3/.classpath
   projects/jbpm-ejb3/jbpm-ejb3/.project
   projects/jbpm-ejb3/jbpm-ejb3/.settings/
   projects/jbpm-ejb3/jbpm-ejb3/.settings/org.eclipse.jdt.core.prefs
   projects/jbpm-ejb3/jbpm-ejb3/.settings/org.maven.ide.eclipse.prefs
   projects/jbpm-ejb3/jbpm-ejb3/pom.xml
   projects/jbpm-ejb3/jbpm-ejb3/src.zip
   projects/jbpm-ejb3/jbpm-ejb3/src/
   projects/jbpm-ejb3/jbpm-ejb3/src/main/
   projects/jbpm-ejb3/jbpm-ejb3/src/main/java/
   projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/
   projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/
   projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/
   projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/binding/
   projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/binding/JbpmEjbConnectorService.java
   projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/binding/JbpmEjbConnectorServiceFactory.java
   projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/mdb/
   projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/mdb/CommandMDB.java
   projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/service/
   projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/service/CommandServiceImpl.java
   projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/service/CommandServiceLocal.java
   projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/job/
   projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/job/ext/
   projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/job/ext/ExecuteJobCommand.java
   projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/job/ext/ExecuteTimerCommand.java
   projects/jbpm-ejb3/jbpm-ejb3/src/main/resources/
   projects/jbpm-ejb3/jbpm-ejb3/src/test/
   projects/jbpm-ejb3/jbpm-ejb3/src/test/java/
   projects/jbpm-ejb3/jbpm-ejb3/src/test/resources/
   projects/jbpm-ejb3/jbpm-ejb3/target/
   projects/jbpm-ejb3/jbpm-ejb3/target/classes/
   projects/jbpm-ejb3/jbpm-ejb3/target/classes/com/
   projects/jbpm-ejb3/jbpm-ejb3/target/classes/com/jbpm/
   projects/jbpm-ejb3/jbpm-ejb3/target/classes/com/jbpm/ejb3/
   projects/jbpm-ejb3/jbpm-ejb3/target/classes/com/jbpm/ejb3/mdb/
   projects/jbpm-ejb3/jbpm-ejb3/target/classes/com/jbpm/ejb3/mdb/CommandMDB.class
   projects/jbpm-ejb3/jbpm-ejb3/target/classes/com/jbpm/ejb3/service/
   projects/jbpm-ejb3/jbpm-ejb3/target/classes/com/jbpm/ejb3/service/CommandServiceImpl.class
   projects/jbpm-ejb3/jbpm-ejb3/target/classes/com/jbpm/ejb3/service/CommandServiceLocal.class
   projects/jbpm-ejb3/jbpm-ejb3/target/test-classes/
Log:
Checking in jBPM-ejb3 project.  This is meant to standardize on MDB and Stateless Session Beans for CMT reasons.

Added: projects/jbpm-ejb3/jbpm-ejb3/.classpath
===================================================================
--- projects/jbpm-ejb3/jbpm-ejb3/.classpath	                        (rev 0)
+++ projects/jbpm-ejb3/jbpm-ejb3/.classpath	2010-09-24 21:23:25 UTC (rev 6671)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+	<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
+	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>


Property changes on: projects/jbpm-ejb3/jbpm-ejb3/.classpath
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: projects/jbpm-ejb3/jbpm-ejb3/.project
===================================================================
--- projects/jbpm-ejb3/jbpm-ejb3/.project	                        (rev 0)
+++ projects/jbpm-ejb3/jbpm-ejb3/.project	2010-09-24 21:23:25 UTC (rev 6671)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>jbpm-ejb3</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.maven.ide.eclipse.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
+	</natures>
+</projectDescription>


Property changes on: projects/jbpm-ejb3/jbpm-ejb3/.project
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: projects/jbpm-ejb3/jbpm-ejb3/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/jbpm-ejb3/jbpm-ejb3/.settings/org.eclipse.jdt.core.prefs	                        (rev 0)
+++ projects/jbpm-ejb3/jbpm-ejb3/.settings/org.eclipse.jdt.core.prefs	2010-09-24 21:23:25 UTC (rev 6671)
@@ -0,0 +1,3 @@
+#Fri Sep 24 07:56:16 EDT 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning


Property changes on: projects/jbpm-ejb3/jbpm-ejb3/.settings/org.eclipse.jdt.core.prefs
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: projects/jbpm-ejb3/jbpm-ejb3/.settings/org.maven.ide.eclipse.prefs
===================================================================
--- projects/jbpm-ejb3/jbpm-ejb3/.settings/org.maven.ide.eclipse.prefs	                        (rev 0)
+++ projects/jbpm-ejb3/jbpm-ejb3/.settings/org.maven.ide.eclipse.prefs	2010-09-24 21:23:25 UTC (rev 6671)
@@ -0,0 +1,9 @@
+#Fri Sep 24 07:51:00 EDT 2010
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1


Property changes on: projects/jbpm-ejb3/jbpm-ejb3/.settings/org.maven.ide.eclipse.prefs
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: projects/jbpm-ejb3/jbpm-ejb3/pom.xml
===================================================================
--- projects/jbpm-ejb3/jbpm-ejb3/pom.xml	                        (rev 0)
+++ projects/jbpm-ejb3/jbpm-ejb3/pom.xml	2010-09-24 21:23:25 UTC (rev 6671)
@@ -0,0 +1,65 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>org.jbpm.ejb3</groupId>
+	<artifactId>jbpm-ejb3</artifactId>
+	<version>1.0.0</version>
+	<name>jBPM EJB3 Module</name>
+	<description>EJB3 Services for jBPM	</description>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.6</source>
+					<target>1.6</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-ejb-plugin</artifactId>
+				<configuration>
+					<ejbVersion>3.1</ejbVersion>
+					<!--
+						<generateClient>true</generateClient> <clientIncludes>
+						<clientInclude>...</clientInclude> </clientIncludes>
+					-->
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+	<dependencies>
+		<dependency>
+			<groupId>javax.ejb</groupId>
+			<artifactId>ejb-api</artifactId>
+			<version>3.0</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>javax.jms</groupId>
+			<artifactId>jms</artifactId>
+			<version>1.1</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.jbpm.jbpm3</groupId>
+			<artifactId>jbpm-jpdl</artifactId>
+			<version>3.2.8</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+	    	<groupId>org.jboss.ejb3</groupId>
+	    	<artifactId>jboss-ejb3-ext-api</artifactId>
+	    	<version>1.1.1</version>
+	    	<scope>provided</scope>
+	    </dependency>
+		<dependency>
+			<groupId>commons-logging</groupId>
+			<artifactId>commons-logging</artifactId>
+			<version>1.1.1</version>
+			<type>jar</type>
+			<scope>provided</scope>
+		</dependency>
+	</dependencies>
+</project>
\ No newline at end of file


Property changes on: projects/jbpm-ejb3/jbpm-ejb3/pom.xml
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/binding/JbpmEjbConnectorService.java
===================================================================
--- projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/binding/JbpmEjbConnectorService.java	                        (rev 0)
+++ projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/binding/JbpmEjbConnectorService.java	2010-09-24 21:23:25 UTC (rev 6671)
@@ -0,0 +1,111 @@
+package com.jbpm.ejb3.binding;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.Hibernate;
+import org.jbpm.JbpmContext;
+import org.jbpm.db.JobSession;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.graph.exe.Token;
+import org.jbpm.job.Job;
+import org.jbpm.job.Timer;
+import org.jbpm.msg.MessageService;
+import org.jbpm.scheduler.SchedulerService;
+
+import com.jbpm.ejb3.service.CommandServiceLocal;
+import com.jbpm.job.ext.ExecuteJobCommand;
+import com.jbpm.job.ext.ExecuteTimerCommand;
+
+public class JbpmEjbConnectorService implements SchedulerService, MessageService {
+
+	private static final long serialVersionUID = 0x76208523adc69608L;
+	
+	private static final Log LOG = LogFactory.getLog(JbpmEjbConnectorService.class);
+
+	private final JbpmContext jbpmContext;
+	private final CommandServiceLocal commandService;
+
+	public JbpmEjbConnectorService(JbpmContext jbpmContext,
+			CommandServiceLocal csLocal) {
+		this.jbpmContext = jbpmContext;
+		this.commandService = csLocal;
+	}
+
+	
+	protected void sendTimer(Timer timer) {
+		send(timer, true);
+	}
+
+	protected void sendJob(Job job) {
+		send(job, false);
+	}
+
+	private void send(Job job, boolean timer) {
+		String type = timer ? " timer " : " job ";
+		if (LOG.isDebugEnabled()) {
+			LOG.debug("Calling async command service: " + type + job.getId());
+		}
+		Hibernate.initialize(job);
+		getJobSession().saveJob(job);
+
+		ExecuteJobCommand command = null;
+		if(timer)
+		{
+			command = new ExecuteTimerCommand(job.getId(), job.getDueDate(), false);
+		}
+		else
+		{
+			command = new ExecuteJobCommand(job.getId(), false);
+		}
+		
+		this.commandService.processCommandAsync(command);
+		
+		if(LOG.isDebugEnabled())
+		{
+			LOG.debug("Successfully called async command service: " + type + job.getId());
+		}
+	}
+
+	public void close() {
+		
+	}
+
+
+	public JobSession getJobSession() {
+		return jbpmContext.getJobSession();
+	}
+
+
+	@Override
+	public void createTimer(Timer timer) {
+		send(timer, true);
+	}
+
+
+	@Override
+	public void deleteTimer(Timer timer) {
+
+		
+	}
+
+
+	@Override
+	public void deleteTimersByName(String timerName, Token token) {
+		// TODO Auto-generated method stub
+		
+	}
+
+
+	@Override
+	public void deleteTimersByProcessInstance(ProcessInstance processInstance) {
+		// TODO Auto-generated method stub
+		
+	}
+
+
+	@Override
+	public void send(Job job) {
+		send(job, false);
+	}
+
+}


Property changes on: projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/binding/JbpmEjbConnectorService.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/binding/JbpmEjbConnectorServiceFactory.java
===================================================================
--- projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/binding/JbpmEjbConnectorServiceFactory.java	                        (rev 0)
+++ projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/binding/JbpmEjbConnectorServiceFactory.java	2010-09-24 21:23:25 UTC (rev 6671)
@@ -0,0 +1,42 @@
+package com.jbpm.ejb3.binding;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.svc.Service;
+import org.jbpm.svc.ServiceFactory;
+
+import com.jbpm.ejb3.service.CommandServiceLocal;
+
+public class JbpmEjbConnectorServiceFactory implements ServiceFactory {
+
+	private static final Log LOG = LogFactory.getLog(JbpmEjbConnectorServiceFactory.class);
+    private String ejbCommandServiceName;
+    
+	public JbpmEjbConnectorServiceFactory() {
+        ejbCommandServiceName = "whatever";
+	}
+	
+	@Override
+	public Service openService() {
+		
+		try {
+			Context initialContext = new InitialContext();
+			CommandServiceLocal cs = (CommandServiceLocal)initialContext.lookup(this.ejbCommandServiceName);
+			return new JbpmEjbConnectorService(JbpmConfiguration.getInstance().getCurrentJbpmContext(), cs);
+		} catch (NamingException e) {
+			LOG.error("Command service not found at JNDI: "+this.ejbCommandServiceName);
+		}
+
+		return null;
+	}
+	
+	@Override
+	public void close() {
+		// hmmm what do i need to do here?
+	}
+}


Property changes on: projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/binding/JbpmEjbConnectorServiceFactory.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/mdb/CommandMDB.java
===================================================================
--- projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/mdb/CommandMDB.java	                        (rev 0)
+++ projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/mdb/CommandMDB.java	2010-09-24 21:23:25 UTC (rev 6671)
@@ -0,0 +1,69 @@
+package com.jbpm.ejb3.mdb;
+
+import java.io.Serializable;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.EJB;
+import javax.ejb.MessageDriven;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.ObjectMessage;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jbpm.command.Command;
+
+import com.jbpm.ejb3.service.CommandServiceLocal;
+
+ at MessageDriven(activationConfig= {
+		@ActivationConfigProperty (propertyName="destinationType", propertyValue="javax.jms.Queue"),    
+	    @ActivationConfigProperty(propertyName="destination", propertyValue="queue/JbpmCommandQueue")})
+public class CommandMDB implements MessageListener {
+	
+	@EJB CommandServiceLocal commandService;
+	private static final Log LOG = LogFactory.getLog(CommandMDB.class);
+	
+	public void onMessage(Message message) {
+		ObjectMessage commandMessage = (ObjectMessage)message;
+
+		try {
+			Command jbpmCommand = extractCommand(commandMessage);
+			LOG.debug("Executing Command.");
+			
+			if(jbpmCommand == null)
+			{
+				//do nothing.
+				return;
+			}
+			commandService.processCommandSync(jbpmCommand);
+			
+			LOG.debug("Executing Complete.");
+		} catch (JMSException e) {
+			LOG.error("Unable to handle command.",e);
+		}
+	}
+
+    protected Command extractCommand(Message message) throws JMSException
+    {
+        if(message instanceof ObjectMessage)
+        {
+            LOG.debug("Deserializing command from jms message...");
+            ObjectMessage objectMessage = (ObjectMessage)message;
+            Serializable object = objectMessage.getObject();
+
+            //Fix the job interface issue.
+            if(object instanceof Command)
+            {
+                return (Command)object;
+            }
+            
+            LOG.warn("Not a command: " + object +" Ignoring.");
+        } else
+        {
+            LOG.warn("Not an object message: " + message);
+        }
+        return null;
+    }
+	
+}


Property changes on: projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/mdb/CommandMDB.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/service/CommandServiceImpl.java
===================================================================
--- projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/service/CommandServiceImpl.java	                        (rev 0)
+++ projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/service/CommandServiceImpl.java	2010-09-24 21:23:25 UTC (rev 6671)
@@ -0,0 +1,61 @@
+package com.jbpm.ejb3.service;
+
+import javax.annotation.Resource;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.command.Command;
+
+import com.jbpm.job.ext.ExecuteTimerCommand;
+
+ at Stateless
+ at TransactionManagement(TransactionManagementType.CONTAINER)
+public class CommandServiceImpl implements CommandServiceLocal {
+
+	protected static final JbpmConfiguration JBPM_CONFIG = JbpmConfiguration.getInstance();
+	protected static final String JMS_JBOSS_SCHEDULED_DELIVERY_PROP_NAME = "JMS_JBOSS_SCHEDULED_DELIVERY";
+	
+	@Resource(mappedName="java:/JmsXA") ConnectionFactory factory;
+	@Resource(mappedName="java:/JbpmCommandQueue") Destination commandQueue;
+	
+	
+	@Override
+	public Object processCommandSync(Command command) {
+		return null;
+	}
+	
+	@Override
+	public void processCommandAsync(Command command) throws JMSException {
+		Connection connection = factory.createConnection();
+		Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
+		
+		ObjectMessage om = session.createObjectMessage();
+		if(command instanceof ExecuteTimerCommand)
+		{
+			ExecuteTimerCommand timerCommand = (ExecuteTimerCommand)command;
+			
+			if(timerCommand.getDueDate()!=null)
+			{
+                om.setLongProperty("JMS_JBOSS_SCHEDULED_DELIVERY", timerCommand.getDueDate().getTime());
+			}
+		}
+		//If it doesn't have a due date, it will be null.
+		if(om.getObject()==null)
+		{
+			om.setObject(command);
+		}
+		
+		MessageProducer producer = session.createProducer(commandQueue);
+		producer.send(om);
+	}
+	
+}


Property changes on: projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/service/CommandServiceImpl.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/service/CommandServiceLocal.java
===================================================================
--- projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/service/CommandServiceLocal.java	                        (rev 0)
+++ projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/service/CommandServiceLocal.java	2010-09-24 21:23:25 UTC (rev 6671)
@@ -0,0 +1,14 @@
+package com.jbpm.ejb3.service;
+
+import javax.ejb.Local;
+import javax.jms.JMSException;
+
+import org.jbpm.command.Command;
+
+ at Local
+public interface CommandServiceLocal {
+
+	public Object processCommandSync(Command command);
+	public void processCommandAsync(Command command) throws JMSException;
+	
+}


Property changes on: projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/ejb3/service/CommandServiceLocal.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/job/ext/ExecuteJobCommand.java
===================================================================
--- projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/job/ext/ExecuteJobCommand.java	                        (rev 0)
+++ projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/job/ext/ExecuteJobCommand.java	2010-09-24 21:23:25 UTC (rev 6671)
@@ -0,0 +1,82 @@
+package com.jbpm.job.ext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jbpm.JbpmContext;
+import org.jbpm.command.Command;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.job.Job;
+
+public class ExecuteJobCommand implements Command {
+
+	private static final Log LOG = LogFactory.getLog(ExecuteJobCommand.class);
+
+	protected final long id;
+	protected final boolean redelivered;
+
+	public ExecuteJobCommand(Long id, boolean redelivered) {
+		this.id = id;
+		this.redelivered = redelivered;
+	}
+
+	@Override
+	public Object execute(JbpmContext jbpmContext) throws Exception {
+		Job job = acquireJob(jbpmContext);
+		if (job == null) {
+			if (LOG.isDebugEnabled()) {
+				LOG.debug("Job " + id + " was deleted");
+			}
+			return null;
+		}
+		if (job.isSuspended()) {
+			if (LOG.isDebugEnabled()) {
+				LOG.debug(job + " is suspended");
+			}
+		}
+		if (redelivered) {
+			if (job.getRetries() > 0) {
+				job.setRetries(job.getRetries() - 1);
+				if (LOG.isDebugEnabled()) {
+					LOG.debug("Rescheduling job " + job.getId());
+				}
+				job.setLockOwner(null);
+				jbpmContext.getServices().getMessageService().send(job);
+			} else {
+				LOG.error("Job retry count exceeded for job " + job.getId());
+			}
+			return null;
+		} else {
+			executeJob(job, jbpmContext);
+			return job;
+		}
+	}
+
+	protected Job acquireJob(JbpmContext jbpmContext) {
+		Job job = jbpmContext.getJobSession().loadJob(id);
+		ProcessInstance processInstance = job.getProcessInstance();
+		jbpmContext.addAutoSaveProcessInstance(processInstance);
+		if (job.isExclusive()) {
+			jbpmContext.getGraphSession().lockProcessInstance(processInstance);
+		}
+		job.setLockOwner(toString());
+		return job;
+	}
+
+	static void executeJob(Job job, JbpmContext jbpmContext) throws Exception {
+		if (LOG.isDebugEnabled()) {
+			LOG.debug("Executing " + job);
+		}
+
+		if (job.execute(jbpmContext)) {
+			jbpmContext.getJobSession().deleteJob(job);
+		}
+	}
+	
+	public long getId() {
+		return id;
+	}
+	
+	public boolean isRedelivered() {
+		return redelivered;
+	}
+}


Property changes on: projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/job/ext/ExecuteJobCommand.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/job/ext/ExecuteTimerCommand.java
===================================================================
--- projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/job/ext/ExecuteTimerCommand.java	                        (rev 0)
+++ projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/job/ext/ExecuteTimerCommand.java	2010-09-24 21:23:25 UTC (rev 6671)
@@ -0,0 +1,77 @@
+package com.jbpm.job.ext;
+
+import java.util.Date;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jbpm.JbpmContext;
+import org.jbpm.job.Timer;
+
+public class ExecuteTimerCommand extends ExecuteJobCommand {
+
+	private static final Log LOG = LogFactory.getLog(ExecuteTimerCommand.class);
+	protected final Date dueDate;
+
+	public ExecuteTimerCommand(Long jobId, Date dueDate, boolean redelivered) {
+		super(jobId, redelivered);
+		this.dueDate = dueDate;
+	}
+
+	public Object execute(JbpmContext jbpmContext) throws Exception {
+		Timer timer = jbpmContext.getJobSession().loadTimer(id);
+		if (timer == null) {
+			if (LOG.isDebugEnabled()) {
+				LOG.debug("Timer "+ id +" was deleted");
+			}
+			return null;
+		}
+		if (timer.isSuspended()) {
+			if (LOG.isDebugEnabled()) {
+				LOG.debug((new StringBuilder()).append(timer).append(
+						" is suspended").toString());
+			}
+			//WHAT WAS THIS FOR?
+			//RetryExecutor.handleSuspendedTimer(timer);
+			return null;
+		}
+		if (redelivered) {
+			if (timer.getRetries() > 0) {
+				timer.setRetries(timer.getRetries() - 1);
+				if (LOG.isDebugEnabled()) {
+					LOG.debug(("Rescheduling timer " + timer.getId() + ", " + timer.getDueDate()).toString());
+				}
+				jbpmContext.getServices().getSchedulerService().createTimer(
+						timer);
+			} else {
+				LOG.error("Timer retry count exceeded for timer " + timer.getId());
+			}
+			return null;
+		}
+		timer.setLockOwner(getClass().getName());
+		if(LOG.isDebugEnabled())
+		{
+			LOG.debug("Executing " + timer.toString());
+		}
+		try {
+			if (timer.execute(jbpmContext)) {
+				jbpmContext.getServices().getSchedulerService().deleteTimer(timer);
+			} else if (timer.getRepeat() != null) {
+				if (LOG.isDebugEnabled()) {
+					LOG.debug("Scheduling timer for repeat on " + timer.getDueDate().toString());
+				}
+				jbpmContext.getServices().getSchedulerService().createTimer(timer);
+			}
+		} catch (Exception e) {
+			if (LOG.isDebugEnabled()) {
+				LOG.debug(("Exception while executing " + timer.toString()), e);
+			}
+			jbpmContext.setRollbackOnly();
+		}
+		return null;
+	}
+	
+	public Date getDueDate() {
+		return dueDate;
+	}
+
+}


Property changes on: projects/jbpm-ejb3/jbpm-ejb3/src/main/java/com/jbpm/job/ext/ExecuteTimerCommand.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: projects/jbpm-ejb3/jbpm-ejb3/src.zip
===================================================================
(Binary files differ)


Property changes on: projects/jbpm-ejb3/jbpm-ejb3/src.zip
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: projects/jbpm-ejb3/jbpm-ejb3/target/classes/com/jbpm/ejb3/mdb/CommandMDB.class
===================================================================
(Binary files differ)


Property changes on: projects/jbpm-ejb3/jbpm-ejb3/target/classes/com/jbpm/ejb3/mdb/CommandMDB.class
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: projects/jbpm-ejb3/jbpm-ejb3/target/classes/com/jbpm/ejb3/service/CommandServiceImpl.class
===================================================================
(Binary files differ)


Property changes on: projects/jbpm-ejb3/jbpm-ejb3/target/classes/com/jbpm/ejb3/service/CommandServiceImpl.class
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: projects/jbpm-ejb3/jbpm-ejb3/target/classes/com/jbpm/ejb3/service/CommandServiceLocal.class
===================================================================
(Binary files differ)


Property changes on: projects/jbpm-ejb3/jbpm-ejb3/target/classes/com/jbpm/ejb3/service/CommandServiceLocal.class
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream



More information about the jbpm-commits mailing list