Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobAddedNotificationManager.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobAddedNotificationManager.java (revision 0) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobAddedNotificationManager.java (revision 0) @@ -0,0 +1,71 @@ +/* + * 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.pvm.internal.jobexecutor; + +import org.jbpm.api.job.Message; +import org.jbpm.internal.log.Log; +import org.jbpm.pvm.internal.env.EnvironmentImpl; +import org.jbpm.pvm.internal.session.DbSession; +import org.jbpm.pvm.internal.session.MessageSession; +import org.jbpm.pvm.internal.tx.Transaction; +import org.jbpm.pvm.internal.util.ReflectUtil; + +/** + * @author Huisheng Xu + */ +public class JobAddedNotificationManager { + + private static final Log log = Log.getLog(JobAddedNotificationManager.class.getName()); + + /* injected */ + Transaction transaction; + + /* injected */ + JobExecutor jobExecutor; + + boolean isNotificationAdded; + + public void doNotify() { + if (jobExecutor == null) { + log.debug("cannot find jobExecutor"); + return; + } + + //a transaction is not required (can be null) + if (transaction == null) { + log.debug("cannot find transaction"); + return; + } + + if (isNotificationAdded) { + return; + } + + isNotificationAdded = true; + + // notify the job executor after the transaction is completed + if (log.isTraceEnabled()) { + log.trace("registering job executor notifier with " + transaction); + } + transaction.registerSynchronization(new JobAddedNotification(jobExecutor)); + } +} Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorMessageSession.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorMessageSession.java (revision 6462) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorMessageSession.java (working copy) @@ -31,33 +31,27 @@ /** * @author Tom Baeyens + * @author Huisheng Xu */ public class JobExecutorMessageSession implements MessageSession { - + private static final Log log = Log.getLog(JobExecutorMessageSession.class.getName()); - + /* injected */ DbSession dbSession; - /* injected */ - Transaction transaction; - - boolean isNotificationAdded; + /** injected. */ + JobAddedNotificationManager jobAddedNotificationManager; public void send(Message message) { - log.debug("sending message "+ReflectUtil.getUnqualifiedClassName(message.getClass())); + if (log.isDebugEnabled()) { + log.debug("sending message " + ReflectUtil.getUnqualifiedClassName(message.getClass())); + } dbSession.save(message); - if (!isNotificationAdded) { - isNotificationAdded = true; - - JobExecutor jobExecutor = EnvironmentImpl.getCurrent().get(JobExecutor.class); - if (jobExecutor!=null) { - // notify the job executor after the transaction is completed - log.trace("registering job executor notifier with "+transaction); - transaction.registerSynchronization(new JobAddedNotification(jobExecutor)); - } + if (jobAddedNotificationManager != null) { + jobAddedNotificationManager.doNotify(); } } } Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSession.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSession.java (revision 6462) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/jobexecutor/JobExecutorTimerSession.java (working copy) @@ -31,41 +31,30 @@ * Timers created with this service are committed at the end of the transaction, * so their execution will be late if the delay is shorter than the transaction. * In that case, they will be executed at the end of the transaction. - * + * * @author Tom Baeyens, Pascal Verdage + * @author Huisheng Xu */ public class JobExecutorTimerSession implements TimerSession { private static final Log log = Log.getLog(TimerSession.class.getName()); /* injected */ - Transaction transaction; - - /* injected */ - JobExecutor jobExecutor; - - /* injected */ Session session; - boolean jobExecutorNotificationScheduled = false; + /** injected. */ + JobAddedNotificationManager jobAddedNotificationManager; public void schedule(Timer timer) { if (timer == null) throw new JbpmException("null timer scheduled"); TimerImpl timerImpl = (TimerImpl) timer; timerImpl.validate(); - + log.debug("scheduling " + timer); session.save(timer); - - if ( (!jobExecutorNotificationScheduled) - && (jobExecutor!=null) - ) { - jobExecutorNotificationScheduled = true; - - //a transaction is not required (can be null) - if (transaction != null) { - transaction.registerSynchronization(new JobAddedNotification(jobExecutor)); - } + + if (jobAddedNotificationManager != null) { + jobAddedNotificationManager.doNotify(); } } Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/JobAddedNotificationManagerBinding.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/JobAddedNotificationManagerBinding.java (revision 0) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/JobAddedNotificationManagerBinding.java (revision 0) @@ -0,0 +1,57 @@ +/* + * 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.pvm.internal.wire.binding; + +import org.jbpm.pvm.internal.jobexecutor.JobAddedNotificationManager; +import org.jbpm.pvm.internal.jobexecutor.JobExecutor; +import org.jbpm.pvm.internal.wire.descriptor.EnvDescriptor; +import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor; +import org.jbpm.pvm.internal.wire.descriptor.TransactionRefDescriptor; +import org.jbpm.pvm.internal.xml.Parse; +import org.jbpm.pvm.internal.xml.Parser; +import org.w3c.dom.Element; + +/** + * parses a descriptor for creating a {@link JobAddedNotificationManager}. + * + * See schema docs for more details. + * + * @author Huisheng Xu + */ +public class JobAddedNotificationManagerBinding extends WireDescriptorBinding { + + public JobAddedNotificationManagerBinding() { + super("job-added-notification-manager"); + } + + public Object parse(Element element, Parse parse, Parser parser) { + ObjectDescriptor objectDescriptor = new ObjectDescriptor(); + objectDescriptor.setClassName(JobAddedNotificationManager.class.getName()); + + // inject fields + objectDescriptor.addInjection("transaction", new TransactionRefDescriptor()); + objectDescriptor.addInjection("jobExecutor", new EnvDescriptor(JobExecutor.class)); + + return objectDescriptor; + } +} + Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MessageSessionBinding.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MessageSessionBinding.java (revision 6462) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MessageSessionBinding.java (working copy) @@ -21,6 +21,7 @@ */ package org.jbpm.pvm.internal.wire.binding; +import org.jbpm.pvm.internal.jobexecutor.JobAddedNotificationManager; import org.jbpm.pvm.internal.jms.JmsMessageSession; import org.jbpm.pvm.internal.jobexecutor.JobExecutorMessageSession; import org.jbpm.pvm.internal.session.DbSession; @@ -35,10 +36,11 @@ import org.w3c.dom.Element; /** parses a descriptor for creating a {@link MessageSession}. - * + * * See schema docs for more details. - * + * * @author Tom Baeyens + * @author Huisheng Xu */ public class MessageSessionBinding extends WireDescriptorBinding { @@ -48,12 +50,12 @@ public Object parse(Element element, Parse parse, Parser parser) { ObjectDescriptor objectDescriptor = new ObjectDescriptor(); - + String target = XmlUtil.attribute(element, "target"); if ("jms".equals(target)) { objectDescriptor.setClassName(JmsMessageSession.class.getName()); objectDescriptor.addInjection("dbSession", new ContextTypeRefDescriptor(DbSession.class)); - + if (element.hasAttribute("session-jndi")) { String jmsSessionJndiName = element.getAttribute("session-jndi"); JndiDescriptor jndiDescriptor = new JndiDescriptor(jmsSessionJndiName); @@ -61,7 +63,7 @@ } else { parse.addProblem("attribute <"+element.getLocalName()+" session-jndi=\"...\" is required when target=\"jms\"", element); } - + if (element.hasAttribute("destination-jndi")) { String jmsDestinationJndiName = element.getAttribute("destination-jndi"); JndiDescriptor jndiDescriptor = new JndiDescriptor(jmsDestinationJndiName); @@ -72,8 +74,9 @@ } else { objectDescriptor.setClassName(JobExecutorMessageSession.class.getName()); - objectDescriptor.addInjection("transaction", new TransactionRefDescriptor()); objectDescriptor.addInjection("dbSession", new ContextTypeRefDescriptor(DbSession.class)); + objectDescriptor.addInjection("jobAddedNotificationManager", + new ContextTypeRefDescriptor(JobAddedNotificationManager.class)); } return objectDescriptor; Index: modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/TimerSessionBinding.java =================================================================== --- modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/TimerSessionBinding.java (revision 6462) +++ modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/TimerSessionBinding.java (working copy) @@ -22,6 +22,7 @@ package org.jbpm.pvm.internal.wire.binding; import org.hibernate.Session; +import org.jbpm.pvm.internal.jobexecutor.JobAddedNotificationManager; import org.jbpm.pvm.internal.jobexecutor.JobExecutor; import org.jbpm.pvm.internal.jobexecutor.JobExecutorTimerSession; import org.jbpm.pvm.internal.session.TimerSession; @@ -35,10 +36,11 @@ import org.w3c.dom.Element; /** parses a descriptor for creating a {@link TimerSession}. - * + * * See schema docs for more details. * * @author Tom Baeyens, Pascal Verdage + * @author Huisheng Xu */ public class TimerSessionBinding extends WireDescriptorBinding { @@ -48,7 +50,7 @@ public Object parse(Element element, Parse parse, Parser parser) { ObjectDescriptor objectDescriptor = new ObjectDescriptor(); - + String target = XmlUtil.attribute(element, "target"); if ((target!=null) && ("ejb".equalsIgnoreCase(target))) { @@ -59,9 +61,9 @@ objectDescriptor.setClassName(JobExecutorTimerSession.class.getName()); // inject fields - objectDescriptor.addInjection("transaction", new TransactionRefDescriptor()); - objectDescriptor.addInjection("jobExecutor", new EnvDescriptor(JobExecutor.class)); objectDescriptor.addInjection("session", new ContextTypeRefDescriptor(Session.class)); + objectDescriptor.addInjection("jobAddedNotificationManager", + new ContextTypeRefDescriptor(JobAddedNotificationManager.class)); } return objectDescriptor; Index: modules/pvm/src/main/resources/jbpm.default.cfg.xml =================================================================== --- modules/pvm/src/main/resources/jbpm.default.cfg.xml (revision 6462) +++ modules/pvm/src/main/resources/jbpm.default.cfg.xml (working copy) @@ -6,7 +6,7 @@ - + @@ -20,7 +20,7 @@ - + @@ -32,14 +32,15 @@ - + + - + - + Index: modules/pvm/src/main/resources/jbpm.wire.bindings.xml =================================================================== --- modules/pvm/src/main/resources/jbpm.wire.bindings.xml (revision 6462) +++ modules/pvm/src/main/resources/jbpm.wire.bindings.xml (working copy) @@ -16,7 +16,7 @@ - + @@ -49,14 +49,15 @@ + - - + + @@ -67,7 +68,7 @@ - + @@ -94,7 +95,7 @@ - +