Friday, May 7, 2010

Integrating Quartz Job Server with JBoss

I am getting the fallowing error while integrating Quartz job server in the JBoss
javax.naming.CommunicationException: Receive timed out
[Root exception is java.net.SocketTimeoutException: Receive timed out]

The steps i fallowed to configure the Quarts

1. I removed the quartz.jar from the {JBoss_Home}/deploy/lib and Quartz-ra.rar from {JBoss_Home}/deploy folder.

2. Added the quartz 1.6.5.jar and quartz-jboss-1.6.5.jar into {JBoss_Home}/deploy/lib .

3. Added the quartz-service.xml with fallowing details
<?xml version="1.0" encoding="UTF-8"?>
<server>
 <mbean code="org.quartz.ee.jmx.jboss.QuartzService" name="user:service=QuartzService,name=QuartzService">  
   <attribute name="JndiName">Quartz</attribute>
   <depends>jboss.jca:service=DataSourceBinding,name=QuartzDS</depends>
   <attribute name="Properties">      
     org.quartz.scheduler.instanceName = DefaultQuartzScheduler
     org.quartz.scheduler.rmi.export = false
     org.quartz.scheduler.rmi.proxy = false
     org.quartz.scheduler.xaTransacted = false
     org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
     org.quartz.threadPool.threadCount = 5
     org.quartz.threadPool.threadPriority = 4
     org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
   </attribute>
 
 </mbean>
</server>

4. I have written the Servlet to schedule the job
package com.radiant.cisms.help.servlets;

import java.io.IOException;
import java.util.Date;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleTrigger;
import org.quartz.impl.StdScheduler;
import org.quartz.impl.StdSchedulerFactory;


/**
* Servlet implementation class for Servlet: JobSeduleServlet
*
*/
public class JobSeduleServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
  static final long serialVersionUID = 1L;
 
   /* (non-Java-doc)
    * @see javax.servlet.http.HttpServlet#HttpServlet()
    */
   public JobSeduleServlet() throws SchedulerException {
       super();
       sedulingUsingJboss();
   }     
 

   protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       System.out.println("under doGet method.................");
       sedulingUsingJboss();
   }    
 
 
   protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       System.out.println("under doPost method.................");
       sedulingUsingJboss();
   } 
 

   public void sedulingUsingJboss(){
       System.out.println("under...sedulingUsingJboss................. ");
        try {
              InitialContext ctx = new InitialContext();
              System.out.println("Intial Context........."+ctx);
              System.out.println("..................."+ctx.lookup("Quartz"));
              StdScheduler scheduler = (StdScheduler) ctx.lookup("Quartz");
            
             JobDetail jd=new JobDetail("myjob",scheduler.DEFAULT_GROUP,TestJob.class);
              CronTrigger ct = new CronTrigger("cronTrigger","group2","0 0/5 * * * ?");
              scheduler.scheduleJob(jd,ct);
            
              } catch (Exception exc) {  
                 exc.printStackTrace();
              }
   }
}

5. Above servlet has been configured in web.xml as fallowes
<servlet>
       <servlet-name>JobSeduleServlet</servlet-name>
       <servlet-class>com.radiant.cisms.help.servlets.JobSeduleServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
   </servlet>

<servlet-mapping>
       <servlet-name>JobSeduleServlet</servlet-name>
       <url-pattern>/servlet/JobSeduleServlet</url-pattern>
   </servlet-mapping>
According to console generated by the server Quartz service is loading successfully.
But while calling the JobScheduleServlet it is throwing the exception as fallows
javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]


No comments: