package com.ericsson.uecontrol.core.logic;

import com.ericsson.uecontrol.core.UeBehaviour;
import com.ericsson.uecontrol.core.util.Configurator.Configurable;
import org.apache.log4j.Logger;

/**
 * Created by ezivkoc on 2015-01-19.
 */
public class UeBehaviourIterator extends UeBehaviour {
    private static final Logger log = Logger.getLogger(UeBehaviourIterator.class);

    @Configurable(order=1, value="Iterations")
    private int iterations = 5;


    private transient int iterationCount = 0;


    @Override
    protected void execute() throws Exception {
        iterationCount++;
        if(iterationCount < iterations){
            log.debug("Iteration: "+ iterationCount);
            super.getExecutor().setNextBehaviour(0);
            Thread.sleep(VISUAL_SLEEP_PERIOD); // Sleep as a visual queue
        }
        else{
            log.debug("Iteration done, skipping");
        }
    }

    @Override
    public void reset() {
        iterationCount = 0;
        super.reset();
    }


    @Override
    public String getName() {
        return "Iterator";
    }

    @Override
    public String toString() {
        return "Will iterate " +iterations+ " times";
    }
}
