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