import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;



public class ClientTimerTask extends TimerTask{
	long lasttimeonac = 0;
	public void run()
	{
		try
		{
			FileReader f = new FileReader("onAC.txt");
			BufferedReader fr = new BufferedReader(f);
			String line = fr.readLine();
			
			int onAC = new Integer(line).intValue();
			fr.close();
			
			WindowsSystemParameters sysparams = new WindowsSystemParameters();
			
			List params = sysparams.Scheduler();
			
			int nowonAC =  new Integer(String.valueOf(params.get(5))).intValue();
			long thistimeonac = 0;
			if(nowonAC == 1 && onAC == 0)
			{
				// bring up the pop up
				thistimeonac = new Long(String.valueOf(params.get(1))).longValue();
				System.out.println("Inside if");
				
				if(thistimeonac - lasttimeonac >= 300000)
				{
					Runtime rtime = Runtime.getRuntime();
					String file = PropertyFileValues.destination_dir+"/"+"Logger_"+ String.valueOf(params.get(0)).substring(0, 10);
					// change to absolute path of OptionFrame.jar
					String[] commands={"java","-jar","OptionFrame.jar",file};
					rtime.exec(commands);
					lasttimeonac = thistimeonac;
				}
			}
			
			FileWriter fw = new FileWriter(new File("onAC.txt"));
			
			fw.write(""+nowonAC);
			
			fw.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
	}
	
}
