Add JobListener

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Add JobListener

popianovka
I'm building a Scheduling system based on Quartz, similar to the one referred to in the Cavaness book.  Everything is working, add Jobs, list jobs, add triggers (Cron), list triggers, etc.  - nice.  I have coded a couple of JobListeners that work when I hard code them.  I have a situation where I add a listener to a job (code snippet pasted here):

ServletContext context = getServletContext();
Scheduler sched = (Scheduler)context.getAttribute("scheduler");

try
{
   JobDetail jobDetail = sched.getJobDetail((String)valIn.get("JOBS"), "Elevation Jobs");
   JobListener listener = (JobListener)Class.forName((String)valIn.get("LISTENER")).newInstance();
   sched.addJobListener(listener);
   jobDetail.addJobListener(listener.getName());
                       
                       
 //the following returns the listener I just added
   String[] sjobs = jobDetail.getJobListenerNames();
}

When I leave this page and go to another to list jobs (another code snippet pasted):

ServletContext context = getServletContext();
Scheduler sched = (Scheduler)context.getAttribute("scheduler");
               
try
{
for (int i = 0; i < groupNames.length; i++)
{
   String groupName = groupNames[i];
   String[] jobs = sched.getJobNames(groupName);
   for (int j = 0; j < jobs.length; j++)
   {
      String job = jobs[j];
      JobDetail jobDetail = sched.getJobDetail(job, groupName);
                                       
      String sJobDesc = jobDetail.getDescription();
      String sJobClass = jobDetail.getJobClass().getName();
      String sJobName = jobDetail.getName();
     
    //the following does not return the listener I added previously  
      String array[] = jobDetail.getJobListenerNames();
   }
}
}

It seems as if the listener I added is not persisting.  Any ideas would be much appreciated.

Thanks in advance,
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=149843&messageID=222498#222498

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Add JobListener

popianovka
The listeners seem to get persisted when adding the job to the scheduler.

You could try, for example:
JobDetail jobDetail =  ... ;
 JobListener listener =  ... ;
 sched.addJobListener(listener);
 jobDetail.addJobListener(listener.getName());

// ... as before, but then replace the job in the scheduler, with the job + listener
 sched.addJob(jobDetail, true);

I think that should persist the listener you've just attached.

Martin
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=149843&messageID=222644#222644

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Add JobListener

popianovka
Perfect, thank you!
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=149843&messageID=230336#230336

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Add JobListener

hadjila20
This post has NOT been accepted by the mailing list yet.
Hi,

I am a beginner in quartz and I would some one to help me please:
I would like to use joblistener order to see the state of my jobs but also to be able to restart on failure.
First I add the xml file of the scheduler follows:

Code:
 <bean id="myJobListener" class="com.hongliang.quartz.MyJobListener">
         <property name="name" value="UnJobListener"/>
     </bean>


Then I create my class joblistener:

Code:
 package com.carte.scheduler;
 
 import org.quartz.JobDetail;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
 import org.quartz.JobListener;
 import org.springframework.batch.core.JobExecution;
 
 public class UnJobListener implements JobListener {
  public static final String LISTENER_NAME = "dummyJobListenerName";
 
  public UnJobListener() {
  // TODO Auto-generated constructor stub
  }
 
  @Override
  public String getName() {
// TODO Auto-generated method stub
  return LISTENER_NAME;
  }
 
  @Override
  // Run this if job is about to be executed.
  public void jobToBeExecuted(JobExecutionContext context) {
  // TODO Auto-generated method stub
  String jobName = context.getJobDetail().getKey().toString();
  System.out.println("jobToBeExecuted");
  System.out.println("Job : " + jobName + " is going to start...");
  //JobDetail jobDetail = context.getJobDetail();
 //         MyJobDetail myJobDetail = (MyJobDetail) jobDetail;          
 //         jobDetail.getJobDataMap().put("MessageAdded", myJobDetail.getMyMessage());
 
 
 
  }
 
 
  @Override
  public void jobExecutionVetoed(JobExecutionContext context) {
  // TODO Auto-generated method stub
        System.out.println("jobExecutionVetoed");
  }
 
  @Override
  public void jobWasExecuted(JobExecutionContext context,
  JobExecutionException jobException) {
  // TODO Auto-generated method stub
  System.out.println("jobWasExecuted");
 
  String jobName = context.getJobDetail().getKey().toString();
  System.out.println("Job : " + jobName + " is finished...");
 
  if (!jobException.getMessage().equals("")) {
  System.out.println("Exception thrown by: " + jobName
  + " Exception: " + jobException.getMessage());
  }
  }
 
 }
 
 
and there I also developed ablock of code that checks whether the state of the job is failed it i restart but a don't use the joblistener.

now I'm confused I do not know how to do, someone to help me svpp.