/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ruleengine;

import CommonFunctions.debugPrinter;
import mdot.Main;

/*class ruleEngineThread
 * Thread that on every tick checks the rules and updates the debug window.
 */
public class ruleEngineThread extends Thread {

    private RuleChecker rC;
    private int time = 0;
    private int manualRefresh = 0;

    public ruleEngineThread(RuleChecker rc, String s, String timeString) {

        super(s);
        rC = rc;
        if (timeString.equals("")) {
            time = 10000;
        } else {
            time = Integer.parseInt(timeString);
        }

    }

    @Override
    public void run() {

        while (true) {

            try {
                rC.CheckRules();

                try {

                    if (Main.DEBUG) {
                        if (Main.treeView != null) {
                            while (true) {
                                if (!Main.treeView.busy) {
                                    Main.treeView.UpdateTree();
                                    break;
                                } else {
                                    debugPrinter.printLine("busy update tree-rules");
                                }
                            }


                        }
                    }
                    sleep(time);
                    yield();

                } catch (InterruptedException ie) {
                    ie.printStackTrace();

                }
            } catch (Exception ie) {
                ie.printStackTrace();

            }
        }


    }
}


