1 package org.oddjob.monitor.action; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import org.apache.log4j.Logger; 7 import org.oddjob.designer.model.DesignDefinition; 8 import org.oddjob.framework.Transportable; 9 import org.oddjob.monitor.model.ExplorerContext; 10 import org.oddjob.monitor.model.JobAction; 11 import org.oddjob.monitor.model.JobMenu; 12 import org.oddjob.monitor.model.JobOption; 13 import org.oddjob.monitor.model.SchedulerTraker; 14 import org.oddjob.scheduling.OddjobScheduler; 15 16 21 22 public class SchedulerMenu extends JobMenu { 23 private static final Logger logger = Logger.getLogger(SchedulerMenu.class); 24 25 private boolean enabled; 26 27 private JobOption[] options; 28 29 32 public String getName() { 33 return "Schedule Job"; 34 } 35 36 public void select(Object component, ExplorerContext eContext) { 37 enabled = true; 38 SchedulerTraker st = eContext.getSchedulerTraker(); 39 OddjobScheduler[] schedulers = st.getSchedulers(); 40 List results = new ArrayList (); 41 for (int i = 0; i < schedulers.length; ++i) { 42 OddjobScheduler scheduler = schedulers[i]; 43 try { 44 if (scheduler instanceof Transportable 47 && ! (component instanceof Transportable)) { 48 continue; 49 } 50 if (!scheduler.canSchedule(component)) { 51 continue; 52 } 53 } catch (Exception e) { 54 logger.debug("Can't schedule on scheduler [" + scheduler + "]", e); 55 continue; 56 } 57 ScheduleMenu sm = new ScheduleMenu(scheduler); 58 sm.optionSelect(component, eContext); 59 results.add(sm); 60 } 61 if (results.size() == 0) { 62 options = new JobOption[1]; 63 options[0] = new NoSchedulers(); 64 } 65 else { 66 options = (ScheduleMenu[]) results.toArray(new ScheduleMenu[0]); 67 } 68 69 } 70 71 public void deSelect() { 72 enabled = false; 73 } 74 75 public boolean enabled() { 76 return enabled; 77 } 78 79 public JobOption[] options() { 80 return options; 81 } 82 83 class NoSchedulers extends JobAction { 84 public boolean enabled() { 85 return false; 86 } 87 public String getName() { 88 return "No Schedulers"; 89 } 90 public void select(Object component, ExplorerContext eContext) { 91 } 92 public void deSelect() { 93 } 94 public void action() throws Exception { 95 } 96 public DesignDefinition form() { 97 return null; 98 } 99 } 100 } 101 | Popular Tags |