[jboss-user] [JBoss jBPM] - Re: [HOW-TO] Programmatically create and cancel Timers
sonicfab
do-not-reply at jboss.com
Thu Oct 11 10:32:00 EDT 2007
Ok here it is below.
(Maybe I should start a blog ;-), or independent paid consultancy ;-)) )
| public class JbpmLifeCycleListener {
|
| /** Keylogger. */
| private static KeyLogger keyLogger = KeyLoggerFactory.getLogger(JbpmLifeCycleListener.class);
|
| /** Jbpm configuration */
| private JbpmConfiguration _jbpmConfiguration;
|
| /** Resource. */
| private Resource configuration;
|
| /** SessionFactory */
| private SessionFactory sessionFactory;
|
| /** Set the configuration file resource. */
| @Required
| public void setConfiguration(Resource configuration) {
| this.configuration = configuration;
| }
|
| /** Set the hibernate session factory. */
| @Required
| public void setSessionFactory(SessionFactory sessionFactory) {
| this.sessionFactory = sessionFactory;
| }
|
| /**
| * Performs work after creation of JbpmConfiguration.
| */
| public void start() {
| initJBPMConfiguration();
| if (null != _jbpmConfiguration) {
| afterCreation(_jbpmConfiguration);
| }
| }
|
| /**
| * Initialize the {@link JbpmConfiguration}
| *
| */
| public void initJBPMConfiguration() {
| if (null == _jbpmConfiguration) {
| try {
| _jbpmConfiguration = JbpmConfiguration.parseInputStream(configuration.getInputStream());
| JbpmContext jbpmContext = _jbpmConfiguration.createJbpmContext();
| ServiceFactory svF = _jbpmConfiguration.getServiceFactory(Services.SERVICENAME_PERSISTENCE);
|
| // Configure it to start its own transaction and open hibernate session
| DbPersistenceServiceFactory dbF = (DbPersistenceServiceFactory)svF;
| dbF.setTransactionEnabled(true);
| dbF.setCurrentSessionEnabled(false);
| try {
| jbpmContext.setSessionFactory(sessionFactory);
| }
|
| finally {
| if (null != jbpmContext) jbpmContext.close();
| }
| } catch (IOException e) {
| keyLogger.log(DefaultLogKeyMessageConstants.GENERIC_ERROR_MESSAGE, new String[]{"Unable" +
| "to retrieve JBPMConfiguration"});
| }
| }
|
| }
|
| /**
| * Performs work before destruction JbpmConfiguration.
| */
| public void stop() {
| initJBPMConfiguration();
| if (null != _jbpmConfiguration) {
| beforeDestroy(_jbpmConfiguration);
| }
| }
|
| /**
| * Called after creation of the jbpm configuration to perform additional tasks.
| * @param configuration jbpmConfiguration
| */
| public void afterCreation(JbpmConfiguration configuration) {
| keyLogger.debug("Starting job executor...");
| configuration.startJobExecutor();
| keyLogger.debug("Job executor started.");
| }
|
| /**
| * Called before destruction of the jbpm configuration.
| * @param configuration
| */
| public void beforeDestroy(JbpmConfiguration configuration) {
| keyLogger.debug("Stopping job executor...");
| configuration.getJobExecutor().stop();
| keyLogger.debug("Job executor stopped.");
| }
|
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4094124#4094124
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4094124
More information about the jboss-user
mailing list