7 Replies Latest reply on May 4, 2010 9:53 AM by rizwanp

    Need deployment structure for Quartz job with Spring framework on jboss

    rizwanp

      Hello,

      Currently my requirement is to deploy the Quartz jobs with Spring framework, executed via cron trigger.

      I have managed to derive the job, trigger and springContext.xml file for this task. Also, I am getting the desired result as a stand-alone application when executed via a testclient's main method.

      Now, i need the help in deploying this on the Jboss server environment and I am stuck as don't want to deploy it as WAR.

      Any suggestiion or help is very much appreciated, please help

      Below are the code components i have attached for the reference.


      import org.quartz.JobExecutionContext;
      import org.quartz.JobExecutionException;


      public interface JobInterface {

      public void init(JobExecutionContext jobExecutionContext)
         throws JobExecutionException;

      public void execute() throws JobExecutionException;

      public void destroy();

      }


      Implementation class :

       

      import org.quartz.JobExecutionContext;
      import org.quartz.JobExecutionException;

      public class RemoveJob implements JobInterface{

      @Override
      public void destroy() {
        // TODO Auto-generated method stub clearance
        System.out.println("Inside destroy");
      }

      @Override
      public void execute() throws JobExecutionException {
        // TODO Auto-generated method stub  actuall job
        System.out.println("Inside execute");
      }

      @Override
      public void init(JobExecutionContext jobExecutionContext)
         throws JobExecutionException {
        // TODO Auto-generated method stub initialization stuff
        System.out.println("Inside init");
      }

      }


      Delegator class
        

      public class DelegatingJobBean extends QuartzJobBean{
      private static final String App_Key = "applicationContext";
      private static final String Job_Key = "job.bean.name";
      // /protected org.apache.commons.logging.Log log = LogFactory.getLog(getClass());

      @Override
      protected void executeInternal(JobExecutionContext ctx)
         throws JobExecutionException {
        // TODO Auto-generated method stub
        System.out.println("Inside executeInternal.............");
        SchedulerContext schdContext = null;
        try
        {
         schdContext = ctx.getScheduler().getContext();
        
        }catch(SchedulerException e)
        {
         throw new JobExecutionException("Failure accesssing scheduler context ");
        }
       
        ApplicationContext appContext = (ApplicationContext)schdContext.get(App_Key);
       
        String jobBeanName = (String)ctx.getJobDetail()
              .getJobDataMap().get(Job_Key);
       
        //log.info("Starting Job : " +jobBeanName);
       
        JobInterface jobBean  =(JobInterface)appContext.getBean(jobBeanName);
       
       
        try
        {
         jobBean.init(ctx);
         jobBean.execute();
        }finally
        {
         jobBean.destroy();
        }
       
      }

      }

      Config File


      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
          >
      <!--  This is your job bean
        -->
      <bean id="removeExpireBean"
        autowire="byName" lazy-init="default" dependency-check="default">
        <!--  Ref to other beans. Add more if needed
        -->
        <!--<property name="serviceLocator">
         <ref bean="serviceLocator" />
        </property>
      --></bean>
      <!--
        Define the bean that delegates the work to the real job bean
      -->
      <bean name="removalJob"
        lazy-init="default" autowire="default" dependency-check="default">
        <property name="jobClass" value="DelegatingJobBean" />
        <property name="jobDataAsMap">
         <map>
          <!--  This specifies the actual job bean name
        -->
          <entry key="job.bean.name" value="removeExpireBean" />
          <!--  Any other job data map entries required by your job
        -->
          <entry key="sdtl.file.prefix" value="sdtl_" />
         </map>
        </property>
      </bean>
      <!--  Associate the delegating job bean with a trigger
        -->
      <bean id="removalTrigger"
        lazy-init="default" autowire="default" dependency-check="default">
        <property name="jobDetail" ref="removalJob" />
        <!--  run every morning at 6:30 AM
        -->
        <property name="cronExpression" value="0/10 * * * * ?" />
      </bean>
      <!--  Define the scheduler with the list of triggers
        -->
      <bean
        lazy-init="default" autowire="default" dependency-check="default">
        <property name="triggers">
         <list>
          <ref bean="removalTrigger" />
         </list>
        </property>
        <!--  Scheduler context key we use this in delegating job bean
        -->
        <property name="applicationContextSchedulerContextKey">
         <value>applicationContext</value>
        </property>
      </bean>
      </beans>

       

      Please suggest the deployment structure to be follw to work with this..