package ld5_2;
import jade.core.Agent;
import jade.core.behaviours.SimpleBehaviour;
import jade.core.behaviours.TickerBehaviour;

public class Sleeper extends Agent {
    private void print(String data, String elgesenosId) {
        if (elgesenosId != null) {
            System.out.println("A[" + getLocalName() + " | " + elgesenosId + "] " + data);
        } else {
            System.out.println("A[" + getLocalName() + "] " + data);
        }
    }



    @Override 
    public void setup() {
        addBehaviour(new MyTicker(this, 1000));
        addBehaviour(new Miegas());
    }
    
    private class MyTicker extends TickerBehaviour {
        public MyTicker(Agent a, long period) {
            super(a, period);
        }

        @Override
        protected void onTick() {
            print("kažkokį tekstą", "Tickeris");
        }
    }

    private class Miegas extends SimpleBehaviour
    {
        int i = 1;
        @Override
        public void action()
        {
            print(String.format("%d | 10", i), "Miegas");
            i++;
            block(1000); //Tipo sleep nera, bet kadangi sako veikti lygegreciai tai ans turetu but block(1000); o ne Thread.sleep(1000);
        }
        @Override
        public boolean done() {
            if (i >= 10){
                print("Baigta", "Miegas");
                return true;
            }
            return false;
        }
    }

    @Override  
    public void takeDown() 
    {     
    } 
}