3 Replies Latest reply on May 1, 2008 2:37 AM by Zahid Maqbool

    JBPM Context in Startup servlet

    Zahid Maqbool Newbie

      Hi all, I have a requirement where I want a backgroung running service using quartz to perform all jbpm state operations. i.e. in which the system would be interacting with an external system. Now my question is this if i run this service manually from my application after starting the server it works perfect. But if i try to get it done through a startup servlet I am unable to get the JBPM context. If any one can help me out on this, It would be great.

        • 1. Re: JBPM Context in Startup servlet
          Ronald van Kuijk Apprentice

          But if i try to get it done through a startup servlet I am unable to get the JBPM context.

          Errors? Code? now it is just guessing for us and we are not good at that ;-)

          • 2. Re: JBPM Context in Startup servlet
            Zahid Maqbool Newbie

            public class Test 
            {
            
               @In JbpmContext jbpmContext;
               public void testQuartz() 
               {
                    System.out.println("TRYING TO Execute TEST JOB");
                    JobDetail jobDetail = new JobDetail("testJob", null,                
            
            TestJob.class);
                
                            jbpmContext.loadProcessInstance(1l);
                            jobDetail.getJobDataMap().put("jbpmContext", jbpmContext);
                            
                            SimpleTrigger trigger = new SimpleTrigger("trigger1", "group1");
                            trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
                            trigger.setRepeatInterval(30L * 1000L);
                            try 
                            {
                                    Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
                                    //sched.addGlobalJobListener(new Listener());
                                    sched.scheduleJob(jobDetail, trigger);
                                    sched.start();
                                    System.out.println(trigger.getNextFireTime());
                            }
                            catch (Exception e) 
                            {
                                    e.printStackTrace();
                            }
            }
            
            }







            When I load processInstance, it throws an error on JBPM Context  as Null

            • 3. Re: JBPM Context in Startup servlet
              Zahid Maqbool Newbie

              O.k. I got it working.


              I used the @Observer annotation to get it done,  of course I took help from... cant remember the name, but someone in this forum  :))


              My Link


              Also the Jbpm context is only available in a transaction.


              So here is my small piece of code which did the job. This is without  quartz so that the size doesn't increases.



              @Transactional
              @Name("startupTesting")
              public class StartupTesting {
              
                   @Logger
                   private Log log;     
                   
                   @In JbpmContext jbpmContext;
              
              
                   /**
                    * This is called by seam after initialization
                    * has finished.
                    */
                   @Observer("org.jboss.seam.postInitialization")
                   public void observe() 
                   {
                        try
                        {
                             log.info("Trying to load Test Jbpm Process Instance");
                             org.jbpm.graph.exe.ProcessInstance pi = jbpmContext.loadProcessInstance(60787l);
                             
                             System.out.println(pi.getKey()+" ----- "+pi.getStart());
                        }
                        catch(Exception e)
                        {
                             e.printStackTrace();
                             log.info("Operation Failed");
                        }
                        log.info("About to load system properties");
              
                   }
              }