Data Store

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
import com.topcoder.util.scheduler.scheduling.Job;
import com.topcoder.util.scheduler.scheduling.ScheduledJobRunner;
import com.topcoder.util.scheduler.scheduling.ScheduledEnable;
import com.topcoder.util.file.fieldconfig.NodeList;

// The CustomJobRunner will be instantiated by the Job Scheduling component to run.
// Its run method will be called.
// This class must be thread-safe.
public class CustomJobRunner implements ScheduledJobRunner {
    private boolean running = false;
    private Boolean success = null;
    private Job job = null;

    public CustomJobRunner() {}

    public boolean isDone() {
        synchronized (this) {
            return this.success != null;
        }
    }

    public void close() {
    }

    public String getStatus() {
	synchronized (this) {
	     if (success == null) {
		   return running ? ScheduledEnable.RUNNING : ScheduledEnable.NOT_STARTED;
	     } else {
		   return success.booleanValue() ? ScheduledEnable.SUCCESSFUL : ScheduledEnable.FAILED
	    }
	}
    }

    public NodeList getMessageData() {
        return null;
    }

    public String getRunningStatus() {
        return getStatus();
    }

    public void setJob(Job job) {
        this.job = job;
    }

    public Job getJob() {
        return this.job;
    }

    public void run() {	
	synchronized (this) {
	     running = true;
	}
	try {
	   // TODO: .. do the business logic

	   synchronized (this ) {
		 running = false;
		 success = Boolean.TRUE;
	    }
	} catch (Exception ex) {
	   synchronized (this ) {
		  running = false;
		  success = Boolean.FALSE;
	   }
	}

    }
}

 

Job Scheduling Component

posted on 2010-01-03 23:38  standlove  阅读(212)  评论(0)    收藏  举报