Author: alex.guizar(a)jboss.com
Date: 2010-01-29 23:33:30 -0500 (Fri, 29 Jan 2010)
New Revision: 6151
Removed:
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/command/jms/
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/SaveJobExceptionCommand.java
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/LockMonitorThread.java
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/etc/jbpm.cfg.xml
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandListenerBean.java
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandServiceBean.java
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/ExecuteJobCommand.java
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java
Log:
JBPM-2691: revert command to save job exception. ESB message service will implement its
own behavior, cf. SOA-1882
delegate redelivery and exception reporting to the container
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java 2010-01-29
20:40:00 UTC (rev 6150)
+++
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/JobExecutorThread.java 2010-01-30
04:33:30 UTC (rev 6151)
@@ -159,9 +159,9 @@
}
catch (RuntimeException e) {
if (!DbPersistenceService.isLockingException(e)) throw e;
- // if this is a locking exception, keep it quiet
+ // keep locking exception quiet
StaleObjectLogConfigurer.getStaleObjectExceptionsLog()
- .error("failed to acquire lock on jobs " + jobsToLock);
+ .error("failed to acquire lock on jobs " + jobsToLock, e);
acquiredJobs = Collections.EMPTY_LIST;
}
}
@@ -190,9 +190,9 @@
jbpmContext.setRollbackOnly();
if (!DbPersistenceService.isLockingException(e)) throw e;
- // if this is a locking exception, keep it quiet
+ // keep locking exception quiet
StaleObjectLogConfigurer.getStaleObjectExceptionsLog()
- .error("failed to complete " + job);
+ .error("failed to complete " + job, e);
}
catch (Error e) {
jbpmContext.setRollbackOnly();
@@ -289,9 +289,9 @@
}
catch (RuntimeException e) {
if (!DbPersistenceService.isLockingException(e)) throw e;
- // if this is a locking exception, keep it quiet
+ // keep locking exception quiet
StaleObjectLogConfigurer.getStaleObjectExceptionsLog()
- .error("failed to determine next due date");
+ .error("failed to determine next due date", e);
nextDueDate = null;
}
}
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/LockMonitorThread.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/LockMonitorThread.java 2010-01-29
20:40:00 UTC (rev 6150)
+++
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/job/executor/LockMonitorThread.java 2010-01-30
04:33:30 UTC (rev 6151)
@@ -81,7 +81,10 @@
}
catch (RuntimeException e) {
jbpmContext.setRollbackOnly();
- throw e;
+ if (!DbPersistenceService.isLockingException(e)) throw e;
+ // keep locking exception quiet
+ StaleObjectLogConfigurer.getStaleObjectExceptionsLog()
+ .error("could not unlock overdue jobs", e);
}
catch (Error e) {
jbpmContext.setRollbackOnly();
@@ -93,9 +96,9 @@
}
catch (RuntimeException e) {
if (!DbPersistenceService.isLockingException(e)) throw e;
- // if this is a locking exception, keep it quiet
+ // keep locking exception quiet
StaleObjectLogConfigurer.getStaleObjectExceptionsLog()
- .error("could not unlock overdue jobs");
+ .error("could not unlock overdue jobs", e);
}
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/etc/jbpm.cfg.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/etc/jbpm.cfg.xml 2010-01-29
20:40:00 UTC (rev 6150)
+++ jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/etc/jbpm.cfg.xml 2010-01-30
04:33:30 UTC (rev 6151)
@@ -7,7 +7,6 @@
<service name="tx" factory="org.jbpm.tx.TxServiceFactory"
/>
<service name="logging"
factory="org.jbpm.logging.db.DbLoggingServiceFactory" />
<service name="authentication"
factory="org.jbpm.security.authentication.DefaultAuthenticationServiceFactory"
/>
- <service name="command"
factory="org.jbpm.command.jms.JmsCommandServiceFactory" />
</jbpm-context>
<!-- use the context class loader -->
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandListenerBean.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandListenerBean.java 2010-01-29
20:40:00 UTC (rev 6150)
+++
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandListenerBean.java 2010-01-30
04:33:30 UTC (rev 6151)
@@ -44,20 +44,22 @@
import org.jbpm.command.Command;
import org.jbpm.ejb.LocalCommandService;
import org.jbpm.ejb.LocalCommandServiceHome;
+import org.jbpm.persistence.db.DbPersistenceService;
+import org.jbpm.persistence.db.StaleObjectLogConfigurer;
/**
- * This message-driven bean listens for {@link ObjectMessage object messages} containing
a command
- * instance. The received commands are executed by the {@link CommandServiceBean command
service}
- * bean, using the local interface.
+ * This message-driven bean listens for {@link ObjectMessage object messages}
+ * containing a command instance. The received commands are executed by the
+ * {@link CommandServiceBean command service} bean, using the local interface.
*
- * The body of the message must be a Java object that implements the {@link Command}
interface. The
- * message properties, if any, are ignored.
+ * The body of the message must be a Java object that implements the
+ * {@link Command} interface. The message properties, if any, are ignored.
*
* <h3>Environment</h3>
*
* <p>
- * The environment entries and resources available for customization are summarized in
the table
- * below.
+ * The environment entries and resources available for customization are
+ * summarized in the table below.
* </p>
*
* <table border="1">
@@ -69,20 +71,22 @@
* <tr>
* <td><code>ejb/LocalCommandServiceBean</code></td>
* <td>EJB Reference</td>
- * <td>Link to the local {@linkplain CommandServiceBean session bean} that executes
commands on a
- * separate jBPM context.</td>
+ * <td>Link to the local {@linkplain CommandServiceBean session bean} that
+ * executes commands on a separate jBPM context.</td>
* </tr>
* <tr>
* <td><code>jms/JbpmConnectionFactory</code></td>
* <td>Resource Manager Reference</td>
- * <td>Logical name of the factory that provides JMS connections for producing
result messages.
- * Required for command messages that indicate a reply destination.</td>
+ * <td>Logical name of the factory that provides JMS connections for producing
+ * result messages. Required for command messages that indicate a reply
+ * destination.</td>
* </tr>
* <tr>
* <td><code>jms/DeadLetterQueue</code></td>
* <td>Message Destination Reference</td>
- * <td>Messages which do not contain a command are sent to the queue referenced
here. Optional; if
- * absent, such messages are rejected, which may cause the container to
redeliver.</td>
+ * <td>Messages which do not contain a command are sent to the queue referenced
+ * here. Optional; if absent, such messages are rejected, which may cause the
+ * container to redeliver.</td>
* </tr>
* </table>
*
@@ -96,8 +100,10 @@
MessageDrivenContext messageDrivenContext;
LocalCommandService commandService;
+
+ Destination deadLetterQueue;
+ ConnectionFactory jmsConnectionFactory;
Connection jmsConnection;
- Destination deadLetterQueue;
public void onMessage(Message message) {
try {
@@ -107,17 +113,32 @@
discard(message);
return;
}
- // execute command via local command executor bean
- Object result = commandService.execute(command);
- // send a response back if a "reply to" destination is set
- Destination replyTo = message.getJMSReplyTo();
- if (replyTo != null && (result instanceof Serializable || result == null))
{
- sendResult((Serializable) result, replyTo, message.getJMSMessageID());
+ try {
+ // execute command via local command executor bean
+ Object result = commandService.execute(command);
+ // send a response back if a "reply to" destination is set
+ Destination replyTo = message.getJMSReplyTo();
+ if (replyTo != null
+ && (result instanceof Serializable || result == null)) {
+ sendResult((Serializable) result, replyTo, message.getJMSMessageID());
+ }
}
+ catch (RuntimeException e) {
+ // MDBs are not supposed to throw exceptions
+ messageDrivenContext.setRollbackOnly();
+ // if this is a locking exception, keep it quiet
+ if (DbPersistenceService.isLockingException(e)) {
+ StaleObjectLogConfigurer.getStaleObjectExceptionsLog()
+ .error("failed to execute " + command, e);
+ }
+ else {
+ log.error("failed to execute " + command, e);
+ }
+ }
}
catch (JMSException e) {
messageDrivenContext.setRollbackOnly();
- log.error("could not process message " + message, e);
+ log.error("failed to process message " + message, e);
}
}
@@ -143,11 +164,13 @@
if (deadLetterQueue == null) {
// lookup dead letter queue
try {
- Context initial = new InitialContext();
- deadLetterQueue = (Destination)
initial.lookup("java:comp/env/jms/DeadLetterQueue");
+ Context jndiContext = new InitialContext();
+ deadLetterQueue =
+ (Destination)
jndiContext.lookup("java:comp/env/jms/DeadLetterQueue");
}
catch (NamingException e) {
- log.debug("failed to retrieve dead letter queue, rejecting message: " +
message);
+ log.debug("failed to retrieve dead letter queue, rejecting message: "
+ + message);
messageDrivenContext.setRollbackOnly();
return;
}
@@ -162,8 +185,8 @@
}
}
- private void sendResult(Serializable result, Destination destination, String
correlationId)
- throws JMSException {
+ private void sendResult(Serializable result, Destination destination,
+ String correlationId) throws JMSException {
log.debug("sending result " + result + " to " + destination);
Session jmsSession = createSession();
try {
@@ -178,20 +201,13 @@
private Session createSession() throws JMSException {
if (jmsConnection == null) {
- // lookup factory and create jms connection
- try {
- Context initial = new InitialContext();
- ConnectionFactory jmsConnectionFactory = (ConnectionFactory)
initial.lookup("java:comp/env/jms/JbpmConnectionFactory");
- jmsConnection = jmsConnectionFactory.createConnection();
- }
- catch (NamingException e) {
- throw new EJBException("error retrieving jms connection factory", e);
- }
+ // create jms connection
+ jmsConnection = jmsConnectionFactory.createConnection();
}
/*
- * if the connection supports xa, the session will be transacted, else the session
will auto
- * acknowledge; in either case no explicit transaction control must be performed -
see ejb 2.1 -
- * 17.3.5
+ * if the connection supports xa, the session will be transacted, else the
+ * session will auto acknowledge; in either case no explicit transaction
+ * control must be performed - see ejb 2.1 - 17.3.5
*/
return jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
}
@@ -210,6 +226,7 @@
}
jmsConnection = null;
}
+ jmsConnectionFactory = null;
deadLetterQueue = null;
commandService = null;
messageDrivenContext = null;
@@ -217,9 +234,14 @@
public void ejbCreate() {
try {
- Context initial = new InitialContext();
- LocalCommandServiceHome commandServiceHome = (LocalCommandServiceHome)
initial.lookup("java:comp/env/ejb/LocalCommandServiceBean");
+ Context jndiContext = new InitialContext();
+
+ LocalCommandServiceHome commandServiceHome =
+ (LocalCommandServiceHome)
jndiContext.lookup("java:comp/env/ejb/LocalCommandServiceBean");
commandService = commandServiceHome.create();
+
+ jmsConnectionFactory =
+ (ConnectionFactory)
jndiContext.lookup("java:comp/env/jms/JbpmConnectionFactory");
}
catch (NamingException e) {
throw new EJBException("error retrieving command service home", e);
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandServiceBean.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandServiceBean.java 2010-01-29
20:40:00 UTC (rev 6150)
+++
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/CommandServiceBean.java 2010-01-30
04:33:30 UTC (rev 6151)
@@ -93,7 +93,8 @@
* <td>The message service sends job messages to the queue referenced here. To
* ensure this is the same queue from which the {@linkplain JobListenerBean job
* listener bean} receives messages, the <code>message-destination-link
- * </code> points to a common logical destination,
<code>JobQueue</code>.</td>
+ * </code> points to a common logical
+ * destination, <code>JobQueue</code>.</td>
* </tr>
* </table>
*
@@ -141,16 +142,16 @@
}
public Object execute(Command command) {
- Object result = null;
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
try {
log.debug("executing " + command);
- result = command.execute(jbpmContext);
+ Object result = command.execute(jbpmContext);
// check whether command requested a rollback
TxService txService = jbpmContext.getServices().getTxService();
if (txService.isRollbackOnly()) {
sessionContext.setRollbackOnly();
}
+ return result;
}
catch (RuntimeException e) {
throw e;
@@ -161,7 +162,6 @@
finally {
jbpmContext.close();
}
- return result;
}
public void setSessionContext(SessionContext sessionContext) {
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/ExecuteJobCommand.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/ExecuteJobCommand.java 2010-01-29
20:40:00 UTC (rev 6150)
+++
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/ExecuteJobCommand.java 2010-01-30
04:33:30 UTC (rev 6151)
@@ -23,7 +23,6 @@
import org.jbpm.JbpmContext;
import org.jbpm.command.Command;
-import org.jbpm.command.CommandService;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.job.Job;
@@ -68,22 +67,9 @@
private static void executeJob(Job job, JbpmContext jbpmContext)
throws Exception {
- try {
- if (job.execute(jbpmContext)) {
- jbpmContext.getJobSession().deleteJob(job);
- }
+ if (job.execute(jbpmContext)) {
+ jbpmContext.getJobSession().deleteJob(job);
}
- catch (Exception e) {
- jbpmContext.setRollbackOnly();
- saveJobException(job, jbpmContext, e);
- }
}
- private static void saveJobException(Job job, JbpmContext jbpmContext,
- Exception exception) {
- CommandService commandService =
- (CommandService) jbpmContext.getServices().getService("command");
- commandService.execute(new SaveJobExceptionCommand(job.getId(), exception));
- }
-
}
Deleted:
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/SaveJobExceptionCommand.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/SaveJobExceptionCommand.java 2010-01-29
20:40:00 UTC (rev 6150)
+++
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/main/java/org/jbpm/ejb/impl/SaveJobExceptionCommand.java 2010-01-30
04:33:30 UTC (rev 6151)
@@ -1,66 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jbpm.ejb.impl;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-import org.jbpm.JbpmContext;
-import org.jbpm.command.Command;
-import org.jbpm.command.CommandService;
-import org.jbpm.db.JobSession;
-import org.jbpm.job.Job;
-
-/**
- * @author Alejandro Guizar
- */
-public class SaveJobExceptionCommand implements Command {
-
- private final long jobId;
- private final Exception exception;
-
- private static final long serialVersionUID = 1L;
-
- public SaveJobExceptionCommand(long jobId, Exception exception) {
- this.jobId = jobId;
- this.exception = exception;
- }
-
- public Object execute(JbpmContext jbpmContext) throws Exception {
- JobSession jobSession = jbpmContext.getJobSession();
- Job job = jobSession.loadJob(jobId);
-
- StringWriter out = new StringWriter();
- exception.printStackTrace(new PrintWriter(out));
- job.setException(out.toString());
-
- int retries = job.getRetries();
- if (retries > 0) {
- job.setRetries(retries - 1);
- CommandService commandService = (CommandService) jbpmContext.getServices()
- .getService("command");
- commandService.execute(new ExecuteJobCommand(jobId));
- }
- return job;
- }
-
-}
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java
===================================================================
---
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java 2010-01-29
20:40:00 UTC (rev 6150)
+++
jbpm3/branches/jbpm-3.2-soa/modules/enterprise/src/test/java/org/jbpm/enterprise/jta/JtaDbPersistenceTest.java 2010-01-30
04:33:30 UTC (rev 6151)
@@ -44,23 +44,23 @@
}
protected CommandService createCommandService() throws Exception {
- return getName().indexOf("CMT") != -1 ? super.createCommandService() : new
CommandServiceImpl(
+ return getName().indexOf("Container") != -1 ? super.createCommandService()
: new CommandServiceImpl(
JbpmConfiguration.getInstance());
}
- public void testCMTSuccess() throws Exception {
+ public void testContainerTxSuccess() throws Exception {
playTransaction(false);
}
- public void testCMTFailure() throws Exception {
+ public void testContainerTxFailure() throws Exception {
playTransaction(true);
}
- public void testBMTSuccess() throws Exception {
+ public void testUserTxSuccess() throws Exception {
playTransaction(false);
}
- public void testBMTFailure() throws Exception {
+ public void testUserTxFailure() throws Exception {
playTransaction(true);
}