package codeOrchestra.colt.core.session.sourcetracking;

import java.io.File;
import java.util.List;

/**
 * @author Alexander Eliseyev
 */
public class SourcesTrackerThread extends Thread {

	private static final long SLEEP_INTERVAL = 50;

    private boolean shouldStop;

	private SourcesTracker sourcesTracker;

	private final SourcesTrackerCallback callback;
	
	public SourcesTrackerThread(SourcesTrackerCallback callback, List<File> sourceDirs) {
		super("Source files changes tracker thread");
		this.callback = callback;
		this.sourcesTracker = new SourcesTracker(sourceDirs);
	}
	
	public void stopRightThere() {
		shouldStop = true;
	}

	@Override
	public void run() {
		while (!shouldStop) {
			try {
				Thread.sleep(SLEEP_INTERVAL);
			} catch (InterruptedException e) {
				// do nothing
			}
            long t = System.currentTimeMillis();
			for (SourceFile changedFile : sourcesTracker.getChangedFiles()) {
                try {
                    if (changedFile != null) {
                        callback.sourceFileChanged(changedFile);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            System.out.println("SourcesTrackerThread run time = " + (System.currentTimeMillis() - t));
        }
	}
	
}

@@ -803,56 +803,8 @@
 %09%09%7D%0A
-            long t = System.currentTimeMillis();
 %0A%09%09%09
@@ -1142,110 +1142,8 @@
   %7D%0A
-            System.out.println(%22SourcesTrackerThread run time = %22 + (System.currentTimeMillis() - t));
 %0A   

remove log message