/** Reads jobs from data_set file and sends them to the Scheduler entity dynamically over time. */ public void body() { super.gridSimHold(10.0); // hold by 10 second while (current_gl < total_jobs) { Sim_event ev = new Sim_event(); sim_get_next(ev); if (ev.get_tag() == AleaSimTags.EVENT_WAKE) { ComplexGridlet gl = readGridlet(current_gl); current_gl++; if (gl == null && current_gl < total_jobs) { super.sim_schedule(this.getEntityId(this.getEntityName()), 0.0, AleaSimTags.EVENT_WAKE); continue; } else if (gl == null && current_gl >= total_jobs) { continue; } // to synchronize job arrival wrt. the data set. double delay = Math.max(0.0, (gl.getArrival_time() - super.clock())); // some time is needed to transfer this job to the scheduler, i.e., delay should be delay = // delay - transfer_time. Fix this in the future. // System.out.println("Sending: "+gl.getGridletID()); last_delay = delay; super.sim_schedule( this.getEntityId("Alea_3.0_scheduler"), delay, AleaSimTags.GRIDLET_INFO, gl); delay = Math.max(0.0, (gl.getArrival_time() - super.clock())); if (current_gl < total_jobs) { // use delay - next job will be loaded after the simulation time is equal to the previous // job arrival. super.sim_schedule(this.getEntityId(this.getEntityName()), delay, AleaSimTags.EVENT_WAKE); } continue; } } System.out.println("Shuting down - last gridlet = " + current_gl + " of " + total_jobs); super.sim_schedule( this.getEntityId("Alea_3.0_scheduler"), Math.round(last_delay + 2), AleaSimTags.SUBMISSION_DONE, new Integer(current_gl)); Sim_event ev = new Sim_event(); sim_get_next(ev); if (ev.get_tag() == GridSimTags.END_OF_SIMULATION) { System.out.println( "Shuting down the " + data_set + "_PWALoader... with: " + fail + " failed or skipped jobs"); } shutdownUserEntity(); super.terminateIOEntities(); }
/** The core method that handles communications among GridSim entities. */ public void body() { // wait for a little while for about 3 seconds. // This to give a time for GridResource entities to register their // services to GIS (GridInformationService) entity. super.gridSimHold(3.0); LinkedList resList = super.getGridResourceList(); // initialises all the containers int totalResource = resList.size(); int resourceID[] = new int[totalResource]; String resourceName[] = new String[totalResource]; // a loop to get all the resources available int i = 0; for (i = 0; i < totalResource; i++) { // Resource list contains list of resource IDs resourceID[i] = ((Integer) resList.get(i)).intValue(); // get their names as well resourceName[i] = GridSim.getEntityName(resourceID[i]); } //////////////////////////////////////////////// // SUBMIT Gridlets // determines which GridResource to send to int index = myId_ % totalResource; if (index >= totalResource) { index = 0; } // sends all the Gridlets Gridlet gl = null; boolean success; for (i = 0; i < list_.size(); i++) { gl = (Gridlet) list_.get(i); // For even number of Gridlets, send with an acknowledgement if (i % 2 == 0) { success = super.gridletSubmit(gl, resourceID[index], 0.0, true); System.out.println( name_ + ": Sending Gridlet #" + gl.getGridletID() + " with status = " + success + " to " + resourceName[index]); } // For odd number of Gridlets, send without an acknowledgement else { success = super.gridletSubmit(gl, resourceID[index], 0.0, false); System.out.println( name_ + ": Sending Gridlet #" + gl.getGridletID() + " with NO ACK so status = " + success + " to " + resourceName[index]); } } ////////////////////////////////////////// // CANCELING Gridlets // hold for few period -- 100 seconds super.gridSimHold(15); System.out.println("<<<<<<<<< pause for 15 >>>>>>>>>>>"); // a loop that cancels an even number of Gridlet for (i = 0; i < list_.size(); i++) { if (i % 2 == 0) { gl = super.gridletCancel(i, myId_, resourceID[index], 0.0); System.out.print(name_ + ": Canceling Gridlet #" + i + " at time = " + GridSim.clock()); if (gl == null) { System.out.println(" result = NULL"); } else // if Cancel is successful, then add it into the list { System.out.println(" result = NOT null"); receiveList_.add(gl); } } } //////////////////////////////////////////////////////// // RECEIVES Gridlets back // hold for few period - 1000 seconds since the Gridlets length are // quite huge for a small bandwidth super.gridSimHold(1000); System.out.println("<<<<<<<<< pause for 1000 >>>>>>>>>>>"); // receives the gridlet back int size = list_.size() - receiveList_.size(); for (i = 0; i < size; i++) { gl = (Gridlet) super.receiveEventObject(); // gets the Gridlet receiveList_.add(gl); // add into the received list System.out.println( name_ + ": Receiving Gridlet #" + gl.getGridletID() + " at time = " + GridSim.clock()); } System.out.println(this.name_ + ":%%%% Exiting body() at time " + GridSim.clock()); // shut down I/O ports shutdownUserEntity(); terminateIOEntities(); // Prints the simulation output printGridletList(receiveList_, name_); }