package com.ericsson.uecontrol.core.behaviour;

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

/**
 * This behaviour simulates an idle period for the device.
 *
 * Created by ezivkoc on 2014-07-15.
 */
public class UeBehaviourSleep extends UeBehaviour{
    private static final Logger log = Logger.getLogger(UeBehaviourSleep.class);
    public static final int SLEEP_PERIOD = 100;

    @Configurable("Sleep(millisec)")
    private int time;

    public UeBehaviourSleep(){
        this(2000);
    }
    public UeBehaviourSleep(int milliseconds){
        time = milliseconds;
    }

    @Override
    protected void execute() throws InterruptedException {
        log.debug(toString());
        int elapsedTime = 0;
        while(elapsedTime < time){
            super.setProgress((float)elapsedTime/time);
            if(super.stopExecution()) break;
            Thread.sleep(SLEEP_PERIOD);
            elapsedTime += SLEEP_PERIOD;
        }
    }

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

    @Override
    public String toString() {
        return "Will sleep for "+(time/1000)+" seconds";
    }
}
