package org.bench4q.master.domain.valueobject.schedulscript;

import java.util.TimerTask;

import org.bench4q.master.domain.RunningScriptInterface;
import org.bench4q.master.domain.service.TestPlanEngine;
import org.bench4q.master.helper.ApplicationContextHelper;

/**
 * 
 * @author coderfengyun
 * 
 * @description This Task will do two things: one is to remove the runningAgent
 *              from testPlanContext, and the other is to remove the
 *              runningAgentFrom HA Blotters
 */
public class ExecutionOverTask extends TimerTask {
	private RunningScriptInterface runningScript;
	private TaskCompleteCallback taskCompleteCallback;

	public RunningScriptInterface getRunningScript() {
		return runningScript;
	}

	public void setRunningScriptModel(RunningScriptInterface runningScript) {
		this.runningScript = runningScript;
	}

	private TaskCompleteCallback getTaskCompleteCallback() {
		return taskCompleteCallback;
	}

	private void setTaskCompleteCallback(
			TaskCompleteCallback taskCompleteCallback) {
		this.taskCompleteCallback = taskCompleteCallback;
	}

	public ExecutionOverTask(RunningScriptInterface runningScript) {
		this.setRunningScriptModel(runningScript);
		this.setTaskCompleteCallback(ApplicationContextHelper.getContext()
				.getBean(TestPlanEngine.class));
	}

	@Override
	public void run() {
		this.getRunningScript().stop();
		this.getTaskCompleteCallback().doTaskComplete(
				this.getRunningScript().getTestPlanID());
		System.out.println("execute ExecutionOverTask");
	}
}
