Index: DCWoRMS/branches/coolemall/src/example/timeestimation/coolemall/PhaseBasedTimeEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/timeestimation/coolemall/PhaseBasedTimeEstimationPlugin.java	(revision 1415)
+++ DCWoRMS/branches/coolemall/src/example/timeestimation/coolemall/PhaseBasedTimeEstimationPlugin.java	(revision 1415)
@@ -0,0 +1,77 @@
+package example.timeestimation.coolemall;
+
+
+import java.util.Map;
+
+import schedframe.events.scheduling.SchedulingEvent;
+import schedframe.resources.computing.ComputingResource;
+import schedframe.resources.computing.Core;
+import schedframe.resources.computing.Processor;
+import schedframe.resources.units.PEUnit;
+import schedframe.resources.units.ProcessingElements;
+import schedframe.resources.units.ResourceUnit;
+import schedframe.resources.units.ResourceUnitName;
+import schedframe.resources.units.StandardResourceUnitName;
+import dcworms.schedframe.scheduling.ExecTask;
+import example.timeestimation.BaseTimeEstimationPlugin;
+
+public class PhaseBasedTimeEstimationPlugin extends BaseTimeEstimationPlugin{
+
+	/*
+	 * This method should return an estimation of time required to execute the task.
+	 * Requested calculation should be done based on the resources allocated for the task,
+	 * task description and task completion percentage.
+	 * 
+	 * Example implementation calculate the estimation based on processing power.
+	 * There is also a simple assumption, that processing power is a linear function
+	 * of number of allocated units and their speed.
+	 */
+	public double execTimeEstimation(SchedulingEvent event, ExecTask task,
+			Map<ResourceUnitName, ResourceUnit> allocatedResources,
+			double completionPercentage) {
+		
+
+		//String taskFreqString = task.getExecutionProfile().getCurrentResourceConsumption().getReferenceHardware().get("cpu_maxfreq");
+		//double taskFreq = Double.valueOf(taskFreqString);
+
+		double speed = 0;
+		PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE);	
+		
+		try {
+			ProcessingElements pes = (ProcessingElements) peUnit;
+			for (ComputingResource compResource : pes) {
+				if(compResource instanceof Core) {
+					Core core = (Core) compResource;
+					speed = core.getProcessor().getPowerInterface().getPState().getFrequency();
+					break;
+				} else if (compResource instanceof Processor) {
+					Processor processor = (Processor) compResource;
+					speed = processor.getPowerInterface().getPState().getFrequency();
+					break;
+				}
+			}		
+		} catch (Exception e){
+			speed = peUnit.getSpeed();			
+		}
+
+		//speed =  taskFreq;
+		int cnt = peUnit.getUsedAmount();
+
+		double execTime = (1 - completionPercentage/100) * task.getExecutionProfile().getCurrentResourceConsumption().getLenght() / (speed * cnt);
+
+		//double execTime = (1 - completionPercentage/100) * task.getExecutionProfile().getCurrentResourceConsumption().getDuration() * (taskFreq / currentFrequency);
+		//double execTime = (1 - completionPercentage/100) * task.getExecutionProfile().getCurrentResourceConsumption().getDuration();
+		
+		// if the result is very close to 0, but less then one millisecond then round this result to 0.001
+		if (Double.compare(execTime, 0.001) < 0) {
+			execTime = 0.001;
+		}
+
+		// time is measured in integer units, so get the nearest execTime int value.
+		execTime = Math.round(execTime);
+		return execTime;
+	}
+
+}
+
+
Index: DCWoRMS/branches/coolemall/src/example/timeestimation/coolemall/CPUFreqScalingPhaseTimeEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/timeestimation/coolemall/CPUFreqScalingPhaseTimeEstimationPlugin.java	(revision 1396)
+++ 	(revision )
@@ -1,59 +1,0 @@
-package example.timeestimation.coolemall;
-
-import java.util.Map;
-
-import schedframe.events.scheduling.SchedulingEvent;
-import schedframe.resources.computing.ComputingResource;
-import schedframe.resources.computing.Core;
-import schedframe.resources.computing.Processor;
-import schedframe.resources.units.PEUnit;
-import schedframe.resources.units.ProcessingElements;
-import schedframe.resources.units.ResourceUnit;
-import schedframe.resources.units.ResourceUnitName;
-import schedframe.resources.units.StandardResourceUnitName;
-import dcworms.schedframe.scheduling.ExecTask;
-import example.timeestimation.BaseTimeEstimationPlugin;
-
-public class CPUFreqScalingPhaseTimeEstimationPlugin extends BaseTimeEstimationPlugin{
-
-	
-	public double execTimeEstimation(SchedulingEvent event, ExecTask task,
-			Map<ResourceUnitName, ResourceUnit> allocatedResources,
-			double completionPercentage) {
-		
-		String taskFreqString = task.getExecutionProfile().getCurrentResourceConsumption().getReferenceHardware().get("cpu_maxfreq");
-		double taskFreq = Double.valueOf(taskFreqString);
-		
-		PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE);
-		double currentFrequency = 0;
-		
-		if(peUnit instanceof ProcessingElements){
-			ProcessingElements pes = (ProcessingElements) peUnit;
-			for (ComputingResource compResource : pes) {
-				if(compResource instanceof Core) {
-					Core core = (Core) compResource;
-					currentFrequency = core.getProcessor().getPowerInterface().getPState().getFrequency();
-					break;
-				} else if (compResource instanceof Processor) {
-					Processor processor = (Processor) compResource;
-					currentFrequency = processor.getPowerInterface().getPState().getFrequency();
-					break;
-				}
-			}
-		}
-		else 
-			currentFrequency = taskFreq;
-
-		double execTime = (1 - completionPercentage/100) * task.getExecutionProfile().getCurrentResourceConsumption().getDuration() * (taskFreq / currentFrequency);
-
-		// if the result is very close to 0, but less then one millisecond then round this result to 0.001
-		if (Double.compare(execTime, 0.001) < 0) {
-			execTime = 0.001;
-		}
-
-		// time is measured in integer units, so get the nearest execTime int value.
-		execTime = Math.round(execTime);
-		return execTime;
-	}
-
-}
Index: DCWoRMS/branches/coolemall/src/example/timeestimation/coolemall/PhaseTimeEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/timeestimation/coolemall/PhaseTimeEstimationPlugin.java	(revision 1396)
+++ 	(revision )
@@ -1,41 +1,0 @@
-package example.timeestimation.coolemall;
-
-
-import java.util.Map;
-
-import schedframe.events.scheduling.SchedulingEvent;
-import schedframe.resources.units.ResourceUnit;
-import schedframe.resources.units.ResourceUnitName;
-import schedframe.scheduling.tasks.phases.ResourceConsumption;
-import dcworms.schedframe.scheduling.ExecTask;
-import dcworms.schedframe.scheduling.Executable;
-import example.timeestimation.BaseTimeEstimationPlugin;
-
-public class PhaseTimeEstimationPlugin extends BaseTimeEstimationPlugin{
-
-	/*
-	 * This method should return an estimation of time required to execute the task.
-	 * Requested calculation should be done based on the resources allocated for the task,
-	 * task description and task completion percentage.
-	 */
-	public double execTimeEstimation(SchedulingEvent event, ExecTask task,
-			Map<ResourceUnitName, ResourceUnit> allocatedResources,
-			double completionPercentage) {
-
-		Executable exec = (Executable) task;
-
-		ResourceConsumption resConsumption = exec.getExecutionProfile().getCurrentResourceConsumption();
-
-		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
-		if (Double.compare(execTime, 0.001) < 0) {
-			execTime = 0.001;
-		}
-
-		// time is measured in integer units, so get the nearest execTime int value.
-		execTime = Math.round(execTime);
-		return execTime;
-	}
-
-}
Index: DCWoRMS/branches/coolemall/src/example/load/ProcessorLoadEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/load/ProcessorLoadEstimationPlugin.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/load/ProcessorLoadEstimationPlugin.java	(revision 1415)
@@ -2,14 +2,14 @@
 
 import schedframe.resources.computing.Processor;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.devices.PhysicalResource;
 import schedframe.scheduling.manager.tasks.JobRegistry;
 import schedframe.scheduling.manager.tasks.JobRegistryImpl;
-import schedframe.scheduling.tasks.phases.PhaseBehaviour;
+import schedframe.scheduling.tasks.phases.PhaseSystemLoad;
 import dcworms.schedframe.scheduling.ExecTask;
 
 public class ProcessorLoadEstimationPlugin extends BaseLoadEstimationPlugin{
 
-	public double estimateUtlization(EnergyEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
+	public double estimateUtlization(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
 		Processor proc = (Processor) resource;
 		double sumCoresLoad = 0;
@@ -26,5 +26,5 @@
 			double cpuUsage = 1 / nrOfThreadsOnCpu;
 
-			for(PhaseBehaviour pb: task.getExecutionProfile().getCurrentResourceConsumption().getBehaviourList()){
+			for(PhaseSystemLoad pb: task.getExecutionProfile().getCurrentResourceConsumption().getSystemLoad()){
 				if(pb.getResouceName().equals("PM_CPU_Usage")){
 					cpuUsage = pb.getUtilization();
Index: DCWoRMS/branches/coolemall/src/example/load/DefaultLoadEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/load/DefaultLoadEstimationPlugin.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/load/DefaultLoadEstimationPlugin.java	(revision 1415)
@@ -2,5 +2,5 @@
 
 import schedframe.resources.computing.ComputingResource;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.devices.PhysicalResource;
 import schedframe.scheduling.manager.tasks.JobRegistry;
@@ -10,5 +10,5 @@
 public class DefaultLoadEstimationPlugin extends BaseLoadEstimationPlugin{
 
-	public double estimateUtlization(EnergyEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
+	public double estimateUtlization(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
 
 		ComputingResource computingResource = (ComputingResource) resource;
Index: DCWoRMS/branches/coolemall/src/example/energy/DefaultEnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/energy/DefaultEnergyEstimationPlugin.java	(revision 1207)
+++ DCWoRMS/branches/coolemall/src/example/energy/DefaultEnergyEstimationPlugin.java	(revision 1415)
@@ -2,5 +2,5 @@
 
 import schedframe.resources.computing.ComputingResource;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.devices.PhysicalResource;
 import schedframe.scheduling.manager.tasks.JobRegistry;
@@ -10,5 +10,5 @@
 
 
-	public double estimatePowerConsumption(EnergyEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
+	public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
 		double powerConsumption = 0;
 		try {
Index: DCWoRMS/branches/coolemall/src/example/energy/NodeEnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/energy/NodeEnergyEstimationPlugin.java	(revision 1247)
+++ DCWoRMS/branches/coolemall/src/example/energy/NodeEnergyEstimationPlugin.java	(revision 1415)
@@ -3,5 +3,5 @@
 import schedframe.resources.computing.Node;
 import schedframe.resources.computing.Processor;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.devices.Device;
 import schedframe.resources.devices.PhysicalResource;
@@ -10,5 +10,5 @@
 public class NodeEnergyEstimationPlugin extends BaseEnergyEstimationPlugin {
 
-	public double estimatePowerConsumption(EnergyEvent event, JobRegistry jobRegistry,
+	public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry,
 			PhysicalResource resource) {
 		double powerConsumption = 0;
Index: DCWoRMS/branches/coolemall/src/example/energy/device/FanEnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/energy/device/FanEnergyEstimationPlugin.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/energy/device/FanEnergyEstimationPlugin.java	(revision 1415)
@@ -1,6 +1,6 @@
 package example.energy.device;
 
-import schedframe.events.scheduling.EventReason;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.events.EventReason;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.computing.profiles.energy.airthroughput.StandardAirflowStateName;
 import schedframe.resources.devices.PhysicalResource;
@@ -10,5 +10,5 @@
 public class FanEnergyEstimationPlugin extends BaseEnergyEstimationPlugin {
 
-	public double estimatePowerConsumption(EnergyEvent event, JobRegistry jobRegistry,
+	public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry,
 			PhysicalResource resource) {
 		double powerConsumption = 0;
@@ -24,5 +24,5 @@
 	}
 
-	public double estimateAirflow(EnergyEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
+	public double estimateAirflow(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
 		double airflow= 0;
 		try {
Index: DCWoRMS/branches/coolemall/src/example/energy/BaseEnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/energy/BaseEnergyEstimationPlugin.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/energy/BaseEnergyEstimationPlugin.java	(revision 1415)
@@ -3,29 +3,44 @@
 import schedframe.Parameters;
 import schedframe.PluginConfiguration;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.computing.profiles.energy.power.plugin.EnergyEstimationPlugin;
+import schedframe.resources.computing.profiles.energy.power.plugin.EnergyPluginConfiguration;
 import schedframe.resources.devices.PhysicalResource;
 import schedframe.scheduling.manager.tasks.JobRegistry;
+import schemas.StringValueWithUnit;
 
 public abstract class BaseEnergyEstimationPlugin implements EnergyEstimationPlugin {
 
+	 EnergyPluginConfiguration plugConf;
+	 
 	@Override
 	public PluginConfiguration getConfiguration() {
-		// TODO Auto-generated method stub
-		return null;
+		return plugConf;
 	}
 	
 	@Override
-	public double estimateAirflow(EnergyEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
+	public double estimateAirflow(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
 		throw new RuntimeException("Not implemented.");
 	}
 
 	@Override
-	public double estimateTemperature(EnergyEvent event, JobRegistry jobRegistry, PhysicalResource  resource) {
+	public double estimateTemperature(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource  resource) {
 		throw new RuntimeException("Not implemented.");
 	}
 	
 	public void init(Parameters parameters) {
-
+		plugConf = new EnergyPluginConfiguration();
+		try{
+			StringValueWithUnit powerCapLevel = parameters.get("powerCapLevel").get(0);
+			plugConf.setPowerCapLevel(Double.valueOf(powerCapLevel.getContent()).doubleValue());
+		} catch(Exception e){
+			plugConf.setPowerCapLevel(-1);
+		}
+		try{
+			StringValueWithUnit powerFloorLevel = parameters.get("powerFloorLevel").get(0);
+			plugConf.setPowerFloorLevel(Double.valueOf(powerFloorLevel.getContent()).doubleValue());
+		} catch(Exception e){
+			plugConf.setPowerFloorLevel(-1);
+		}
 	}
 
Index: DCWoRMS/branches/coolemall/src/example/energy/DataCenterEnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/energy/DataCenterEnergyEstimationPlugin.java	(revision 1258)
+++ DCWoRMS/branches/coolemall/src/example/energy/DataCenterEnergyEstimationPlugin.java	(revision 1415)
@@ -3,5 +3,5 @@
 import schedframe.resources.computing.Node;
 import schedframe.resources.computing.DataCenter;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.computing.profiles.energy.power.PowerUsage;
 import schedframe.resources.devices.PhysicalResource;
@@ -11,5 +11,5 @@
 
 	@Override
-	public double estimatePowerConsumption(EnergyEvent event, JobRegistry jobRegistry,
+	public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry,
 			PhysicalResource resource) {
 		double power = 0;
Index: DCWoRMS/branches/coolemall/src/example/energy/ProcessorEnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/energy/ProcessorEnergyEstimationPlugin.java	(revision 1207)
+++ DCWoRMS/branches/coolemall/src/example/energy/ProcessorEnergyEstimationPlugin.java	(revision 1415)
@@ -3,5 +3,5 @@
 import schedframe.resources.ResourceStatus;
 import schedframe.resources.computing.Processor;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.computing.profiles.energy.power.StandardPowerStateName;
 import schedframe.resources.devices.PhysicalResource;
@@ -10,5 +10,5 @@
 public class ProcessorEnergyEstimationPlugin extends BaseEnergyEstimationPlugin  {
 
-	public double estimatePowerConsumption(EnergyEvent event, JobRegistry jobRegistry,
+	public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry,
 			PhysicalResource resource) {
 		double powerConsumption;
@@ -42,4 +42,7 @@
 			
 		}
+		if(cpu.getLoadInterface().getRecentUtilization().getValue() != 0.0){
+			powerConsumption = powerConsumption * cpu.getLoadInterface().getRecentUtilization().getValue()/100;			
+		}
 		return powerConsumption;
 	}
Index: DCWoRMS/branches/coolemall/src/example/energy/coolemall/CB1EnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/energy/coolemall/CB1EnergyEstimationPlugin.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/energy/coolemall/CB1EnergyEstimationPlugin.java	(revision 1415)
@@ -10,5 +10,5 @@
 import schedframe.resources.computing.coolemall.ComputeBox1;
 import schedframe.resources.computing.coolemall.NodeGroup;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.computing.profiles.energy.airthroughput.CustomAirflowStateName;
 import schedframe.resources.computing.profiles.energy.power.PState;
@@ -26,5 +26,5 @@
 	double powerUpgradeLevel = -1;
 	
-	public double estimatePowerConsumption(EnergyEvent event, JobRegistry jobRegistry,
+	public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry,
 			PhysicalResource resource) {
 		
Index: DCWoRMS/branches/coolemall/src/example/energy/coolemall/FlowPumpInletEnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/energy/coolemall/FlowPumpInletEnergyEstimationPlugin.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/energy/coolemall/FlowPumpInletEnergyEstimationPlugin.java	(revision 1415)
@@ -5,5 +5,5 @@
 import schedframe.resources.computing.coolemall.ComputeBox1;
 import schedframe.resources.computing.coolemall.NodeGroup;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.devices.Device;
 import schedframe.resources.devices.Fan;
@@ -15,5 +15,5 @@
 public class FlowPumpInletEnergyEstimationPlugin extends BaseEnergyEstimationPlugin {
 
-	public double estimatePowerConsumption(EnergyEvent event, JobRegistry jobRegistry,
+	public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry,
 			PhysicalResource resource) {
 		
@@ -86,5 +86,5 @@
 	}
 	
-	public double estimateAirflow(EnergyEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
+	public double estimateAirflow(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
 		double airflow = 0;
 		double Vair_total;
Index: DCWoRMS/branches/coolemall/src/example/energy/coolemall/NodeEnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/energy/coolemall/NodeEnergyEstimationPlugin.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/energy/coolemall/NodeEnergyEstimationPlugin.java	(revision 1415)
@@ -5,5 +5,5 @@
 import schedframe.resources.computing.Node;
 import schedframe.resources.computing.Processor;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.computing.profiles.energy.power.StandardPowerStateName;
 import schedframe.resources.devices.Device;
@@ -15,5 +15,5 @@
 public class NodeEnergyEstimationPlugin extends BaseEnergyEstimationPlugin {
 
-	public double estimatePowerConsumption(EnergyEvent event, JobRegistry jobRegistry,
+	public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry,
 			PhysicalResource resource) {
 		double powerConsumption = 0;
Index: DCWoRMS/branches/coolemall/src/example/energy/coolemall/CB2EnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/energy/coolemall/CB2EnergyEstimationPlugin.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/energy/coolemall/CB2EnergyEstimationPlugin.java	(revision 1415)
@@ -8,5 +8,5 @@
 import schedframe.resources.computing.coolemall.ComputeBox1;
 import schedframe.resources.computing.coolemall.NodeGroup;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.computing.profiles.energy.power.StandardPowerStateName;
 import schedframe.resources.devices.Device;
@@ -19,5 +19,5 @@
 public class CB2EnergyEstimationPlugin extends BaseEnergyEstimationPlugin{
 
-	public double estimatePowerConsumption(EnergyEvent event, JobRegistry jobRegistry,
+	public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry,
 			PhysicalResource resource) {
 		
Index: DCWoRMS/branches/coolemall/src/example/energy/coolemall/FlowPumpOutletEnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/energy/coolemall/FlowPumpOutletEnergyEstimationPlugin.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/energy/coolemall/FlowPumpOutletEnergyEstimationPlugin.java	(revision 1415)
@@ -5,5 +5,5 @@
 import schedframe.resources.computing.coolemall.ComputeBox1;
 import schedframe.resources.computing.coolemall.NodeGroup;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.devices.Device;
 import schedframe.resources.devices.Fan;
@@ -15,5 +15,5 @@
 public class FlowPumpOutletEnergyEstimationPlugin extends BaseEnergyEstimationPlugin {
 
-	public double estimatePowerConsumption(EnergyEvent event, JobRegistry jobRegistry,
+	public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry,
 			PhysicalResource resource) {
 		
@@ -23,5 +23,5 @@
 	}
 	
-	public double estimateAirflow(EnergyEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
+	public double estimateAirflow(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
 		double airflow = 0;
 		double Vair_total;
Index: DCWoRMS/branches/coolemall/src/example/energy/coolemall/HeatsinkEnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/energy/coolemall/HeatsinkEnergyEstimationPlugin.java	(revision 1247)
+++ DCWoRMS/branches/coolemall/src/example/energy/coolemall/HeatsinkEnergyEstimationPlugin.java	(revision 1415)
@@ -3,5 +3,5 @@
 import schedframe.resources.computing.Node;
 import schedframe.resources.computing.Processor;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.devices.Device;
 import schedframe.resources.devices.PhysicalResource;
@@ -11,5 +11,5 @@
 public class HeatsinkEnergyEstimationPlugin extends BaseEnergyEstimationPlugin  {
 
-	public double estimatePowerConsumption(EnergyEvent event, JobRegistry jobRegistry,
+	public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry,
 			PhysicalResource resource) {
 		
Index: DCWoRMS/branches/coolemall/src/example/energy/coolemall/CoolingDeviceEnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/energy/coolemall/CoolingDeviceEnergyEstimationPlugin.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/energy/coolemall/CoolingDeviceEnergyEstimationPlugin.java	(revision 1415)
@@ -7,5 +7,5 @@
 import schedframe.resources.computing.coolemall.ComputeBox1;
 import schedframe.resources.computing.coolemall.NodeGroup;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.computing.profiles.energy.power.StandardPowerStateName;
 import schedframe.resources.devices.Device;
@@ -18,10 +18,10 @@
 public class CoolingDeviceEnergyEstimationPlugin extends BaseEnergyEstimationPlugin {
 
-	public double estimateAirflow(EnergyEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
+	public double estimateAirflow(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
 		double airflow = 0;
 		return airflow;
 	}
 
-	public double estimatePowerConsumption(EnergyEvent event, JobRegistry jobRegistry,
+	public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry,
 			PhysicalResource resource) {
 		
Index: DCWoRMS/branches/coolemall/src/example/energy/coolemall/ProcessorEnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/energy/coolemall/ProcessorEnergyEstimationPlugin.java	(revision 1322)
+++ DCWoRMS/branches/coolemall/src/example/energy/coolemall/ProcessorEnergyEstimationPlugin.java	(revision 1415)
@@ -2,5 +2,5 @@
 
 import schedframe.resources.computing.Processor;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.computing.profiles.energy.power.StandardPowerStateName;
 import schedframe.resources.devices.PhysicalResource;
@@ -10,5 +10,5 @@
 public class ProcessorEnergyEstimationPlugin extends BaseEnergyEstimationPlugin  {
 
-	public double estimatePowerConsumption(EnergyEvent event, JobRegistry jobRegistry,
+	public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry,
 			PhysicalResource resource) {
 		
Index: DCWoRMS/branches/coolemall/src/example/energy/coolemall/NodeGroupEnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/energy/coolemall/NodeGroupEnergyEstimationPlugin.java	(revision 1247)
+++ DCWoRMS/branches/coolemall/src/example/energy/coolemall/NodeGroupEnergyEstimationPlugin.java	(revision 1415)
@@ -3,5 +3,5 @@
 import schedframe.resources.computing.Node;
 import schedframe.resources.computing.coolemall.NodeGroup;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.devices.PhysicalResource;
 import schedframe.scheduling.manager.tasks.JobRegistry;
@@ -10,5 +10,5 @@
 public class NodeGroupEnergyEstimationPlugin extends BaseEnergyEstimationPlugin{
 
-	public double estimatePowerConsumption(EnergyEvent event, JobRegistry jobRegistry,
+	public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry,
 			PhysicalResource resource) {
 		
Index: DCWoRMS/branches/coolemall/src/example/energy/coolemall/FanEnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/energy/coolemall/FanEnergyEstimationPlugin.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/energy/coolemall/FanEnergyEstimationPlugin.java	(revision 1415)
@@ -1,8 +1,8 @@
 package example.energy.coolemall;
 
-import schedframe.events.scheduling.EventReason;
+import schedframe.events.EventReason;
 import schedframe.resources.computing.ComputingResource;
 import schedframe.resources.computing.Node;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.ResourceEvent;
 import schedframe.resources.computing.profiles.energy.power.StandardPowerStateName;
 import schedframe.resources.devices.Device;
@@ -14,5 +14,5 @@
 public class FanEnergyEstimationPlugin extends BaseEnergyEstimationPlugin {
 
-	public double estimatePowerConsumption(EnergyEvent event, JobRegistry jobRegistry,
+	public double estimatePowerConsumption(ResourceEvent event, JobRegistry jobRegistry,
 			PhysicalResource resource) {
 		
@@ -35,5 +35,5 @@
 	}
 	
-	public double estimateAirflow(EnergyEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
+	public double estimateAirflow(ResourceEvent event, JobRegistry jobRegistry, PhysicalResource resource) {
 		
 		double airflow = 0;
Index: DCWoRMS/branches/coolemall/src/example/localplugin/Cluster_FCFSBF_ConsolidationHighPerf_NodePowMan_Plugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/localplugin/Cluster_FCFSBF_ConsolidationHighPerf_NodePowMan_Plugin.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/localplugin/Cluster_FCFSBF_ConsolidationHighPerf_NodePowMan_Plugin.java	(revision 1415)
@@ -7,9 +7,10 @@
 import java.util.Comparator;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import schedframe.events.scheduling.SchedulingEvent;
-import schedframe.exceptions.ResourceException;
 import schedframe.resources.ResourceStatus;
 import schedframe.resources.StandardResourceType;
@@ -17,8 +18,11 @@
 import schedframe.resources.computing.Node;
 import schedframe.resources.computing.Processor;
-import schedframe.resources.computing.profiles.energy.airthroughput.StandardAirflowStateName;
+import schedframe.resources.computing.profiles.energy.airthroughput.AirflowState;
+import schedframe.resources.computing.profiles.energy.airthroughput.AirflowStateName;
+import schedframe.resources.computing.profiles.energy.airthroughput.CustomAirflowStateName;
 import schedframe.resources.computing.profiles.energy.power.PState;
 import schedframe.resources.computing.profiles.energy.power.StandardPowerStateName;
 import schedframe.resources.devices.Device;
+import schedframe.resources.devices.Fan;
 import schedframe.resources.units.ProcessingElements;
 import schedframe.resources.units.ResourceUnit;
@@ -55,5 +59,5 @@
 			// check all tasks in queue
 
-			List<Node> notSelectedNodes = resourceManager.getNodes();
+			Set<Node> selectedNodes = new HashSet<Node>();
 			
 			for (int i = 0; i < q.size(); i++) {
@@ -67,9 +71,20 @@
 						ProcessingElements pe = (ProcessingElements) choosenResources.get(StandardResourceUnitName.PE);
 						Node node = (Node) pe.get(0).getParent();
-						notSelectedNodes.remove(node);
+						selectedNodes.add(node);
 					} 
 				}
 			}
-			turnOffIdleNodes(notSelectedNodes);
+			List<Node> nodes = resourceManager.getNodes();
+			nodes.removeAll(selectedNodes);
+			turnOffIdleNodes(nodes);
+			for(Node node: resourceManager.getNodes()){
+				for(Device device: node.getParent().getResourceCharacteristic().getDevices()){
+					if(device.getType().equals(StandardResourceType.Fan)){
+						Fan fan = (Fan) device;
+						adjustFanSpeed(fan, selectedNodes);
+						break;
+					}
+				}
+			}
 			break;
 		}
@@ -84,10 +99,7 @@
 		Node node;
 		if(availableNodes.size() == 0){
-			try {
-				nodes = (List<Node>) resourceManager.getResourcesByTypeWithStatus(StandardResourceType.Node, ResourceStatus.UNAVAILABLE);
-			} catch (ResourceException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
+
+			nodes = (List<Node>) resourceManager.getResourcesByTypeWithStatus(StandardResourceType.Node, ResourceStatus.UNAVAILABLE);
+
 			Collections.sort(nodes, new PerformanceComparator());
 			node = turnOnFirstNode(nodes, task);
@@ -112,4 +124,5 @@
 			}
 		}
+
 		ProcessingElements result = new ProcessingElements(node.getFullName());
 		result.addAll(choosenResources);
@@ -167,10 +180,4 @@
 					continue;
 				else {
-					for(Device device: node.getParent().getResourceCharacteristic().getDevices()){
-						if(device.getType().equals(StandardResourceType.Fan)){
-							device.getAirflowInterface().setAirflowState(StandardAirflowStateName.ON);
-							break;
-						}
-					}
 					node.getPowerInterface().setPowerState(StandardPowerStateName.ON);
 					startedNode = node;
@@ -190,13 +197,6 @@
 			
 			if(freeProcessors == node.getProcessors().size()) {
-				for(Device device: node.getParent().getResourceCharacteristic().getDevices()){
-					if(device.getType().equals(StandardResourceType.Fan)){
-						device.getAirflowInterface().setAirflowState(StandardAirflowStateName.OFF);
-						break;
-					}
-				}
 				node.getPowerInterface().setPowerState(StandardPowerStateName.OFF);
 			}
-
 		}
 	}
@@ -249,4 +249,59 @@
 	    }
 	}
+	
+	private void adjustFanSpeed(Fan fan, Set<Node> selectedNodes){
+		AirflowStateName newState;
+		double totalLoad = 0;
+		double loadLevel;
+		ComputingResource compRes = fan.getComputingResource();
+		for(ComputingResource n: compRes.getChildren()){
+			if(fan.getChilledResources().contains(n.getFullName())){
+				if(selectedNodes.contains(n)){
+					totalLoad = totalLoad + 100;
+				} else {
+					totalLoad = totalLoad + n.getLoadInterface().getRecentUtilization().getValue();
+				}	
+			}
+		}
+		loadLevel = totalLoad / compRes.getChildren().size();
+		
+		double highestLoadLevel = 0;
+
+		if(fan.getAirflowInterface().supportAirflowState(new CustomAirflowStateName("ON_" + new Double(loadLevel).intValue()))){
+			newState = new CustomAirflowStateName("ON_" + new Double(loadLevel).intValue());
+		} else {
+			for(AirflowState airflowState: fan.getAirflowInterface().getSupportedAirflowStates()){
+				Double load;
+				try{
+					load = Double.valueOf(airflowState.getName().getLabel().substring(3));
+				}catch (Exception e){
+					continue;
+				}
+				if(highestLoadLevel < load){
+					highestLoadLevel = load;
+				}
+			}
+			if(loadLevel == 0){
+				newState = new CustomAirflowStateName("OFF");
+			} else {
+
+				double higherLoadLevel = highestLoadLevel;
+
+				for(AirflowState airflowState: fan.getAirflowInterface().getSupportedAirflowStates()){
+					Double load;
+					try{
+						load = Double.valueOf(airflowState.getName().getLabel().substring(3));
+					}catch (Exception e){
+						continue;
+					}
+					if(loadLevel < load){
+						higherLoadLevel = load;
+					}
+				}
+				newState = new CustomAirflowStateName("ON_" + Double.valueOf(higherLoadLevel).intValue());
+			}
+		}
+		fan.getAirflowInterface().setAirflowState(newState);
+	}
 
 }
Index: DCWoRMS/branches/coolemall/src/example/localplugin/Cluster_FCFSBF_ConsolidationLowPower_NodePowMan_Plugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/localplugin/Cluster_FCFSBF_ConsolidationLowPower_NodePowMan_Plugin.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/localplugin/Cluster_FCFSBF_ConsolidationLowPower_NodePowMan_Plugin.java	(revision 1415)
@@ -11,5 +11,4 @@
 
 import schedframe.events.scheduling.SchedulingEvent;
-import schedframe.exceptions.ResourceException;
 import schedframe.resources.ResourceStatus;
 import schedframe.resources.StandardResourceType;
@@ -83,10 +82,7 @@
 		Node node;
 		if(availableNodes.size() == 0){
-			try {
-				nodes = (List<Node>) resourceManager.getResourcesByTypeWithStatus(StandardResourceType.Node, ResourceStatus.UNAVAILABLE);
-			} catch (ResourceException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
+			
+			nodes = (List<Node>) resourceManager.getResourcesByTypeWithStatus(StandardResourceType.Node, ResourceStatus.UNAVAILABLE);
+
 			Collections.sort(nodes, new PowerComparator());
 			node = turnOnFirstNode(nodes, task);
Index: DCWoRMS/branches/coolemall/src/example/localplugin/FCFSBF_RandomPluginWithPausingResuming.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/localplugin/FCFSBF_RandomPluginWithPausingResuming.java	(revision 1415)
+++ DCWoRMS/branches/coolemall/src/example/localplugin/FCFSBF_RandomPluginWithPausingResuming.java	(revision 1415)
@@ -0,0 +1,172 @@
+package example.localplugin;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import schedframe.events.scheduling.SchedulingEvent;
+import schedframe.resources.ResourceStatus;
+import schedframe.resources.computing.ComputingResource;
+import schedframe.resources.computing.Processor;
+import schedframe.resources.units.ProcessingElements;
+import schedframe.resources.units.ResourceUnit;
+import schedframe.resources.units.ResourceUnitName;
+import schedframe.resources.units.StandardResourceUnitName;
+import schedframe.scheduling.manager.resources.ClusterResourceManager;
+import schedframe.scheduling.manager.resources.ResourceManager;
+import schedframe.scheduling.manager.tasks.JobRegistry;
+import schedframe.scheduling.plan.SchedulingPlanInterface;
+import schedframe.scheduling.plan.impl.SchedulingPlan;
+import schedframe.scheduling.plugin.ModuleList;
+import schedframe.scheduling.queue.TaskQueue;
+import schedframe.scheduling.queue.TaskQueueList;
+import schedframe.scheduling.tasks.TaskInterface;
+import dcworms.schedframe.scheduling.ExecTask;
+import example.localplugin.BaseLocalSchedulingPlugin;
+import gridsim.dcworms.DCWormsTags;
+
+public class FCFSBF_RandomPluginWithPausingResuming extends BaseLocalSchedulingPlugin {
+
+	public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry,
+			ResourceManager resManager, ModuleList modules) {
+
+		ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
+		List<Processor> processors = resourceManager.getProcessors();
+		SchedulingPlan plan = new SchedulingPlan();
+		// choose the events types to serve.
+		// Different actions for different events are possible.
+		switch (event.getType()) {
+		case START_TASK_EXECUTION:
+		case TASK_RESUMED:
+		//case TIMER:
+			// our tasks are placed only in first queue (see BaseLocalSchedulingPlugin.placeJobsInQueues() method)
+			TaskQueue q = queues.get(0);
+			// check all tasks in queue
+
+			for (int i = 0; i < q.size(); i++) {
+				TaskInterface<?> task = q.get(i);
+				// if status of the tasks in READY
+				if (task.getStatus() == DCWormsTags.READY) {
+
+					Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(processors, task);
+					if (choosenResources != null) {
+						addToSchedulingPlan(plan, task, choosenResources);
+					} else {
+						ExecTask taskToPause = getTaskWithLowestPriority(jobRegistry.getRunningTasks());
+						if(getTaskPriority(task) > getTaskPriority(taskToPause)){
+							jobRegistry.pauseTask(taskToPause.getJobId(), taskToPause.getId());
+						}
+					}
+				}
+			}
+
+			break;
+		case TASK_FINISHED:
+			for(ExecTask exec: jobRegistry.getTasks(DCWormsTags.PAUSED)){
+				jobRegistry.resumeTask(exec.getJobId(), exec.getId());
+			}
+			q = queues.get(0);
+			// check all tasks in queue
+
+			for (int i = 0; i < q.size(); i++) {
+				TaskInterface<?> task = q.get(i);
+				// if status of the tasks in READY
+				if (task.getStatus() == DCWormsTags.READY) {
+					Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(processors, task);
+					if (choosenResources != null) {
+						addToSchedulingPlan(plan, task, choosenResources);
+					}
+				}
+			}
+
+			break;
+		case TASK_PAUSED: 
+			 q = queues.get(0);
+			// check all tasks in queue
+
+			for (int i = 0; i < q.size(); i++) {
+				TaskInterface<?> task = q.get(i);
+				// if status of the tasks in READY
+				if (task.getStatus() == DCWormsTags.READY) {
+
+					Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(processors, task);
+					if (choosenResources != null) {
+						addToSchedulingPlan(plan, task, choosenResources);
+					}
+				}
+			}
+
+		}
+		
+		return plan;
+	}
+
+	private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution(
+			List<Processor> processors, TaskInterface<?> task) {
+
+		Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>(1);
+
+		int cpuRequest;
+		try {
+			cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
+		} catch (NoSuchFieldException e) {
+			cpuRequest = 0;
+		}
+
+		if (cpuRequest != 0) {
+
+			if (processors.size() < cpuRequest) {
+				return null;
+			}
+
+			List<ComputingResource> choosenResources = new ArrayList<ComputingResource>(cpuRequest);				
+			for (int i = 0; i < processors.size() && cpuRequest > 0; i++) {
+				if (processors.get(i).getStatus() == ResourceStatus.FREE) {
+					choosenResources.add(processors.get(i));
+					cpuRequest--;
+				}
+			}
+			if (cpuRequest > 0) {
+				return null;
+			}
+
+			ProcessingElements pe = new ProcessingElements();
+			pe.addAll(choosenResources);
+			map.put(StandardResourceUnitName.PE, pe);
+			return map;
+		}
+
+		return null;
+	}
+	
+	
+	private int getTaskPriority(TaskInterface<?> task){
+		int priority;
+		
+		try {
+			double cpuRequest = task.getCpuCntRequest();
+			priority = (-1) * Double.valueOf(cpuRequest).intValue();
+		} catch (NoSuchFieldException e) {
+			priority = Integer.MIN_VALUE;
+		}
+		
+		return priority;
+	}
+	
+	private ExecTask getTaskWithLowestPriority(List<ExecTask> tasks){
+		ExecTask lowestPriorityTask = null;
+		int lowestPriority = Integer.MAX_VALUE;
+		for(ExecTask execTask: tasks){
+			int taskPriority = getTaskPriority(execTask);
+			if(taskPriority < lowestPriority){
+				lowestPriority = getTaskPriority(execTask);
+				lowestPriorityTask = execTask;
+			}
+		}
+		
+		return lowestPriorityTask;
+	}
+
+
+}
Index: DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox1/CB1_FCFS_ConsolidationHighPerf_NodePowMan_SP.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox1/CB1_FCFS_ConsolidationHighPerf_NodePowMan_SP.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox1/CB1_FCFS_ConsolidationHighPerf_NodePowMan_SP.java	(revision 1415)
@@ -9,5 +9,4 @@
 
 import schedframe.events.scheduling.SchedulingEvent;
-import schedframe.exceptions.ResourceException;
 import schedframe.resources.ResourceStatus;
 import schedframe.resources.StandardResourceType;
@@ -94,10 +93,7 @@
 		Node node;
 		if(avNodes.size() == 0){
-			try {
-				nodes = (List<Node>) resourceManager.getResourcesByTypeWithStatus(StandardResourceType.Node, ResourceStatus.UNAVAILABLE);
-			} catch (ResourceException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
+
+			nodes = (List<Node>) resourceManager.getResourcesByTypeWithStatus(StandardResourceType.Node, ResourceStatus.UNAVAILABLE);
+
 			Collections.sort(nodes, new FavourableNodeComparator());
 			node = turnOnFirstNode(nodes, task);
Index: DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox1/CB1_FCFS_ConsolidationLowPower_NodePowMan_SP.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox1/CB1_FCFS_ConsolidationLowPower_NodePowMan_SP.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox1/CB1_FCFS_ConsolidationLowPower_NodePowMan_SP.java	(revision 1415)
@@ -9,5 +9,4 @@
 
 import schedframe.events.scheduling.SchedulingEvent;
-import schedframe.exceptions.ResourceException;
 import schedframe.resources.ResourceStatus;
 import schedframe.resources.StandardResourceType;
@@ -94,10 +93,7 @@
 		Node node;
 		if(avNodes.size() == 0){
-			try {
-				nodes = (List<Node>) resourceManager.getResourcesByTypeWithStatus(StandardResourceType.Node, ResourceStatus.UNAVAILABLE);
-			} catch (ResourceException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
+
+			nodes = (List<Node>) resourceManager.getResourcesByTypeWithStatus(StandardResourceType.Node, ResourceStatus.UNAVAILABLE);
+
 			Collections.sort(nodes, new FavourableNodeComparator());
 			node = turnOnFirstNode(nodes, task);
Index: DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox2/CB2_FCFS_ConsolidationHighPerf_NodePowMan_SP.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox2/CB2_FCFS_ConsolidationHighPerf_NodePowMan_SP.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox2/CB2_FCFS_ConsolidationHighPerf_NodePowMan_SP.java	(revision 1415)
@@ -9,5 +9,4 @@
 
 import schedframe.events.scheduling.SchedulingEvent;
-import schedframe.exceptions.ResourceException;
 import schedframe.resources.ResourceStatus;
 import schedframe.resources.StandardResourceType;
@@ -95,10 +94,7 @@
 		Node node;
 		if(avNodes.size() == 0){
-			try {
-				nodes = (List<Node>) resourceManager.getResourcesByTypeWithStatus(StandardResourceType.Node, ResourceStatus.UNAVAILABLE);
-			} catch (ResourceException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
+			
+			nodes = (List<Node>) resourceManager.getResourcesByTypeWithStatus(StandardResourceType.Node, ResourceStatus.UNAVAILABLE);
+
 			Collections.sort(nodes, new PerformanceComparator());
 			node = turnOnFirstNode(nodes, task);
Index: DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox2/CB2_FCFS_ConsolidationLowPower_NodePowMan_SP.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox2/CB2_FCFS_ConsolidationLowPower_NodePowMan_SP.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox2/CB2_FCFS_ConsolidationLowPower_NodePowMan_SP.java	(revision 1415)
@@ -9,5 +9,4 @@
 
 import schedframe.events.scheduling.SchedulingEvent;
-import schedframe.exceptions.ResourceException;
 import schedframe.resources.ResourceStatus;
 import schedframe.resources.StandardResourceType;
@@ -94,10 +93,7 @@
 		Node node;
 		if(avNodes.size() == 0){
-			try {
-				nodes = (List<Node>) resourceManager.getResourcesByTypeWithStatus(StandardResourceType.Node, ResourceStatus.UNAVAILABLE);
-			} catch (ResourceException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
+
+			nodes = (List<Node>) resourceManager.getResourcesByTypeWithStatus(StandardResourceType.Node, ResourceStatus.UNAVAILABLE);
+
 			Collections.sort(nodes, new PowerComparator());
 			node = turnOnFirstNode(nodes, task);
Index: DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox2/CB2_FCFS_Random_PowerCapping_SP.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox2/CB2_FCFS_Random_PowerCapping_SP.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox2/CB2_FCFS_Random_PowerCapping_SP.java	(revision 1415)
@@ -78,11 +78,7 @@
 				if (task.getStatus() == DCWormsTags.READY) {
 
-					try {
-						if(resourceManager.getResourcesByTypeWithStatus(StandardResourceType.Core, ResourceStatus.FREE).size() == 0)
-							break;
-					} catch (ResourceException e) {
-						// TODO Auto-generated catch block
-						e.printStackTrace();
-					}
+					if(resourceManager.getResourcesByTypeWithStatus(StandardResourceType.Core, ResourceStatus.FREE).size() == 0)
+						break;
+
 					Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(resourceManager, task);
 					if (choosenResources != null) {
Index: DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox2/CB2_FCFS_Random_SP.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox2/CB2_FCFS_Random_SP.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/computebox2/CB2_FCFS_Random_SP.java	(revision 1415)
@@ -8,5 +8,4 @@
 
 import schedframe.events.scheduling.SchedulingEvent;
-import schedframe.exceptions.ResourceException;
 import schedframe.resources.ResourceStatus;
 import schedframe.resources.StandardResourceType;
@@ -61,11 +60,7 @@
 				if (task.getStatus() == DCWormsTags.READY) {
 
-					try {
-						if(resourceManager.getResourcesByTypeWithStatus(StandardResourceType.Core, ResourceStatus.FREE).size() == 0)
-							break;
-					} catch (ResourceException e) {
-						// TODO Auto-generated catch block
-						e.printStackTrace();
-					}
+					if(resourceManager.getResourcesByTypeWithStatus(StandardResourceType.Core, ResourceStatus.FREE).size() == 0)
+						break;
+
 					Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(resourceManager, task);
 					if (choosenResources != null) {
Index: DCWoRMS/branches/coolemall/src/example/localplugin/BaseLocalSchedulingPlugin.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/localplugin/BaseLocalSchedulingPlugin.java	(revision 1396)
+++ DCWoRMS/branches/coolemall/src/example/localplugin/BaseLocalSchedulingPlugin.java	(revision 1415)
@@ -6,12 +6,9 @@
 import schedframe.Parameters;
 import schedframe.PluginConfiguration;
-import schedframe.events.scheduling.SchedulingEvent;
 import schedframe.events.scheduling.SchedulingEventType;
-import schedframe.events.scheduling.SchedulingResponseType;
 import schedframe.resources.units.ResourceUnit;
 import schedframe.resources.units.ResourceUnitName;
 import schedframe.scheduling.TaskList;
 import schedframe.scheduling.manager.resources.ResourceManager;
-import schedframe.scheduling.manager.tasks.JobRegistry;
 import schedframe.scheduling.plan.impl.Allocation;
 import schedframe.scheduling.plan.impl.ScheduledTask;
@@ -31,17 +28,4 @@
 	public PluginConfiguration getConfiguration() {
 		return plugConf;
-	}
-	
-	public SchedulingResponseType handleResourceAllocationViolation(SchedulingEvent event,
-			TaskQueueList queues, 
-			JobRegistry jobRegistry, 
-					ResourceManager resourceManager, ModuleList modules){
-		SchedulingResponseType responeEvent = null;
-		switch(event.getType()){
-			case TASK_REQUESTED_TIME_EXPIRED: 
-				responeEvent = SchedulingResponseType.KILL_TASK;
-				break;
-		}
-		return responeEvent;
 	}
 	
Index: DCWoRMS/branches/coolemall/src/example/localplugin/FCFSBF_RandomPluginWithMigration.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/localplugin/FCFSBF_RandomPluginWithMigration.java	(revision 1415)
+++ DCWoRMS/branches/coolemall/src/example/localplugin/FCFSBF_RandomPluginWithMigration.java	(revision 1415)
@@ -0,0 +1,141 @@
+package example.localplugin;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import schedframe.events.scheduling.SchedulingEvent;
+import schedframe.resources.ResourceStatus;
+import schedframe.resources.computing.ComputingResource;
+import schedframe.resources.computing.Node;
+import schedframe.resources.computing.Processor;
+import schedframe.resources.units.ProcessingElements;
+import schedframe.resources.units.ResourceUnit;
+import schedframe.resources.units.ResourceUnitName;
+import schedframe.resources.units.StandardResourceUnitName;
+import schedframe.scheduling.manager.resources.ClusterResourceManager;
+import schedframe.scheduling.manager.resources.ResourceManager;
+import schedframe.scheduling.manager.tasks.JobRegistry;
+import schedframe.scheduling.manager.tasks.JobRegistryImpl;
+import schedframe.scheduling.plan.SchedulingPlanInterface;
+import schedframe.scheduling.plan.impl.SchedulingPlan;
+import schedframe.scheduling.plugin.ModuleList;
+import schedframe.scheduling.queue.TaskQueue;
+import schedframe.scheduling.queue.TaskQueueList;
+import schedframe.scheduling.tasks.TaskInterface;
+import dcworms.schedframe.scheduling.ExecTask;
+import example.localplugin.BaseLocalSchedulingPlugin;
+import gridsim.dcworms.DCWormsTags;
+
+public class FCFSBF_RandomPluginWithMigration extends BaseLocalSchedulingPlugin {
+
+	public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry,
+			ResourceManager resManager, ModuleList modules) {
+
+		ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
+		List<Processor> processors = resourceManager.getProcessors();
+		SchedulingPlan plan = new SchedulingPlan();
+		// choose the events types to serve.
+		// Different actions for different events are possible.
+		switch (event.getType()) {
+		case START_TASK_EXECUTION:
+		case TASK_FINISHED:
+		//case TIMER:
+			// our tasks are placed only in first queue (see BaseLocalSchedulingPlugin.placeJobsInQueues() method)
+			TaskQueue q = queues.get(0);
+			// check all tasks in queue
+
+			for (int i = 0; i < q.size(); i++) {
+				TaskInterface<?> task = q.get(i);
+				// if status of the tasks in READY
+				if (task.getStatus() == DCWormsTags.READY) {
+					Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(processors, task);
+					if (choosenResources != null) {
+						addToSchedulingPlan(plan, task, choosenResources);
+					} 
+				}
+			}
+			break;
+		case POWER_LIMIT_EXCEEDED:
+			String src = event.getSource();
+			optimizeEnergyUsage(jobRegistry, resourceManager , src);
+			break;
+
+		}
+		
+		return plan;
+	}
+
+	private void optimizeEnergyUsage(JobRegistry jobRegistry, ClusterResourceManager resourceManager, String resName) {
+		Node overLoadedNode = (Node)resourceManager .getResourceByName(resName);
+		Node leastLoadedNode = findLeastLoadedResource(resourceManager.getNodes());
+		
+		if(leastLoadedNode.getLoadInterface().getRecentUtilization().getValue() >= overLoadedNode.getLoadInterface().getRecentUtilization().getValue()){
+			return;
+		}
+
+		JobRegistry srcHostJr = new JobRegistryImpl(overLoadedNode.getFullName());
+		int runningTasksNumber = srcHostJr.getRunningTasks().size();
+		for(int i = srcHostJr.getRunningTasks().size() - 1; i >= 0 && runningTasksNumber > 2; i--) {
+			ExecTask execTask = srcHostJr.getRunningTasks().get(i);
+			Map<ResourceUnitName, ResourceUnit> destinationResources = chooseResourcesForExecution(findLeastLoadedResource(resourceManager.getNodes()).getProcessors(), execTask);
+			jobRegistry.migrateTask(execTask.getJobId(), execTask.getId(), destinationResources);
+			runningTasksNumber--;
+		}
+	}
+
+	private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution(
+			List<Processor> processors, TaskInterface<?> task) {
+
+		Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>(1);
+
+		int cpuRequest;
+		try {
+			cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
+		} catch (NoSuchFieldException e) {
+			cpuRequest = 0;
+		}
+
+		if (cpuRequest != 0) {
+
+			if (processors.size() < cpuRequest) {
+				return null;
+			}
+
+			List<ComputingResource> choosenResources = new ArrayList<ComputingResource>(cpuRequest);				
+			for (int i = 0; i < processors.size() && cpuRequest > 0; i++) {
+				if (processors.get(i).getStatus() == ResourceStatus.FREE) {
+					choosenResources.add(processors.get(i));
+					cpuRequest--;
+				}
+			}
+			if (cpuRequest > 0) {
+				return null;
+			}
+
+			ProcessingElements pe = new ProcessingElements();
+			pe.addAll(choosenResources);
+			map.put(StandardResourceUnitName.PE, pe);
+			return map;
+		}
+
+		return null;
+	}
+
+	private Node findLeastLoadedResource(List<Node> nodes ){
+		Node leastLoadedNode = null;
+		double minLoad = Double.MAX_VALUE;
+		
+		for(int i = 0; i < nodes.size(); i++){
+			Node node = nodes.get(i);
+			double totalLoad = node.getLoadInterface().getRecentUtilization().getValue();
+			if(totalLoad < minLoad){
+				leastLoadedNode= node;
+				minLoad = totalLoad;
+			}
+		}
+		return leastLoadedNode;
+	}
+
+}
