1 package org.oddjob.state; 2 3 import java.util.Date ; 4 5 import org.oddjob.Stateful; 6 7 8 13 14 abstract public class AbstractJobStateListener implements JobStateListener { 15 16 22 public final void jobStateChange(JobStateEvent event) { 23 JobState state = event.getJobState(); 24 Stateful source = (Stateful)event.getSource(); 25 Date time = event.getTime(); 26 Throwable throwable = event.getException(); 27 if (state == JobState.READY) { 28 jobStateReady(source, time); 29 } 30 else if (state == JobState.EXECUTING) { 31 jobStateExecuting(source, time); 32 } 33 else if (state == JobState.COMPLETE) { 34 jobStateComplete(source, time); 35 hasFinishedRunning(event); 36 } 37 else if (state == JobState.NOT_COMPLETE) { 38 jobStateNotComplete(source, time); 39 hasFinishedRunning(event); 40 } 41 else if (state == JobState.EXCEPTION) { 42 jobStateException(source, time, throwable); 43 hasFinishedRunning(event); 44 } 45 else { 46 throw new IllegalStateException ("Unknown state! - this should never happen."); 47 } 48 } 49 50 protected void jobStateReady(Stateful source, Date time) { 51 } 52 53 protected void jobStateExecuting(Stateful source, Date time) { 54 } 55 56 protected void jobStateComplete(Stateful source, Date time) { 57 } 58 59 protected void jobStateNotComplete(Stateful source, Date time) { 60 } 61 62 protected void jobStateException(Stateful source, Date time, Throwable throwable) { 63 } 64 65 protected void hasFinishedRunning(JobStateEvent e) { 66 } 67 } 68 | Popular Tags |