Index: /xssim/branches/tpiontek/src/example/localplugin/FCFSConsolidationClusterLocalPlugin.java
===================================================================
--- /xssim/branches/tpiontek/src/example/localplugin/FCFSConsolidationClusterLocalPlugin.java	(revision 269)
+++ /xssim/branches/tpiontek/src/example/localplugin/FCFSConsolidationClusterLocalPlugin.java	(revision 270)
@@ -2,4 +2,6 @@
 
 import gridsim.Gridlet;
+import gridsim.gssim.ResourceHistoryItem;
+import gridsim.gssim.SubmittedTask;
 
 import java.util.ArrayList;
@@ -12,10 +14,18 @@
 import schedframe.scheduling.TaskInterface;
 import schedframe.scheduling.events.SchedulingEvent;
+import schedframe.scheduling.events.TaskFinishedEvent;
 import schedframe.scheduling.plugin.grid.ModuleList;
+import schedframe.scheduling.utils.ResourceParameterName;
 import test.rewolucja.GSSIMJobInterface;
+import test.rewolucja.resources.ProcessingElements;
+import test.rewolucja.resources.ResourceStatus;
+import test.rewolucja.resources.ResourceType;
 import test.rewolucja.resources.manager.implementation.ClusterResourceManager;
 import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface;
+import test.rewolucja.resources.physical.base.ComputingResource;
 import test.rewolucja.resources.physical.implementation.ComputingNode;
+import test.rewolucja.resources.physical.implementation.Processor;
 import test.rewolucja.scheduling.JobRegistryInterface;
+import test.rewolucja.scheduling.UsedResourceList;
 import test.rewolucja.scheduling.plan.SchedulingPlanInterfaceNew;
 import test.rewolucja.scheduling.plan.SchedulingPlanNew;
@@ -38,6 +48,17 @@
 		// Different actions for different events are possible.
 		switch (event.getType()) {
-		case START_TASK_EXECUTION:
 		case TASK_FINISHED:
+			if( scenario == 1)
+			{	
+				TaskFinishedEvent finEvent = (TaskFinishedEvent) event;
+				SubmittedTask subTask = jobRegistry.getSubmittedTask(finEvent.getJobId(), finEvent.getTaskId());
+				UsedResourceList<ResourceHistoryItem> usedResourcesList = subTask.getUsedResources();
+				ProcessingElements pes = (ProcessingElements)usedResourcesList.getLast().getResourceUnits().get(ResourceParameterName.PROCESSINGELEMENTS);
+				
+				ComputingNode cn = ((Processor)pes.get(0)).getComputingNode();
+				if( cn.getFreeProcessors().size() == cn.getProcessorsNumber())
+					cn.getPowerInterface().setPowerState( PowerState.OFF);
+			}
+		case START_TASK_EXECUTION: 
 			// our tasks are placed only in first queue (see
 			// BaseLocalPlugin.placeJobsInQueues() method)
@@ -52,7 +73,9 @@
 
 					ComputingNode node = chooseResourcesForExecution(resourceManager, PowerState.ON, task);
+					
 					if (node  != null) {
-						System.out.println("Uruchamiam na zasobie: " + node.getName());
-						addToSchedulingPlan(plan, task, node.getName());
+						List<Processor> cpus = chooseProcessorsForExecution(node, ResourceStatus.FREE, task);
+						//System.out.println("Uruchamiam na zasobie: " + node.getName());
+						addToSchedulingPlan(plan, task, cpus);
 					} 
 					else
@@ -62,5 +85,5 @@
 						if( node != null)
 						{
-							System.out.println("Wlaczam wezel: " + node.getName());
+							//System.out.println("Wlaczam wezel: " + node.getName());
 							node.getPowerInterface().setPowerState( PowerState.ON);
 							i--;
@@ -78,5 +101,7 @@
 						if( node.getFreeProcessors().size() == node.getProcessorsNumber())
 						{
+							//System.out.println("Wylaczam zasob" + node.getName());
 							node.getPowerInterface().setPowerState( PowerState.OFF);
+							//System.out.println("Zasob  w stanie: " + node.getPowerInterface().getPowerState());
 						}
 					break;
@@ -86,4 +111,5 @@
 			break;
 		}
+		
 		return plan;
 	}
@@ -91,4 +117,6 @@
 	private ComputingNode chooseResourcesForExecution(ClusterResourceManager resourceManager, PowerState status, TaskInterface<?> task) {
 
+		//System.out.println("Szukam zasobow w stanie: "  +status);
+		
 		List<ComputingNode> nodes = resourceManager.getComputingNodes();
 		nodes = findSuitableNodes(task, status, nodes);
@@ -107,19 +135,19 @@
 	
 	private List<ComputingNode> findSuitableNodes(TaskInterface<?> task, PowerState status, List<ComputingNode> nodes){
-		int cpuRequest;
-		try {
-			cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
-		} catch (NoSuchFieldException e) {
-			cpuRequest = 1;
-		}
+		
+		int cpuRequest = getCpuRequest(task);
 		
 		List<ComputingNode> suitableNodes = new ArrayList<ComputingNode>();
+			
 		for(ComputingNode node: nodes)
 		{
+			if( node.getPowerInterface().getPowerState() == status)
 				switch( status)
 				{
 					case ON:
 						if(node.getFreeProcessorsNumber() >= cpuRequest)
+						{
 							suitableNodes.add(node);
+						}	
 						break;
 					case OFF:
@@ -140,4 +168,26 @@
 		// no extra initialization is expected.
 	}
+	
+	private List<Processor> chooseProcessorsForExecution( 
+			ComputingNode node, ResourceStatus status, TaskInterface<?> task) {
+		
+		int cpuRequest = getCpuRequest(task);
 
+		List<Processor> cpus = (List<Processor>)node.getDescendantsByTypeAndStatus( ResourceType.CPU, status);
+		
+		return cpus.subList(0, cpuRequest);
+	}
+	
+	private int getCpuRequest( TaskInterface<?> task)
+	{
+		int cpuRequest;
+		
+		try {
+			cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
+		} catch (NoSuchFieldException e) {
+			cpuRequest = 1;
+		}
+		
+		return cpuRequest;
+	}
 }
