1 4 package org.oddjob.jobs.job; 5 6 import org.oddjob.Stateful; 7 import org.oddjob.framework.BasePrimary; 8 import org.oddjob.images.IconHelper; 9 import org.oddjob.state.JobState; 10 import org.oddjob.state.JobStateEvent; 11 import org.oddjob.state.JobStateListener; 12 import org.oddjob.util.OddjobConfigException; 13 14 50 public class TriggerJob extends BasePrimary 51 implements Stateful, JobStateListener, Runnable { 52 private static final long serialVersionUID = 20051206; 53 54 59 private String state; 60 61 62 private JobState jobState; 63 64 69 private Stateful on; 70 71 public boolean isTransient() { 72 return true; 73 } 74 75 public boolean independant() { 76 return true; 77 } 78 79 public void run() { 80 if (!configure()) { 81 return; 82 } 83 84 if (jobState == null) { 85 if (state == null) { 86 jobState = JobState.COMPLETE; 87 logger().debug("Defaulting to complete."); 88 } 89 else { 90 jobState = JobState.stateFor(state); 91 } 92 } 93 if (jobState == null) { 94 throw new OddjobConfigException("State is invalid."); 95 } 96 on.addJobStateListener(this); 97 } 98 99 102 public void jobStateChange(JobStateEvent event) { 103 if (event.getJobState() == jobState) { 106 stateHandler.fireEvent( 107 new JobStateEvent(this, JobState.COMPLETE, 108 event.getTime(), event.getException())); 109 logger().debug("[" + this.toString() + "] firing, event [" + event + "]"); 110 iconHelper.changeIcon(IconHelper.COMPLETE); 111 } 112 else { 113 stateHandler.fireEvent(new JobStateEvent(this, 114 JobState.READY, event.getTime(), null)); 115 iconHelper.changeIcon(IconHelper.READY); 116 } 117 } 118 119 public Stateful getOn() { 120 return on; 121 } 122 123 public void setOn(Stateful on) { 124 this.on = on; 125 } 126 127 public String getState() { 128 return state; 129 } 130 public void setState(String state) { 131 this.state = state; 132 } 133 134 public void onDestroy() { 135 on.removeJobStateListener(this); 136 } 137 } 138 | Popular Tags |