package cz.vutbr.feec.burget.advanced;

import java.util.Vector;

import cz.vutbr.feec.simlib.Proc;
import cz.vutbr.feec.simlib.Simulation;

public class Main {
	final static double RFT_PERIOD = 5000.; 
	final static double FT_PERIOD = 5000.; 
	final static double R_PERIOD = 5000.;
	
	public static void main(String[] args) {

		Simulation sim = new Simulation();

		// mnozina vsech R
		Vector<Receiver> receivers = new Vector<Receiver>();
		Vector<Member> multicast = new Vector<Member>();
		
		// strom s 1x RFT, 10x FT, 10x10 R
		
		// Root feedback target
		FT rft = createRFT();
		sim.addProcess(rft, 0);
		
		for (int i = 0; i < 10; i++) {
			FT ft = createFT();
			rft.addChild(ft);
			sim.addProcess(ft, 0);
			multicast.add(ft);
			
			// pro kazdy FT pridam 10 r
//			for (int j = 0; j < 10; j++) {
//				Receiver r = new Receiver(R_PERIOD);
//				ft.addChild(r);
//				receivers.add(r);
//				multicast.add(r);
//				sim.addProcess(r, 0);
//				
//				r.setValue(1.);
//			}
		}
		AddReceivers addR = new AddReceivers(10, rft);
		sim.addProcess(addR, 50*5000);
		
		AddReceivers addR2 = new AddReceivers(10, rft);
		sim.addProcess(addR2, 70*5000);
		
		AddReceivers addR3 = new AddReceivers(10, rft);
		sim.addProcess(addR3, 90*5000);
		
		sim.start(5000 * 130);
	}

	private static FT createRFT() {
		FT rft = new FT(RFT_PERIOD);
		rft.addActionListener(new MemberActionListener() {
			@Override
			public void onFeedbackSent(Member m) {
				System.out.println(((FT)m).getReceivedMessages());
			}
		});
		return rft;
	}
	
	private static FT createFT() {
		FT rft = new FT(FT_PERIOD);
		return rft;
	}
}
