1 16 package org.apache.cocoon.components.cron; 17 18 import java.text.SimpleDateFormat ; 19 import java.util.Date ; 20 21 import org.quartz.CronTrigger; 22 import org.quartz.JobDataMap; 23 import org.quartz.JobDetail; 24 import org.quartz.Scheduler; 25 import org.quartz.SchedulerException; 26 import org.quartz.SimpleTrigger; 27 import org.quartz.Trigger; 28 29 35 public class QuartzJobSchedulerEntry implements JobSchedulerEntry { 36 37 38 private final JobDataMap m_data; 39 40 41 private final JobDetail m_detail; 42 43 44 private final Scheduler m_scheduler; 45 46 47 private final SimpleDateFormat m_formatter = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss"); 48 49 50 private final String m_name; 51 52 53 private final Trigger m_trigger; 54 55 63 public QuartzJobSchedulerEntry(final String name, final Scheduler scheduler) 64 throws SchedulerException { 65 m_scheduler = scheduler; 66 m_name = name; 67 m_detail = m_scheduler.getJobDetail(name, QuartzJobScheduler.DEFAULT_QUARTZ_JOB_GROUP); 68 m_data = m_detail.getJobDataMap(); 69 m_trigger = m_scheduler.getTrigger(name, QuartzJobScheduler.DEFAULT_QUARTZ_JOB_GROUP); 70 } 71 72 75 public String getJobName() { 76 String name = (String )m_data.get(QuartzJobScheduler.DATA_MAP_ROLE); 77 78 if (null == name) { 79 name = m_data.get(QuartzJobScheduler.DATA_MAP_OBJECT).getClass().getName(); 80 } 81 82 return name; 83 } 84 85 88 public String getName() { 89 return m_name; 90 } 91 92 95 public Date getNextTime() { 96 return m_trigger.getNextFireTime(); 97 } 98 99 102 public boolean isRunning() { 103 Boolean runs = (Boolean )m_data.get(QuartzJobScheduler.DATA_MAP_KEY_ISRUNNING); 104 if (null != runs) { 105 return runs.booleanValue(); 106 } 107 108 return false; 109 } 110 111 114 public String getSchedule() { 115 if (m_trigger instanceof CronTrigger) { 116 return "cron: " + ((CronTrigger)m_trigger).getCronExpression(); 117 } else if (m_trigger instanceof SimpleTrigger) { 118 if (((SimpleTrigger)m_trigger).getRepeatInterval() == 0) { 119 return "once: at " + m_formatter.format(m_trigger.getFinalFireTime()); 120 } 121 122 return "periodic: every " + (((SimpleTrigger)m_trigger).getRepeatInterval() / 1000) + "s"; 123 } else { 124 return "next: " + m_formatter.format(m_trigger.getNextFireTime()); 125 } 126 } 127 } 128 | Popular Tags |