Index: DCWoRMS/branches/coolemall/src/example/energy/recs/ProcessorEnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/trunk/src/example/energy/recs/ProcessorEnergyEstimationPlugin.java	(revision 783)
+++ DCWoRMS/branches/coolemall/src/example/energy/recs/ProcessorEnergyEstimationPlugin.java	(revision 883)
@@ -6,4 +6,5 @@
 import schedframe.resources.computing.Processor;
 import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.EnergyEventType;
 import schedframe.resources.computing.profiles.energy.power.StandardPowerStateName;
 import schedframe.scheduling.manager.tasks.JobRegistry;
@@ -20,9 +21,11 @@
 			try {
 				if(resource.getStatus() == ResourceStatus.BUSY)
-					powerConsumption = cpu.getPowerInterface().getPowerConsumption(cpu.getPowerInterface().getPState());
+					powerConsumption = 60;
+					//powerConsumption = cpu.getPowerInterface().getPowerConsumption(cpu.getPowerInterface().getPState());
 				else {
-					powerConsumption = cpu.getPowerInterface().getPowerConsumption(StandardPowerStateName.ON);
+					powerConsumption = 10;
+					//powerConsumption = cpu.getPowerInterface().getPowerConsumption(StandardPowerStateName.ON);
 				}
-			} catch (NoSuchFieldException e) {
+			} catch (Exception e) {
 				try {
 					powerConsumption = cpu.getPowerInterface().getPowerConsumption(StandardPowerStateName.ON);
@@ -32,4 +35,6 @@
 			}
 		}
+		if(event.getType() == EnergyEventType.RESOURCE_UTILIZATION_CHANGED)
+			powerConsumption = powerConsumption/2;
 		return powerConsumption;
 	}
Index: DCWoRMS/branches/coolemall/src/example/energy/CPUEnergyEstimationPlugin.java
===================================================================
--- DCWoRMS/trunk/src/example/energy/CPUEnergyEstimationPlugin.java	(revision 580)
+++ DCWoRMS/branches/coolemall/src/example/energy/CPUEnergyEstimationPlugin.java	(revision 883)
@@ -17,17 +17,27 @@
 			powerConsumption = 0;
 		else {
-			try {
-				if(resource.getStatus() == ResourceStatus.BUSY)
+			if(resource.getStatus() == ResourceStatus.BUSY){
+				try {
+
 					powerConsumption = cpu.getPowerInterface().getPowerConsumption(cpu.getPowerInterface().getPState());
-				else {
-					powerConsumption = cpu.getPowerInterface().getPowerConsumption(StandardPowerStateName.ON);
+				} catch (NoSuchFieldException e) {
+					try {
+						powerConsumption = cpu.getPowerInterface().getPowerConsumption(StandardPowerStateName.ON);
+					} catch (NoSuchFieldException e1) {
+						powerConsumption = 10;
+					}
 				}
-			} catch (NoSuchFieldException e) {
+			} else{
 				try {
-					powerConsumption = cpu.getPowerInterface().getPowerConsumption(StandardPowerStateName.ON);
-				} catch (NoSuchFieldException e1) {
-					powerConsumption = 10;
+					powerConsumption = cpu.getPowerInterface().getPowerConsumption(cpu.getPowerInterface().getPState());
+				} catch (NoSuchFieldException e) {
+					try {
+						powerConsumption = cpu.getPowerInterface().getPowerConsumption(StandardPowerStateName.ON);
+					} catch (NoSuchFieldException e1) {
+						powerConsumption = 0;
+					}
 				}
 			}
+			
 		}
 		return powerConsumption;
Index: DCWoRMS/branches/coolemall/src/example/localplugin/FCFSBF_LocalPlugin.java
===================================================================
--- DCWoRMS/trunk/src/example/localplugin/FCFSBF_LocalPlugin.java	(revision 574)
+++ DCWoRMS/branches/coolemall/src/example/localplugin/FCFSBF_LocalPlugin.java	(revision 883)
@@ -2,5 +2,8 @@
 
 import gridsim.dcworms.DCWormsTags;
+import schedframe.events.scheduling.EventReason;
 import schedframe.events.scheduling.SchedulingEvent;
+import schedframe.resources.computing.profiles.energy.EnergyEvent;
+import schedframe.resources.computing.profiles.energy.EnergyEventType;
 import schedframe.scheduling.manager.resources.ResourceManager;
 import schedframe.scheduling.manager.tasks.JobRegistry;
@@ -10,4 +13,6 @@
 import schedframe.scheduling.queue.TaskQueueList;
 import schedframe.scheduling.tasks.TaskInterface;
+import simulator.DataCenterWorkloadSimulator;
+import test.EventManager;
 
 public class FCFSBF_LocalPlugin extends BaseLocalSchedulingPlugin {
@@ -28,5 +33,9 @@
 			for (int i = 0; i < q.size(); i++) {
 				TaskInterface<?> task = q.get(i);
-				
+				//EventManager em = DataCenterWorkloadSimulator.getEventManager();
+				//EnergyEvent energyEvent = new EnergyEvent(EnergyEventType.AIRFLOW_STATE_CHANGED, "Resource controller");
+				//energyEvent.setReason(EventReason.SIM_INIT);
+				//em.sendToAllResources(40000, energyEvent);
+				//em.sendToAllSchedulers(40000, DCWormsTags.UPDATE_PROCESSING, new String("test"));
 				// if status of the tasks in READY
 				if (task.getStatus() == DCWormsTags.READY) {
Index: DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/recs/RECS_Consolidation_SP.java
===================================================================
--- DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/recs/RECS_Consolidation_SP.java	(revision 883)
+++ DCWoRMS/branches/coolemall/src/example/localplugin/coolemall/recs/RECS_Consolidation_SP.java	(revision 883)
@@ -0,0 +1,193 @@
+package example.localplugin.coolemall.recs;
+
+import example.localplugin.BaseLocalSchedulingPlugin;
+import gridsim.dcworms.DCWormsTags;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import schedframe.events.scheduling.SchedulingEvent;
+import schedframe.exceptions.ResourceException;
+import schedframe.resources.ResourceStatus;
+import schedframe.resources.UserResourceType;
+import schedframe.resources.computing.ComputingNode;
+import schedframe.resources.computing.ComputingResource;
+import schedframe.resources.computing.Core;
+import schedframe.resources.computing.Processor;
+import schedframe.resources.computing.profiles.energy.power.StandardPowerStateName;
+import schedframe.resources.computing.recs.Node;
+import schedframe.resources.units.Memory;
+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.grid.ModuleList;
+import schedframe.scheduling.queue.TaskQueue;
+import schedframe.scheduling.queue.TaskQueueList;
+import schedframe.scheduling.tasks.TaskInterface;
+
+public class RECS_Consolidation_SP extends BaseLocalSchedulingPlugin {
+
+	public RECS_Consolidation_SP () {
+	}
+
+	public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry,
+			ResourceManager resManager, ModuleList modules) {
+
+		ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
+		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:
+			// our tasks are placed only in first queue (see
+			// BaseLocalSchedulingPlugin.placeJobsInQueues() method)
+			TaskQueue q = queues.get(0);
+			// check all tasks in queue
+			List<Node> nodes;
+			try {
+				nodes = (List<Node>) resourceManager.getResourcesOfType(new UserResourceType("Node"));
+			} catch (ResourceException e) {
+				break;
+			}
+			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 = null;
+					try {
+						choosenResources = chooseResourcesForExecution(nodes, task);
+					} catch (NoSuchFieldException e) {
+						// TODO Auto-generated catch block
+						e.printStackTrace();
+					}
+					if (choosenResources  != null) {
+						addToSchedulingPlan(plan, task, choosenResources);
+					} 
+				}
+			}
+			turnOffIdleNodes(nodes);
+
+			break;
+		}
+		return plan;
+	}
+	
+	private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution(List<Node> nodes, TaskInterface<?> task) throws NoSuchFieldException {
+
+		nodes = findSuitableNodes(task, nodes);
+		Collections.sort(nodes, new Comparator<Node>(){
+		    public int compare(Node node1, Node node2){   
+		    	int freeCores1 = 0, freeCores2 = 0;
+		    	int freeCpus1 = 0, freeCpus2 = 0;
+		    	
+		    	List<Processor> processors1 = node1.getProcessors();
+		    	for(Processor processor: processors1){
+		    		freeCores1 = freeCores1 + processor.getFreeCores().size();
+		    	}
+		    	
+		    	List<Processor> processors2 = node2.getProcessors();
+		    	for(Processor processor: processors2){
+		    		freeCores2 = freeCores2 + processor.getFreeCores().size();
+		    	}
+		    	
+		    	if(freeCores1 == 0 && freeCores2 == 0){
+		    		freeCpus1 = node1.getFreeProcessorsNumber();
+		    		freeCpus2 = node2.getFreeProcessorsNumber();
+		    		
+		    		if(freeCpus1 > freeCpus2) {
+		    			return -1;
+		    		} else if(freeCpus1 < freeCpus2) {
+		    			return 1;
+		    		} else {
+		    			return 0;
+		    		}
+		    	} else {
+		    		if(freeCores1 > freeCores2) {
+		    			return -1;
+		    		} else if(freeCores1 < freeCores2) {
+		    			return 1;
+		    		} else {
+		    			return 0;
+		    		}
+		    	}
+		    }
+		});
+		if(nodes.size() > 0)
+		{
+			Node node = nodes.get(0);
+			Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>();
+			List<ComputingResource> choosenResources =  new ArrayList<ComputingResource>();
+			int cpuRequest;
+			try {
+				cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
+			} catch (NoSuchFieldException e) {
+				cpuRequest = 0;
+			}
+			for (int i = 0; i < node.getProcessors().size() && cpuRequest > 0; i++) {
+				if (node.getProcessors().get(i).getStatus() == ResourceStatus.FREE) {
+					choosenResources.add(node.getProcessors().get(i));
+					cpuRequest--;
+				}
+			}
+			ProcessingElements result = new ProcessingElements(node.getName());
+			result.addAll(choosenResources);
+			map.put(StandardResourceUnitName.PE, result);
+			
+			int memoryRequest;
+			try {
+				memoryRequest = Double.valueOf(task.getMemoryRequest()).intValue();
+			} catch (NoSuchFieldException e) {
+				memoryRequest = 0;
+			}
+			if (memoryRequest != 0) {
+				Memory memory = new Memory(node.getMemory(), memoryRequest, memoryRequest);
+				map.put(StandardResourceUnitName.MEMORY, memory);
+			}
+			return map;
+		} else 
+			return null;
+	}
+	
+	private List<Node> findSuitableNodes(TaskInterface<?> task, List<Node> nodes) throws NoSuchFieldException{
+		int cpuRequest;
+		try {
+			cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
+		} catch (NoSuchFieldException e) {
+			cpuRequest = 1;
+		}
+		int memoryRequest;
+		try {
+			memoryRequest = Double.valueOf(task.getMemoryRequest()).intValue();
+		} catch (NoSuchFieldException e) {
+			memoryRequest = 0;
+		}
+		List<Node> suitableNodes = new ArrayList<Node>();
+		for(Node node: nodes){
+			if(node.getFreeProcessorsNumber() >= cpuRequest && node.getFreeMemory() >= memoryRequest){
+				suitableNodes.add(node);
+			}
+		}
+		return suitableNodes;
+	}
+
+	private void turnOffIdleNodes(List<Node> nodes){
+		for(Node node : nodes){
+			JobRegistry jr = new JobRegistryImpl(node.getName());
+			if(jr.getRunningTasks().size() == 0)
+				node.getPowerInterface().setPowerState(StandardPowerStateName.OFF);
+		}
+	}
+}
