/* ************************************************************************
#
#  DivConq
#
#  http://divconq.com/
#
#  Copyright:
#    Copyright 2012 eTimeline, LLC. All rights reserved.
#
#  License:
#    See the license.txt file in the project's top-level directory for details.
#
#  Authors:
#    * Andy White
#
************************************************************************ */
package divconq.scheduler;

import divconq.work.IRunnable;
import divconq.work.ITaskInfo;
import divconq.work.TaskInfo;

public class SimpleSchedule implements ISchedule {
	protected ITaskInfo work = null;		
	protected boolean repeat = false;
	protected long nextrunat = 0;
	protected int every = 0;
	
	public SimpleSchedule(IRunnable run, long at, int repeatevery) {
		this.work = new TaskInfo(run);		
		this.nextrunat = at;
		
		if (repeatevery > 0) {
			this.repeat = true;
			this.every = repeatevery;
		}
	}
	
	public SimpleSchedule(ITaskInfo run, long at, int repeatevery) {
		this.work = run;
		this.nextrunat = at;
		
		if (repeatevery > 0) {
			this.repeat = true;
			this.every = repeatevery;
		}
	}
	
	@Override
	public boolean reschedule() {
		if (!this.repeat)
			return false;
		
		this.nextrunat += (this.every * 1000);
		return true;
	}

	@Override
	public long when() {
		return this.nextrunat;
	}

	@Override
	public ITaskInfo task() {
		return this.work;
	}

}
