[jboss-user] [JBoss jBPM] - Re: Job Executor and Spring

oravecz do-not-reply at jboss.com
Sun Oct 12 02:47:38 EDT 2008


I tried my suggestion and it works, but the JbpmObjectFactory supplied in the spring modules integration is a bit lacking. It isn't wired in as the default object factory out of the gate. You have to do this yourself. Also, it is an all or nothing proposition, meaning if you use this object factory, all of the resources used by jBPM need to be defined in Spring.

Here is a new class that will attempt to find resource names in Spring, and if that fails, it will delegate to the original jBPM mechanism.



  | import org.springmodules.workflow.jbpm31.JbpmObjectFactory;
  | import org.jbpm.configuration.ObjectFactoryImpl;
  | import org.jbpm.configuration.ObjectFactoryParser;
  | import org.jbpm.JbpmConfiguration;
  | import org.springframework.core.io.Resource;
  | import org.springframework.beans.factory.InitializingBean;
  | import org.springframework.beans.factory.NoSuchBeanDefinitionException;
  | import org.slf4j.Logger;
  | import org.slf4j.LoggerFactory;
  | 
  | import java.io.*;
  | 
  | /**
  |  *
  |  */
  | public class SpringJbpmObjectFactory extends JbpmObjectFactory implements InitializingBean {
  | 
  |     // Statics -----------------------------------------------------------------
  | 
  |     private static final Logger LOG = LoggerFactory.getLogger(SpringJbpmObjectFactory.class);
  | 
  |     // Instances ---------------------------------------------------------------
  | 
  |     protected ObjectFactoryImpl _objectFactory;
  | 
  |     protected Resource _configuration;
  | 
  |     // InitializingBean implementation -----------------------------------------
  | 
  |     public void afterPropertiesSet() throws Exception {
  |         if (_configuration != null) {
  |             LOG.info("creating JbpmConfiguration from resource " + _configuration.getDescription());
  |             InputStream stream = _configuration.getInputStream();
  |             _objectFactory = ObjectFactoryParser.parseInputStream(stream);
  |             stream.close();
  |         }
  |         JbpmConfiguration.Configs.setDefaultObjectFactory(this);
  |     }
  | 
  |     // JbpmObjectFactory overrides ---------------------------------------------
  | 
  |     @Override
  |     public Object createObject(final String name) {
  |         Object result = null;
  |         try {
  |             result = super.createObject(name);
  |         } catch (NoSuchBeanDefinitionException e) {
  |             result = _objectFactory.createObject(name);
  |         }
  |         return result;
  |     }
  | 
  |     @Override
  |     public boolean hasObject(final String name) {
  |         boolean result = false;
  |         try {
  |             result = super.hasObject(name);
  |         } catch (NoSuchBeanDefinitionException e) {
  |             result = _objectFactory.hasObject(name);
  |         }
  |         return result;
  |     }
  | 
  |     // Properties --------------------------------------------------------------
  |     
  |     public void setConfiguration(final Resource configuration) {
  |         _configuration = configuration;
  |     }
  | }
  | 

If you are already using spring module for jBPM, you are probably using the LocalJbpmConfigurationFactoryBean class and you are more than likely specifying the path to a jbpm.xml config file. That's a problem, since the presence of a config file causes a fallback to the original object factory even if you specify your own object factory.

Here's how to configure spring to use the new object factory and a JobExecutor defined in the spring config file.



  |     <bean id="jbpmObjectFactory" class="com.example.jbpm.SpringJbpmObjectFactory"
  |           p:configuration="classpath:META-INF/jbpm.cfg.xml"
  |             />
  | 
  |     <bean id="jbpmConfig" class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean"
  |           p:sessionFactory-ref="sessionFactory"
  |           p:objectFactory-ref="jbpmObjectFactory"
  |             >
  |         <property name="processDefinitionsResources">
  |             <list>
  |                 <value>classpath:workflow/**/processdefinition.xml</value>
  |             </list>
  |         </property>
  | 
  |     </bean>
  | 
  |     <bean name="jbpm.job.executor" class="org.jbpm.job.executor.JobExecutor"
  |             p:jbpmConfiguration-ref="jbpmConfig"
  |             p:nbrOfThreads="1"
  |             p:idleInterval="5000"
  |             p:maxIdleInterval="3600000"
  |             p:historyMaxSize="20"
  |             p:maxLockTime="600000"
  |             p:lockMonitorInterval="60000"
  |             p:lockBufferTime="5000"
  |             >
  |         <property name="name" value="JbpmJobExecutor" />
  |     </bean>
  | 

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

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



More information about the jboss-user mailing list