Index: /DCWoRMS/trunk/src/test/EventManager.java
===================================================================
--- /DCWoRMS/trunk/src/test/EventManager.java	(revision 780)
+++ /DCWoRMS/trunk/src/test/EventManager.java	(revision 793)
@@ -1,5 +1,9 @@
 package test;
 
+import eduni.simjava.Sim_event;
+import eduni.simjava.Sim_system;
 import gridsim.GridSimCore;
+import gridsim.GridSimTags;
+import gridsim.dcworms.DCWormsTags;
 
 import java.util.ArrayList;
@@ -9,10 +13,8 @@
 
 import schedframe.ResourceController;
+import schedframe.events.Event;
 import schedframe.events.ResourceEventCommand;
-import schedframe.events.scheduling.EventReason;
 import schedframe.exceptions.ModuleException;
 import schedframe.resources.computing.ComputingResource;
-import schedframe.resources.computing.profiles.energy.EnergyEvent;
-import schedframe.resources.computing.profiles.energy.EnergyEventType;
 import schedframe.scheduling.Scheduler;
 import schedframe.scheduling.plugin.grid.Module;
@@ -23,8 +25,48 @@
 	protected ResourceController resourceController;
 	
-	public EventManager(String name) throws Exception {
+	public EventManager(String name, ResourceController resourceController) throws Exception {
 		super(name, 1);
+		this.resourceController = resourceController;
 	}
 
+	public void body() {
+
+
+		// Process events until END_OF_SIMULATION is received from the
+		// GridSimShutdown Entity
+		Sim_event ev = new Sim_event();
+		sim_get_next(ev);
+		boolean run = true;
+		while (Sim_system.running()  && run) {
+			// sim_get_next(ev);
+			// if the simulation finishes then exit the loop
+			if (ev.get_tag() == GridSimTags.END_OF_SIMULATION) {
+				// managemetnSystem_.setEndSimulation();
+				run = false;
+				break;
+			}
+			
+			// process the received event
+			processRequest(ev);
+			sim_get_next(ev);
+		}
+	}
+	
+	protected void processRequest(Sim_event ev) {
+		switch (ev.get_tag()) {
+
+		case DCWormsTags.TO_COMP_RESOURCES:
+			sendToResources(ev);
+			break;
+
+		case DCWormsTags.TO_SCHEDULERS:
+			//super.send((Integer)ev.get_data(), 0, DCWormsTags.PHASE_CHANGED, null);
+			break;
+
+		default:
+			break;
+		}
+	}
+	
 	public void send(String entityName, double delay, int tag, Object data){
 		super.send(entityName, delay, tag, data);
@@ -61,10 +103,12 @@
 		}
 		
+		
 		for(Scheduler scheduler: allSchedulers){
+			//sendInternal(delay, DCWormsTags.TO_SCHEDULERS, scheduler.get_id());
 			super.send(scheduler.get_id(), delay, tag, data);
 		}
 	}
 	
-	public void sendToAllResources(double delay, int tag, Object data){
+	public void sendToAllResources(double delay, Event event){
 		List<ComputingResource> allComputingResources = new ArrayList<ComputingResource>();
 
@@ -87,19 +131,24 @@
 			}
 		}
+		sendInternal(delay, DCWormsTags.TO_COMP_RESOURCES, new ResourceBroadcastOrder(allComputingResources, event));
+	}
+
+	private void sendToResources(Sim_event ev){
+		ResourceEventCommand rec;
 		
-		ResourceEventCommand rec;
-		EnergyEvent event;
+		ResourceBroadcastOrder rbo = (ResourceBroadcastOrder)ev.get_data();
+		List<ComputingResource> allComputingResources = rbo.getComputingResources();
+		Event event = rbo.getEvent();
 		for(ComputingResource compRes: allComputingResources){
 			rec = new ResourceEventCommand(compRes);
-			event = new EnergyEvent(EnergyEventType.AIRFLOW_STATE_CHANGED, "Resource controller");
-			event.setReason(EventReason.SIM_INIT);
 			rec.execute(event);
-			//super.send(scheduler.get_id(), delay, tag, data);
 		}
-
+	}
+	
+	public void sendInternal(double delay, int tag, Object data) {
+		this.send(this.get_id(), delay, tag, data);
 	}
 	
 	public void sendTo(List<String> ids){
-		
 	}
 	
@@ -112,2 +161,24 @@
 
 }
+
+class ResourceBroadcastOrder {
+
+	private List<ComputingResource> computingResources;
+	private Event event;
+	
+	public ResourceBroadcastOrder(List<ComputingResource> computingResources, Event event) {
+		super();
+		this.computingResources = computingResources;
+		this.event = event;
+	}
+
+	public List<ComputingResource> getComputingResources() {
+		return computingResources;
+	}
+
+	public Event getEvent() {
+		return event;
+	}
+}
+
+
