1 4 package org.oddjob.monitor.model; 5 6 import java.util.ArrayList ; 7 import java.util.List ; 8 9 import org.apache.log4j.Logger; 10 import org.oddjob.framework.Transportable; 11 import org.oddjob.scheduling.OddjobScheduler; 12 import org.oddjob.scheduling.ScheduleSummary; 13 14 20 public class SchedulerTraker { 21 private static final Logger logger = Logger.getLogger(SchedulerTraker.class); 22 23 24 private List schedulers = new ArrayList (); 25 26 31 synchronized public void addScheduler(OddjobScheduler scheduler) { 32 schedulers.add(scheduler); 33 } 34 35 40 synchronized public void removeSchedule(OddjobScheduler scheduler) { 41 schedulers.remove(scheduler); 42 } 43 44 51 public JobSchedulerSummary[] getSchedulerSummaries(Object component) { 52 List results = new ArrayList (); 53 OddjobScheduler[] sa = getSchedulers(); 54 for (int i = 0; i < sa.length; ++i) { 55 ScheduleSummary[] summaries = null; 56 try { 57 OddjobScheduler scheduler = sa[i]; 58 if (scheduler instanceof Transportable 61 && ! (component instanceof Transportable)) { 62 continue; 63 } 64 summaries = scheduler.summariesFor(component); 65 if (summaries == null) { 66 throw new IllegalStateException ("An OddjobScheduler should never provide null summaries."); 67 } 68 } catch (Exception e) { 69 logger.warn("Failed to retrieve scheduler summaries.", e); 71 continue; 72 } 73 for (int j = 0; j < summaries.length; ++j) { 74 results.add(new JobSchedulerSummary(sa[i], summaries[j])); 75 } 76 } 77 return (JobSchedulerSummary[]) results.toArray(new JobSchedulerSummary[0]); 78 } 79 80 85 synchronized public OddjobScheduler[] getSchedulers() { 86 return (OddjobScheduler[]) schedulers.toArray(new OddjobScheduler[0]); 87 } 88 } 89 | Popular Tags |