Index: xssim/branches/tpiontek/src/test/rewolucja/energy/profile/implementation/CPUPowerProfile.java
===================================================================
--- xssim/branches/tpiontek/src/test/rewolucja/energy/profile/implementation/CPUPowerProfile.java	(revision 241)
+++ xssim/branches/tpiontek/src/test/rewolucja/energy/profile/implementation/CPUPowerProfile.java	(revision 252)
@@ -103,5 +103,9 @@
 	
 	public boolean setPState(PStateType pStateType){
+			
 		PState newPState = getSupportedPStates().get(pStateType);
+		
+		if( newPState == getPState())
+			return false;
 		
 		if(newPState != null)
Index: xssim/branches/tpiontek/src/test/rewolucja/energy/profile/implementation/CPU_B_PowerProfile.java
===================================================================
--- xssim/branches/tpiontek/src/test/rewolucja/energy/profile/implementation/CPU_B_PowerProfile.java	(revision 241)
+++ xssim/branches/tpiontek/src/test/rewolucja/energy/profile/implementation/CPU_B_PowerProfile.java	(revision 252)
@@ -23,7 +23,7 @@
 		static {
 			Map<PStateType, PState> pStatesMap = new HashMap<PStateType, PState>();
-			pStatesMap.put(PStateType.P0, new PState(PStateType.P0, 2200, 0, 19));
-			pStatesMap.put(PStateType.P1, new PState(PStateType.P1, 2000, 0, 16));
-			pStatesMap.put(PStateType.P2, new PState(PStateType.P2, 1800, 0, 14));
+			pStatesMap.put(PStateType.P0, new PState(PStateType.P0, 2200, 0, 20));
+			pStatesMap.put(PStateType.P1, new PState(PStateType.P1, 2000, 0, 17));
+			pStatesMap.put(PStateType.P2, new PState(PStateType.P2, 1800, 0, 16));
 			pStatesMap.put(PStateType.P3, new PState(PStateType.P3, 1000, 0, 10));
 			pStates = Collections.unmodifiableMap(pStatesMap);
Index: xssim/branches/tpiontek/src/example/localplugin/FCFSRandomClusterLocalPlugin.java
===================================================================
--- xssim/branches/tpiontek/src/example/localplugin/FCFSRandomClusterLocalPlugin.java	(revision 250)
+++ xssim/branches/tpiontek/src/example/localplugin/FCFSRandomClusterLocalPlugin.java	(revision 252)
@@ -42,5 +42,5 @@
 			
 			for( Processor cpu : cpus)
-				cpu.getPowerInterface().setPState( PStateType.P3);
+				cpu.getPowerInterface().setPState( PStateType.P0);
 			
 			init = false;
Index: xssim/branches/tpiontek/src/example/localplugin/FCFSPreferedRandomClusterLocalPlugin.java
===================================================================
--- xssim/branches/tpiontek/src/example/localplugin/FCFSPreferedRandomClusterLocalPlugin.java	(revision 252)
+++ xssim/branches/tpiontek/src/example/localplugin/FCFSPreferedRandomClusterLocalPlugin.java	(revision 252)
@@ -0,0 +1,169 @@
+package example.localplugin;
+
+import gridsim.Gridlet;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.Random;
+
+import schedframe.scheduling.TaskInterface;
+import schedframe.scheduling.events.SchedulingEvent;
+import schedframe.scheduling.plugin.grid.ModuleList;
+import test.rewolucja.GSSIMJobInterface;
+import test.rewolucja.energy.profile.PStateType;
+import test.rewolucja.resources.ResourceStatus;
+import test.rewolucja.resources.manager.implementation.ClusterResourceManager;
+import test.rewolucja.resources.manager.interfaces.ResourceManagerInterface;
+import test.rewolucja.resources.physical.implementation.ComputingNode;
+import test.rewolucja.resources.physical.implementation.Processor;
+import test.rewolucja.scheduling.JobRegistryInterface;
+import test.rewolucja.scheduling.plan.SchedulingPlanInterfaceNew;
+import test.rewolucja.scheduling.plan.SchedulingPlanNew;
+import test.rewolucja.scheduling.queue.Queue;
+import test.rewolucja.scheduling.queue.QueueList;
+
+public class FCFSPreferedRandomClusterLocalPlugin extends BaseLocalPlugin {
+
+	private Random rand;
+	private boolean init = true;
+	
+	public FCFSPreferedRandomClusterLocalPlugin() {
+		rand = new Random(5);
+	}
+
+	public SchedulingPlanInterfaceNew schedule(SchedulingEvent event, QueueList queues, JobRegistryInterface jobRegistry,
+			 ResourceManagerInterface resManager, ModuleList modules) {
+		
+		ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
+		
+		if( init)
+		{
+			List<Processor> cpus = resourceManager.getProcessors();
+			
+			for( Processor cpu : cpus)
+				cpu.getPowerInterface().setPState( PStateType.P0);
+			
+			init = false;
+		}
+		
+
+		
+		SchedulingPlanNew plan = new SchedulingPlanNew();
+		// chose 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
+			// BaseLocalPlugin.placeJobsInQueues() method)
+			Queue q = queues.get(0);
+			// check all tasks in queue
+
+			for (int i = 0; i < q.size(); i++) {
+				GSSIMJobInterface<?> job = q.get(i);
+				TaskInterface<?> task = (TaskInterface<?>) job;
+				// if status of the tasks in READY
+				if (task.getStatus() == Gridlet.READY) {
+					String nodeName = chooseRandomProvider(resourceManager, task);
+					if (nodeName != null) {
+						addToSchedulingPlan(plan, task, nodeName);
+					}
+				}
+			}
+			
+			int scenario = 0;
+			switch( scenario)
+			{
+				case 0: break;
+				case 1: ;
+				
+				List<Processor> cpus = resourceManager.getProcessors();
+				for( Processor cpu : cpus)
+				{
+					switch( cpu.getStatus())
+					{
+						case FREE: cpu.getPowerInterface().setPState( PStateType.P3); break;
+						case PENDING: cpu.getPowerInterface().setPState( PStateType.P0); break;
+					}
+					
+				}
+				break;
+				default: break;
+			}
+			
+			break;
+		}
+		return plan;
+	}
+
+	private List<ComputingNode> findSuitableNodes(String model, int cpuRequest, List<ComputingNode> nodes){
+		List<ComputingNode> avNodes = new ArrayList<ComputingNode>();
+		for(ComputingNode node: nodes){
+			if( (model == null || node.getCategory().getName().equals(model)) && node.getFreeProcessorsNumber() >= cpuRequest){
+				avNodes.add(node);
+			}
+		}
+		return avNodes;
+	}
+	
+	private String chooseRandomProvider(ClusterResourceManager resourceManager, TaskInterface<?> task) {
+		
+		int cpuRequest;
+		try {
+			cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
+		} catch (NoSuchFieldException e) {
+			cpuRequest = 1;
+		}
+		
+		List<ComputingNode> nodes = null;
+		
+		String prefered = null;
+		
+		nodes = findSuitableNodes(prefered, cpuRequest, resourceManager.getComputingNodes());
+		if( nodes.size() > 0)
+		{	
+			int nodeIdx = rand.nextInt(nodes.size());
+			ComputingNode node = nodes.get(nodeIdx);
+			
+			//for( Processor cpu : node.getFreeProcessors())
+			//	if( cpu.getPowerInterface().getPState().getName() != PStateType.P0)
+			//		cpu.getPowerInterface().setPState( PStateType.P0);
+			
+			return node.getName();
+		}
+		
+		if( prefered != null)
+		{	
+			if( prefered.equals("A"))
+				prefered = "B";
+			else
+				prefered = "A";
+			
+			nodes = findSuitableNodes(prefered, cpuRequest, resourceManager.getComputingNodes());
+			if( nodes.size() > 0)
+			{	
+				int nodeIdx = rand.nextInt(nodes.size());
+				ComputingNode node = nodes.get(nodeIdx);
+				
+				//for( Processor cpu : node.getFreeProcessors())
+				//	if( cpu.getPowerInterface().getPState().getName() != PStateType.P0)
+				//		cpu.getPowerInterface().setPState( PStateType.P0);
+				
+				return node.getName();
+			}
+		}
+			
+		return null;
+	}
+	
+	public String getName() {
+		return getClass().getName();
+	}
+
+	public void init(Properties properties) {
+		// no extra initialization is expected.
+	}
+
+}
+
