KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > monitor > action > SchedulerMenu


1 package org.oddjob.monitor.action;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
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 /**
17  * Creates a menu of available schedulers.
18  *
19  * @author Rob Gordon
20  */

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     /**
30      * Get the name of the action.
31      */

32     public String JavaDoc getName() {
33         return "Schedule Job";
34     }
35
36     public void select(Object JavaDoc component, ExplorerContext eContext) {
37         enabled = true;
38         SchedulerTraker st = eContext.getSchedulerTraker();
39         OddjobScheduler[] schedulers = st.getSchedulers();
40         List JavaDoc results = new ArrayList JavaDoc();
41         for (int i = 0; i < schedulers.length; ++i) {
42             OddjobScheduler scheduler = schedulers[i];
43             try {
44                 // if job isn't a proxy, then don't attempt to send
45
// accross network
46
if (scheduler instanceof Transportable
47                         && ! (component instanceof Transportable)) {
48                     continue;
49                 }
50                 if (!scheduler.canSchedule(component)) {
51                     continue;
52                 }
53             } catch (Exception JavaDoc 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 JavaDoc getName() {
88             return "No Schedulers";
89         }
90         public void select(Object JavaDoc component, ExplorerContext eContext) {
91         }
92         public void deSelect() {
93         }
94         public void action() throws Exception JavaDoc {
95         }
96         public DesignDefinition form() {
97             return null;
98         }
99     }
100 }
101
Popular Tags