package com.mot.labs.ucsl.util;

public class Timer extends Thread {

	private TimerListener l = null;
	private long time = 0;
	private boolean repeat = false;
	private boolean running = false;
	private long id;
	
	public Timer(TimerListener l, long time, boolean repeat) {
		this.l = l;
		this.time = time;
		this.repeat = repeat;
		this.id = System.currentTimeMillis();
	}
	
	public long getID() {
		return id;
	}
	
	public void run() {
		running = true;
		while(running) {
			try {
				Thread.sleep(time);
			}
			catch(Exception e) {
				e.printStackTrace();
			}
			l.timerExpired(id);
			if (!repeat) {
				running = false;
			}
		}
	}
	
	public void stopTimer() {
		running = false;
	}
	
}
