Index: /DCWoRMS/branches/coolemall/src/dcworms/schedframe/scheduling/Executable.java
===================================================================
--- /DCWoRMS/branches/coolemall/src/dcworms/schedframe/scheduling/Executable.java	(revision 885)
+++ /DCWoRMS/branches/coolemall/src/dcworms/schedframe/scheduling/Executable.java	(revision 896)
@@ -25,4 +25,5 @@
 import schedframe.scheduling.tasks.AbstractProcessesGroup;
 import schedframe.scheduling.tasks.Task;
+import schedframe.scheduling.tasks.phases.ResourceConsumption;
 import schedframe.scheduling.tasks.phases.ResourceConsumptionProfile;
 import schedframe.scheduling.tasks.requirements.ResourceParameterName;
@@ -39,5 +40,4 @@
 	
 	protected int status; 
-	protected double length;
 	protected Map<ResourceParameterName, Object> specificResources;
 	
@@ -158,5 +158,5 @@
         }
 
-        if (newStatus < DCWormsTags.CREATED || newStatus > DCWormsTags.FAILED_RESOURCE_UNAVAILABLE) {
+        if (newStatus < DCWormsTags.CREATED || newStatus > DCWormsTags.NEW_EXEC_PHASE) {
             throw new Exception("Executable.setStatuts() : Error - " +
                     "Invalid integer range for Execiutable status.");
@@ -204,4 +204,20 @@
     		}
         }
+        
+        if(status == DCWormsTags.NEW_EXEC_PHASE){
+        	if(prevStatus == DCWormsTags.INEXEC){
+        		status = DCWormsTags.INEXEC;
+        		setCompletionPercentage(0);
+        		task.getResourceConsumptionProfile().setCurrentPhase(task.getResourceConsumptionProfile().getCurrentPhase() + 1);
+        		
+        		DateTime currentDateTime = new DateTime();
+        		
+        		if(getUsedResources().getLast().getTimeStamp().getMillis() == currentDateTime.getMillis()){
+        			return;
+        		}
+    			ResourceHistoryItem resHistItem = new ResourceHistoryItem(getUsedResources().getLast().getResourceUnits(), currentDateTime);
+    			addUsedResources(resHistItem);
+        	}
+        }
 	}
 	
@@ -209,5 +225,4 @@
 		if(this.specificResources == null)
 			this.specificResources = new HashMap<ResourceParameterName, Object>();
-		
 		this.specificResources.put(resourceName, value);
 	}
@@ -216,5 +231,4 @@
 		if(this.specificResources == null)
 			return false;
-
 		return this.specificResources.containsKey(resourceName);
 	}
@@ -255,11 +269,9 @@
 	}
 	
-    public void setSchedulerName(int resourceId)
-    {
+    public void setSchedulerName(int resourceId){
         this.schedName = GridSim.getEntityName(resourceId);
     }
 
-    public String getSchedulerName()
-    {
+    public String getSchedulerName(){
         return schedName;
     }
@@ -368,12 +380,6 @@
 	}
 
-	private int currentPhase = 0;
-
-	public int getCurrentPhase() {
-		return currentPhase;
-	}
-
-	public void setCurrentPhase(int currentPhase) {
-		this.currentPhase = currentPhase;
+	public ResourceConsumption getCurrentResourceConsumption(){
+		return task.getResourceConsumptionProfile().getCurrentResourceConsumption();
 	}
 	
Index: /DCWoRMS/branches/coolemall/src/gridsim/dcworms/DCWormsTags.java
===================================================================
--- /DCWoRMS/branches/coolemall/src/gridsim/dcworms/DCWormsTags.java	(revision 808)
+++ /DCWoRMS/branches/coolemall/src/gridsim/dcworms/DCWormsTags.java	(revision 896)
@@ -14,5 +14,5 @@
 	public static final int TO_SCHEDULERS = DCWORMSBASE - 3;
 	
-	public static final int PHASE_CHANGED = DCWORMSBASE - 2;
+	public static final int TASK_EXECUTION_CHANGED = DCWORMSBASE - 2;
 	
 	public static final int UPDATE_PROCESSING = DCWORMSBASE - 1;
@@ -55,5 +55,5 @@
     public static final int RESUMED = 9;
 
-    public static final int FAILED_RESOURCE_UNAVAILABLE = 10;
+    public static final int NEW_EXEC_PHASE = 10;
 
 }
Index: /DCWoRMS/branches/coolemall/src/test/PhaseTimeEstimationPlugin.java
===================================================================
--- /DCWoRMS/branches/coolemall/src/test/PhaseTimeEstimationPlugin.java	(revision 883)
+++ /DCWoRMS/branches/coolemall/src/test/PhaseTimeEstimationPlugin.java	(revision 896)
@@ -8,4 +8,5 @@
 import schedframe.resources.units.ResourceUnitName;
 import schedframe.resources.units.StandardResourceUnitName;
+import schedframe.scheduling.tasks.phases.ResourceConsumption;
 import dcworms.schedframe.scheduling.ExecTask;
 import dcworms.schedframe.scheduling.Executable;
@@ -27,7 +28,6 @@
 			double completionPercentage) {
 
-		
 		Executable exec = (Executable) task;
-	//	System.out.println(exec.getJobId() +":"+ exec.getApplicationName());
+		// System.out.println(exec.getJobId() +":"+ exec.getApplicationName());
 		// collect all information necessary to do the calculation
 		PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE);
@@ -40,8 +40,8 @@
 
 		// estimate remainingTaskLength
-		double remainingLength =  task.getLength() * (1 - completionPercentage/100);
-		
+		ResourceConsumption resConsumption = exec.getResourceConsumptionProfile().getCurrentResourceConsumption();
+
 		// do the calculation
-		double execTime = (remainingLength / (cnt * speed));
+		double execTime = (1 - completionPercentage/100) * resConsumption.getDuration();
 
 		// if the result is very close to 0, but less then one millisecond then round this result to 0.001
Index: /DCWoRMS/branches/coolemall/src/schedframe/events/scheduling/SchedulingEventType.java
===================================================================
--- /DCWoRMS/branches/coolemall/src/schedframe/events/scheduling/SchedulingEventType.java	(revision 477)
+++ /DCWoRMS/branches/coolemall/src/schedframe/events/scheduling/SchedulingEventType.java	(revision 896)
@@ -20,5 +20,5 @@
 
 	//time related
-	TIMER(254),
+	TIMER(256),
 	
 	//resource related
@@ -33,5 +33,5 @@
 	RESERVATION_EXPIRED(16384),
 	
-	RESOURCE_STATE_CHANGED(32668)
+	RESOURCE_STATE_CHANGED(32768)
 	;
 	
Index: /DCWoRMS/branches/coolemall/src/schedframe/scheduling/tasks/Task.java
===================================================================
--- /DCWoRMS/branches/coolemall/src/schedframe/scheduling/tasks/Task.java	(revision 887)
+++ /DCWoRMS/branches/coolemall/src/schedframe/scheduling/tasks/Task.java	(revision 896)
@@ -4,4 +4,5 @@
 import java.io.StringWriter;
 import java.util.ArrayList;
+import java.util.LinkedList;
 import java.util.List;
 
@@ -96,5 +97,5 @@
 
 	private void preparePhases() {
-		List<ResourceConsumption> resourceConsumptionList = new ArrayList<ResourceConsumption>();
+		LinkedList<ResourceConsumption> resourceConsumptionList = new LinkedList<ResourceConsumption>();
 		
 		if(task.getExecution() == null || task.getExecution().getResourceConsumptionProfile() == null){
Index: /DCWoRMS/branches/coolemall/src/schedframe/scheduling/tasks/phases/ResourceConsumption.java
===================================================================
--- /DCWoRMS/branches/coolemall/src/schedframe/scheduling/tasks/phases/ResourceConsumption.java	(revision 883)
+++ /DCWoRMS/branches/coolemall/src/schedframe/scheduling/tasks/phases/ResourceConsumption.java	(revision 896)
@@ -51,14 +51,6 @@
 	}
 
-	public void setReferenceHardware(String referenceHardware) {
-		this.referenceHardware = referenceHardware;
-	}
-
 	public long getDuration() {
 		return duration;
-	}
-
-	public void setDuration(long duration) {
-		this.duration = duration;
 	}
 
@@ -67,6 +59,3 @@
 	}
 
-	public void setBehaviourList(List<PhaseBehaviour> behaviourList) {
-		this.phaseBehaviourList = behaviourList;
-	}
 }
Index: /DCWoRMS/branches/coolemall/src/schedframe/scheduling/tasks/phases/ResourceConsumptionProfile.java
===================================================================
--- /DCWoRMS/branches/coolemall/src/schedframe/scheduling/tasks/phases/ResourceConsumptionProfile.java	(revision 883)
+++ /DCWoRMS/branches/coolemall/src/schedframe/scheduling/tasks/phases/ResourceConsumptionProfile.java	(revision 896)
@@ -1,17 +1,39 @@
 package schedframe.scheduling.tasks.phases;
 
-import java.util.ArrayList;
+import java.util.LinkedList;
 import java.util.List;
 
 public class ResourceConsumptionProfile {
 	
-	protected List<ResourceConsumption> resourceConsumptionList;
+	protected LinkedList<ResourceConsumption> resourceConsumptionList;
+	protected int currentPhase;
 	
 	public ResourceConsumptionProfile() {
-		this.resourceConsumptionList = new ArrayList<ResourceConsumption>();
+		this.resourceConsumptionList = new LinkedList<ResourceConsumption>();
+		this.currentPhase = -1;
 	}
 	
-	public ResourceConsumptionProfile(List<ResourceConsumption> resourceConsumptionList) {
+	public ResourceConsumptionProfile(LinkedList<ResourceConsumption> resourceConsumptionList) {
 		this.resourceConsumptionList = resourceConsumptionList;
+		this.currentPhase = -1;
+	}
+	
+	public LinkedList<ResourceConsumption> getResourceConsumptionList(){
+		return resourceConsumptionList;
+	}
+	
+	public ResourceConsumption getCurrentResourceConsumption(){
+		if(currentPhase < resourceConsumptionList.size())
+			return resourceConsumptionList.get(currentPhase);
+		else 
+			return null;
+	}
+
+	public int getCurrentPhase() {
+		return currentPhase;
+	}
+
+	public void setCurrentPhase(int currentPhase) {
+		this.currentPhase = currentPhase;
 	}
 }
Index: /DCWoRMS/branches/coolemall/src/schedframe/scheduling/policy/local/LocalManagementSystem.java
===================================================================
--- /DCWoRMS/branches/coolemall/src/schedframe/scheduling/policy/local/LocalManagementSystem.java	(revision 822)
+++ /DCWoRMS/branches/coolemall/src/schedframe/scheduling/policy/local/LocalManagementSystem.java	(revision 896)
@@ -164,7 +164,7 @@
 			break;
 			
-		case DCWormsTags.PHASE_CHANGED:
+		case DCWormsTags.TASK_EXECUTION_CHANGED:
 			execTask = (ExecTask) ev.get_data();
-			//updatePhases(execTask);
+			updateTaskExecution(execTask, SchedulingEventType.RESOURCE_STATE_CHANGED);
 			break;
 		}
@@ -224,17 +224,14 @@
 		removeFromQueue(task);
 
-		SchedulingEvent event = new SchedulingEvent(SchedulingEventType.START_TASK_EXECUTION);
-		int time = Double.valueOf(
-				execTimeEstimationPlugin.execTimeEstimation(event, task, choosenResources, exec.getCompletionPercentage())).intValue();
-		log.debug(task.getJobId() + "_" + task.getId() + " starts executing on " + new DateTime()
-				+ " will finish after " + time);
-
-		if (time < 0.0)
-			return;
-
-		exec.setEstimatedDuration(time);
+		log.debug(task.getJobId() + "_" + task.getId() + " starts executing on " + new DateTime());
+
+		//if (phaseDuration < 0.0)
+		//	return;
+
+		//exec.setEstimatedDuration(exec.getEstimatedDuration() + phaseDuration);
 		DateTime currentTime = new DateTime();
 		ResourceHistoryItem resHistItem = new ResourceHistoryItem(choosenResources, currentTime);
 		exec.addUsedResources(resHistItem);
+		
 		try {
 			exec.setStatus(DCWormsTags.INEXEC);
@@ -244,6 +241,6 @@
 		}
 		
-		//updatePhases(exec);
-		scheduler.sendInternal(time, DCWormsTags.TASK_EXECUTION_FINISHED, exec);
+		updateTaskExecution(exec, SchedulingEventType.START_TASK_EXECUTION);
+		//scheduler.sendInternal(time, DCWormsTags.TASK_EXECUTION_FINISHED, exec);
 
 		try {
@@ -251,6 +248,6 @@
 			scheduler.sendInternal(expectedDuration, DCWormsTags.TASK_REQUESTED_TIME_EXPIRED, exec);
 		} catch (NoSuchFieldException e) {
-			double t = exec.getEstimatedDuration();
-			scheduler.sendInternal(t, DCWormsTags.TASK_REQUESTED_TIME_EXPIRED, exec);
+			//double t = exec.getEstimatedDuration();
+			//scheduler.sendInternal(t, DCWormsTags.TASK_REQUESTED_TIME_EXPIRED, exec);
 		}
 
@@ -261,25 +258,4 @@
 		notifyComputingResources(peUnit, EnergyEventType.TASK_STARTED, exec);
 		
-		/*if(peUnit instanceof ProcessingElements){
-			ProcessingElements pes = (ProcessingElements) peUnit;
-			for (ComputingResource resource : pes) {
-				resource.handleEvent(new EnergyEvent(EnergyEventType.TASK_STARTED, exec));
-			}
-		} else {
-			ComputingResource resource = null;
-			try {
-				resource = ResourceController.getComputingResourceByName(peUnit.getResourceId());
-			} catch (ResourceException e) {
-				return;
-			}
-			resource.handleEvent(new EnergyEvent(EnergyEventType.TASK_STARTED, exec));
-		}
-*/
-
-		/*for(ExecTaskInterface etask : jobRegistry.getRunningTasks()){
-			System.out.println(etask.getJobId());
-			for(String taskId: etask.getVisitedResources())
-				System.out.println("====="+taskId);
-		}*/
 	}
 	
@@ -323,20 +299,4 @@
 		PEUnit peUnit = (PEUnit)lastUsed.get(StandardResourceUnitName.PE);
 		notifyComputingResources(peUnit, EnergyEventType.TASK_FINISHED, exec);
-		/*if(peUnit instanceof ProcessingElements){
-			ProcessingElements pes = (ProcessingElements) peUnit;
-			for (ComputingResource resource : pes) {
-				resource.handleEvent(new EnergyEvent(EnergyEventType.TASK_FINISHED, exec));
-			}
-		} else {
-			ComputingResource resource = null;
-			try {
-				resource = ResourceController.getComputingResourceByName(peUnit.getResourceId());
-			} catch (ResourceException e) {
-				return;
-			}
-			resource.handleEvent(new EnergyEvent(EnergyEventType.TASK_FINISHED, exec));
-		}*/
-
-		//sendFinishedWorkloadUnit(executable);
 	}
 	
@@ -353,6 +313,5 @@
 			Executable exec = (Executable)task;
 			//exec.setCompletionPercentage(exec.getCompletionPercentage() + 100 * timeSpan/exec.getEstimatedDuration());
-			exec.setCompletionPercentage(exec.getCompletionPercentage() + (100 - exec.getCompletionPercentage()) * timeSpan/(exec.getEstimatedDuration() - new DateTime().getMillis()/1000 + exec.getExecStartTime() + timeSpan));
-			
+			exec.setCompletionPercentage(exec.getCompletionPercentage() + 100 * (timeSpan / exec.getEstimatedDuration()));
 			UsedResourcesList usedResourcesList = exec.getUsedResources();
 			PEUnit peUnit = (PEUnit)usedResourcesList.getLast().getResourceUnits()
@@ -364,5 +323,4 @@
 	
 	private void notifyComputingResources(PEUnit peUnit, EnergyEventType eventType, Object obj){
-
 		if(peUnit instanceof ProcessingElements){
 			ProcessingElements pes = (ProcessingElements) peUnit;
@@ -409,55 +367,59 @@
 		for (ExecTask execTask : jobRegistry.getRunningTasks()) {
 			Executable exec = (Executable)execTask;
-			List<String> visitedResource = exec.getVisitedResources();
-			String originResource = ev.get_data().toString();
-			if(!ArrayUtils.contains(visitedResource.toArray(new String[visitedResource.size()]), originResource)){
-				continue;
-			}
-			
+
 			Map<ResourceUnitName, ResourceUnit> choosenResources = exec.getUsedResources().getLast().getResourceUnits();
-			int time = Double.valueOf(execTimeEstimationPlugin.execTimeEstimation(new SchedulingEvent(SchedulingEventType.RESOURCE_STATE_CHANGED), 
+			double lastTimeStamp = exec.getUsedResources().getLast().getTimeStamp().getMillis()/1000;
+			int phaseDuration = Double.valueOf(execTimeEstimationPlugin.execTimeEstimation(new SchedulingEvent(SchedulingEventType.RESOURCE_STATE_CHANGED), 
 					execTask, choosenResources, exec.getCompletionPercentage())).intValue();
 
-			//check if the new estimated end time is equal to the previous one; if yes the continue without update
-			if(DoubleMath.subtract((exec.getExecStartTime() + exec.getEstimatedDuration()), (new DateTime().getMillis()/1000 + time)) == 0.0){
-				continue;
-			}
-			//exec.setEstimatedDuration(time);
-			exec.setEstimatedDuration(Long.valueOf(new DateTime().getMillis()/1000).intValue() - Double.valueOf(exec.getExecStartTime()).intValue() + time);
-			ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), DCWormsTags.TASK_EXECUTION_FINISHED);
-			scheduler.sim_cancel(filter, null);
-			scheduler.sendInternal(time, DCWormsTags.TASK_EXECUTION_FINISHED, execTask);
+			if(DoubleMath.subtract((lastTimeStamp + exec.getEstimatedDuration()), (new DateTime().getMillis()/1000 + phaseDuration)) == 0.0){
+				return;
+			}
+
+			exec.setEstimatedDuration(phaseDuration);
+			DateTime currentTime = new DateTime();
+			ResourceHistoryItem resHistItem = new ResourceHistoryItem(choosenResources, currentTime);
+			exec.addUsedResources(resHistItem);
+			
+			if(exec.getResourceConsumptionProfile().getCurrentResourceConsumption() == exec.getResourceConsumptionProfile().getResourceConsumptionList().getLast()){
+				ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), DCWormsTags.TASK_EXECUTION_FINISHED);
+				scheduler.sim_cancel(filter, null);
+				scheduler.sendInternal(phaseDuration , DCWormsTags.TASK_EXECUTION_FINISHED, execTask);
+				PEUnit peUnit = (PEUnit)exec.getUsedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE);
+				notifyComputingResources(peUnit, EnergyEventType.RESOURCE_UTILIZATION_CHANGED, exec);
+			} else{
+				ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), DCWormsTags.TASK_EXECUTION_CHANGED);
+				scheduler.sim_cancel(filter, null);
+				scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_CHANGED, execTask);
+				PEUnit peUnit = (PEUnit)exec.getUsedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE);
+				notifyComputingResources(peUnit, EnergyEventType.RESOURCE_UTILIZATION_CHANGED, exec);
+			}
 		}
 	}	
-	
-	
-	/*protected void updatePhases(ExecTask execTask) {
-		updateProcessingProgress();
+
+	protected void updateTaskExecution(ExecTask execTask, SchedulingEventType schedEvType) {
 
 		if (execTask.getStatus() == DCWormsTags.INEXEC) {
 			Executable exec = (Executable)execTask;
-
-			double phaseLength = 0;
-			try{
-				phaseLength = exec.getResourceConsumptionProfile().getResourceConsumption(exec.getCurrentPhase()).getResourceConsumptionTypeChoice().getPercentage()/100;
-			} catch(Exception e){
-				ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), DCWormsTags.TASK_EXECUTION_FINISHED);
-				scheduler.sim_cancel(filter, null);
-				double t = DoubleMath.subtract((exec.getExecStartTime() + exec.getEstimatedDuration()), (new DateTime().getMillis()/1000));
-				scheduler.sendInternal(t, DCWormsTags.TASK_EXECUTION_FINISHED, execTask);
-				PEUnit peUnit = (PEUnit)exec.getUsedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE);
-				notifyComputingResources(peUnit, EnergyEventType.RESOURCE_UTILIZATION_CHANGED, exec);
-			}
-			if(phaseLength != 0){			
-				exec.setCurrentPhase(exec.getCurrentPhase() + 1);
-				ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), DCWormsTags.PHASE_CHANGED);
-				scheduler.sim_cancel(filter, null);
-				scheduler.sendInternal(phaseLength * exec.getEstimatedDuration(), DCWormsTags.PHASE_CHANGED, execTask);
-				PEUnit peUnit = (PEUnit)exec.getUsedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE);
-				notifyComputingResources(peUnit, EnergyEventType.RESOURCE_UTILIZATION_CHANGED, exec);
-			} 
-			System.out.println("===" + exec.getJobId() + ":" + phaseLength);
-		}
-	}	*/
+			
+			try {
+				exec.setStatus(DCWormsTags.NEW_EXEC_PHASE);
+			} catch (Exception e) {
+			}
+			
+			Map<ResourceUnitName, ResourceUnit> choosenResources = exec.getUsedResources().getLast().getResourceUnits();
+
+			int phaseDuration = Double.valueOf(execTimeEstimationPlugin.execTimeEstimation(new SchedulingEvent(schedEvType), 
+					execTask, choosenResources, exec.getCompletionPercentage())).intValue();
+
+			exec.setEstimatedDuration(phaseDuration);
+			
+			if(exec.getResourceConsumptionProfile().getCurrentResourceConsumption() == exec.getResourceConsumptionProfile().getResourceConsumptionList().getLast()){
+				scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_FINISHED, execTask);
+			} else {
+				scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_CHANGED, execTask);
+			}
+		}
+	}	
 
 	public double calculateTotalLoad(int size) {
