package org.cloudbus.cloudsim.simulate;

import java.util.List;

import org.cloudbus.cloudsim.ResCloudlet;

public class EstimationCloudletObserve {
	private List<Integer> datacenterList;
	private ResCloudlet resCloudlet;
	private int datacenterIdOFCurrrentExecVm;
	
	public EstimationCloudletObserve(ResCloudlet resCloudlet, List<Integer> datacenterList) {
		this.datacenterList = datacenterList;
		this.resCloudlet = resCloudlet;
		this.setDatacenterIdOFCurrrentExecVm(-1);
	}
	
	public List<Integer> getDatacenterList() {
		return datacenterList;
	}
	
	public void setDatacenterList(List<Integer> datacenterList) {
		this.datacenterList = datacenterList;
	}
	
	public ResCloudlet getResCloudlet() {
		return resCloudlet;
	}
	
	public void setResCloudlet(ResCloudlet resCloudlet) {
		this.resCloudlet = resCloudlet;
	}
	//if resturn datacenterID that will be cancel exec;
	public int receiveEstimateResult(int datacenterID, ResCloudlet reResCloudlet,Boolean result) {
		int DatacenterCancelExec = datacenterID;
		int totalDatacenter = datacenterList.size();
		for (int i = 0; i < totalDatacenter; i++) {
			if (datacenterList.get(i) == datacenterID) {
				datacenterList.remove(i);
				break;
			}
		}
//		if(reResCloudlet.getCloudlet().getDeadline() >= reResCloudlet.getClouddletFinishTime()  ){
			double finishTime = reResCloudlet.getClouddletFinishTime();
			double bestFinishTime = resCloudlet.getClouddletFinishTime();
//			Log.printLine(finishTime);
//			Log.printLine(bestFinishTime);
//			Log.printLine("-----------------------------------------------------------------");
//			Log.printLine(resCloudlet.getClouddletFinishTime());
//			Log.printLine(DatacenterCancelExec);
			if (finishTime > 0 && finishTime < bestFinishTime) {
				DatacenterCancelExec = getDatacenterIdOFCurrrentExecVm();
				setNewVmToExce(datacenterID,finishTime,reResCloudlet);
			}
//		}
		return DatacenterCancelExec;
	}
	
	private void setNewVmToExce(int datacenterID,double finishTime, ResCloudlet reResCloudlet) {
		setDatacenterIdOFCurrrentExecVm(datacenterID);
		resCloudlet.setFinishTime(finishTime);
		resCloudlet.getCloudlet().setVmId(reResCloudlet.getCloudlet().getVmId()); 
	}

	public boolean isFinished() {
		return datacenterList.size() == 0;
	}

	public int getDatacenterIdOFCurrrentExecVm() {
		return datacenterIdOFCurrrentExecVm;
	}

	public void setDatacenterIdOFCurrrentExecVm(int datacenterIdOFCurrrentExecVm) {
		this.datacenterIdOFCurrrentExecVm = datacenterIdOFCurrrentExecVm;
	}
}

@@ -190,16 +190,22 @@
 private 
+Custom
 ResCloud
@@ -300,16 +300,22 @@
 Observe(
+Custom
 ResCloud
@@ -762,16 +762,22 @@
 loudlet(
+Custom
 ResCloud
@@ -937,16 +937,22 @@
 nterID, 
+Custom
 ResCloud

change rescloudlet to customrescloudlet