Roy's Blog

On Software and Fish.

Get All Jobs With Terracotta Quartz 2.0+

| Comments

The most recent Terracotta Quartz release seems to have changed some of the API methods to list scheduled jobs. Although minor changes, I thought I’d post sample code here for anyone trying the same thing as I, and hitting a wall with the API differences. Some of the changes are documented here in the latest release, but it’s OSS, so expect the docs to suck. ;–)

The changes, as best I can tell (correct me if I’m wrong), revolve around accessing the Scheduler object.You can see the differences between the 1.8 API and the 2.0 API.

Changes I found:

  • scheduler.getJobGroupNames() now returns a List , and not a String[].

  • scheduler.getJobNames(groupName); has dissapeared.

  • You must now use scheduler.getJobKeys(GroupMatcher.groupEquals(name)); to get a Set, which will be used to call scheduler.getJobDetail((JobKey)iter.next());

Sample Code

      try
      { 
         Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
         List jobGroups = scheduler.getJobGroupNames();
         for (int i = 0; i < jobGroups.size(); i++)
         {
            String name = (String) jobGroups.get(i);
            Set keys = scheduler.getJobKeys(GroupMatcher.groupEquals(name));
            Iterator iter = keys.iterator();
            while (iter.hasNext())
            {
               JobDetail jobDetail = scheduler.getJobDetail((JobKey)iter.next());
               JobDataMap jobDataMap = jobDetail.getJobDataMap();
               // do something
            }
         }
      }
      catch (SchedulerException se)
      {
         se.printStackTrace();
      }

I specially like the addition of scheduler.getJobKeys(GroupMatcher.groupEquals(name));, where GroupMatcher can take some crude expressions like groupContains(String compareTo) and groupStartsWith(String compareTo).

Comments