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_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/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/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;
+	}
+
+}
