From: <mar...@us...> - 2009-04-03 04:28:33
|
Revision: 260 http://gridsim.svn.sourceforge.net/gridsim/?rev=260&view=rev Author: marcos_dias Date: 2009-04-03 04:28:19 +0000 (Fri, 03 Apr 2009) Log Message: ----------- Several methods of allocation policies have been made synchronised because under a scenario with a large number of simulation events, or the absence of network links, GridResource and allocation policy could change attributes of the policy at the same time. Modified Paths: -------------- trunk/source/gridsim/SpaceShared.java trunk/source/gridsim/TimeShared.java trunk/source/gridsim/resFailure/FailureMsg.java trunk/source/gridsim/resFailure/GridResourceWithFailure.java trunk/source/gridsim/resFailure/RegionalGISWithFailure.java trunk/source/gridsim/resFailure/SpaceSharedWithFailure.java trunk/source/gridsim/resFailure/TimeSharedWithFailure.java Modified: trunk/source/gridsim/SpaceShared.java =================================================================== --- trunk/source/gridsim/SpaceShared.java 2008-11-16 10:42:53 UTC (rev 259) +++ trunk/source/gridsim/SpaceShared.java 2009-04-03 04:28:19 UTC (rev 260) @@ -23,6 +23,7 @@ * * @author Manzur Murshed and Rajkumar Buyya * @author Anthony Sulistio (re-written this class) + * @author Marcos Dias de Assuncao (has made some methods synchronized) * @since GridSim Toolkit 2.2 * @see gridsim.GridSim * @see gridsim.ResourceCharacteristics @@ -94,7 +95,7 @@ // if the simulation finishes then exit the loop if (ev.get_tag() == GridSimTags.END_OF_SIMULATION || - super.isEndSimulation() == true) + super.isEndSimulation()) { break; } @@ -128,7 +129,7 @@ * @pre gl != null * @post $none */ - public void gridletSubmit(Gridlet gl, boolean ack) + public synchronized void gridletSubmit(Gridlet gl, boolean ack) { // update the current Gridlets in exec list up to this point in time updateGridletProcessing(); @@ -160,14 +161,14 @@ } // if no available PE then put the ResGridlet into a Queue list - if (success == false) + if (!success) { rgl.setGridletStatus(Gridlet.QUEUED); gridletQueueList_.add(rgl); } // sends back an ack if required - if (ack == true) + if (ack) { super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, true, gl.getGridletID(), gl.getUserID() @@ -185,7 +186,7 @@ * @pre userId > 0 * @post $none */ - public int gridletStatus(int gridletId,int userId) + public synchronized int gridletStatus(int gridletId,int userId) { ResGridlet rgl = null; @@ -247,7 +248,7 @@ * @pre userId > 0 * @post $none */ - public void gridletCancel(int gridletId, int userId) + public synchronized void gridletCancel(int gridletId, int userId) { // cancels a Gridlet ResGridlet rgl = cancel(gridletId, userId); @@ -292,7 +293,7 @@ * @pre userId > 0 * @post $none */ - public void gridletPause(int gridletId, int userId, boolean ack) + public synchronized void gridletPause(int gridletId, int userId, boolean ack) { boolean status = false; @@ -354,7 +355,7 @@ } // sends back an ack if required - if (ack == true) + if (ack) { super.sendAck(GridSimTags.GRIDLET_PAUSE_ACK, status, gridletId, userId); @@ -382,7 +383,7 @@ * @pre destId > 0 * @post $none */ - public void gridletMove(int gridletId, int userId, int destId, boolean ack) + public synchronized void gridletMove(int gridletId, int userId, int destId, boolean ack) { // cancels the Gridlet ResGridlet rgl = cancel(gridletId, userId); @@ -394,7 +395,7 @@ ".SpaceShared.gridletMove(): Cannot find " + "Gridlet #" + gridletId + " for User #" + userId); - if (ack == true) // sends back an ack if required + if (ack) // sends back an ack if required { super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, false, gridletId, userId); @@ -411,7 +412,7 @@ + gridletId + " for User #" + userId + " since it has FINISHED."); - if (ack == true) // sends back an ack if required + if (ack) // sends back an ack if required { super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, false, gridletId, userId); @@ -445,7 +446,7 @@ * @pre userId > 0 * @post $none */ - public void gridletResume(int gridletId, int userId, boolean ack) + public synchronized void gridletResume(int gridletId, int userId, boolean ack) { boolean status = false; @@ -468,7 +469,7 @@ } // otherwise put into Queue list - if (success == false) + if (!success) { rgl.setGridletStatus(Gridlet.QUEUED); gridletQueueList_.add(rgl); @@ -486,7 +487,7 @@ } // sends back an ack if required - if (ack == true) + if (ack) { super.sendAck(GridSimTags.GRIDLET_RESUME_ACK, status, gridletId, userId); @@ -514,7 +515,7 @@ // allocate the Gridlet into an empty PE slot and remove it from // the queue list boolean success = allocatePEtoGridlet(obj); - if (success == true) { + if (success) { gridletQueueList_.remove(obj); } } @@ -528,7 +529,7 @@ * @pre $none * @post $none */ - private void updateGridletProcessing() + private synchronized void updateGridletProcessing() { // Identify MI share for the duration (from last event time) double time = GridSim.clock(); @@ -645,7 +646,7 @@ * @pre length >= 0.0 * @post $none */ - private double forecastFinishTime(double availableRating, double length) + private static double forecastFinishTime(double availableRating, double length) { double finishTime = (length / availableRating); @@ -665,7 +666,7 @@ * @pre $none * @post $none */ - private void checkGridletCompletion() + private synchronized void checkGridletCompletion() { ResGridlet obj = null; int i = 0; @@ -725,8 +726,7 @@ * or paused list. * @param gridletId a Gridlet ID * @param userId the user or owner's ID of this Gridlet - * @param an object of ResGridlet or <tt>null</tt> if this Gridlet is not - * found + * @return an ResGridlet object <tt>null</tt> if this Gridlet is not found * @pre gridletId > 0 * @pre userId > 0 * @post $none @@ -784,6 +784,5 @@ } return rgl; } +} -} // end class - Modified: trunk/source/gridsim/TimeShared.java =================================================================== --- trunk/source/gridsim/TimeShared.java 2008-11-16 10:42:53 UTC (rev 259) +++ trunk/source/gridsim/TimeShared.java 2009-04-03 04:28:19 UTC (rev 260) @@ -9,9 +9,11 @@ package gridsim; +import eduni.simjava.Sim_event; +import eduni.simjava.Sim_system; + +import java.util.Calendar; import java.util.Iterator; -import gridsim.*; -import eduni.simjava.*; /** @@ -25,6 +27,7 @@ * * @author Manzur Murshed and Rajkumar Buyya * @author Anthony Sulistio (re-written this class) + * @author Marcos Dias de Assuncao (has made some methods synchronized) * @since GridSim Toolkit 2.2 * @see gridsim.GridSim * @see gridsim.ResourceCharacteristics @@ -118,7 +121,7 @@ // if the simulation finishes then exit the loop if (ev.get_tag() == GridSimTags.END_OF_SIMULATION || - super.isEndSimulation() == true) + super.isEndSimulation()) { break; } @@ -150,7 +153,7 @@ * @pre gl != null * @post $none */ - public void gridletSubmit(Gridlet gl, boolean ack) + public synchronized void gridletSubmit(Gridlet gl, boolean ack) { // update Gridlets in execution up to this point in time updateGridletProcessing(); @@ -179,7 +182,7 @@ gridletInExecList_.add(rgl); // add into the execution list // sends back an ack if required - if (ack == true) + if (ack) { super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, true, gl.getGridletID(), gl.getUserID() @@ -200,7 +203,7 @@ * @pre userId > 0 * @post $none */ - public int gridletStatus(int gridletId, int userId) + public synchronized int gridletStatus(int gridletId, int userId) { ResGridlet rgl = null; @@ -252,7 +255,7 @@ * @pre userId > 0 * @post $none */ - public void gridletCancel(int gridletId, int userId) + public synchronized void gridletCancel(int gridletId, int userId) { // Finds the gridlet in execution and paused list ResGridlet rgl = cancel(gridletId, userId); @@ -301,7 +304,7 @@ * @pre userId > 0 * @post $none */ - public void gridletPause(int gridletId, int userId, boolean ack) + public synchronized void gridletPause(int gridletId, int userId, boolean ack) { boolean status = false; @@ -349,7 +352,7 @@ } // sends back an ack - if (ack == true) + if (ack) { super.sendAck(GridSimTags.GRIDLET_PAUSE_ACK, status, gridletId, userId); @@ -377,7 +380,7 @@ * @pre destId > 0 * @post $none */ - public void gridletMove(int gridletId, int userId, int destId, boolean ack) + public synchronized void gridletMove(int gridletId, int userId, int destId, boolean ack) { // cancel the Gridlet first ResGridlet rgl = cancel(gridletId, userId); @@ -389,7 +392,7 @@ ".TimeShared.gridletMove(): Cannot find " + "Gridlet #" + gridletId + " for User #" + userId); - if (ack == true) // sends ack that this operation fails + if (ack) // sends ack that this operation fails { super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, false, gridletId, userId); @@ -409,7 +412,7 @@ + " Gridlet #" + gridletId + " for User #" + userId + " since it has FINISHED."); - if (ack == true) + if (ack) { super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, false, gridletId, userId); @@ -436,7 +439,7 @@ * @pre userId > 0 * @post $none */ - public void gridletResume(int gridletId, int userId, boolean ack) + public synchronized void gridletResume(int gridletId, int userId, boolean ack) { boolean success = false; @@ -470,7 +473,7 @@ } // sends back an ack to sender - if (ack == true) + if (ack) { super.sendAck(GridSimTags.GRIDLET_RESUME_ACK, success, gridletId, userId); @@ -698,7 +701,7 @@ * @param length remaining Gridlet length * @return Gridlet's finish time. */ - private double forecastFinishTime(double availableRating, double length) + private static double forecastFinishTime(double availableRating, double length) { double finishTime = length / availableRating; @@ -740,7 +743,7 @@ * @pre $none * @post $none */ - private void internalEvent() + private synchronized void internalEvent() { // this is a constraint that prevents an infinite loop // Compare between 2 floating point numbers. This might be incorrect @@ -761,8 +764,7 @@ * or paused list. * @param gridletId a Gridlet ID * @param userId the user or owner's ID of this Gridlet - * @param an object of ResGridlet or <tt>null</tt> if this Gridlet is not - * found + * @return a ResGridlet object or <tt>null</tt> if this Gridlet is not found * @pre gridletId > 0 * @pre userId > 0 * @post $none @@ -810,6 +812,5 @@ return rgl; } +} -} // end class - Modified: trunk/source/gridsim/resFailure/FailureMsg.java =================================================================== --- trunk/source/gridsim/resFailure/FailureMsg.java 2008-11-16 10:42:53 UTC (rev 259) +++ trunk/source/gridsim/resFailure/FailureMsg.java 2009-04-03 04:28:19 UTC (rev 260) @@ -48,7 +48,7 @@ } /** - * This method sets the time atribute of the ResourceFailure object + * This method sets the time attribute of the ResourceFailure object * @param time the time that the failure will last */ public void setTime(double time) @@ -57,7 +57,7 @@ } /** - * This method returns the time atribute of the ResourceFailure object + * This method returns the time attribute of the ResourceFailure object * @return time */ public double getTime() @@ -66,7 +66,7 @@ } /** - * This method sets the res_id atribute of the ResourceFailure object + * This method sets the res_id attribute of the ResourceFailure object * @param r the resource id of the resource */ public void setRes(int r) @@ -75,7 +75,7 @@ } /** - * This method returns the res_id atribute of the ResourceFailure object + * This method returns the res_id attribute of the ResourceFailure object * @return the resource id */ public int getRes() @@ -84,7 +84,7 @@ } /** - * This method sets the numMachines atribute of the ResourceFailure object + * This method sets the numMachines attribute of the ResourceFailure object * @param n the number of machines which will fail in this resource */ public void setNumMachines(int n) Modified: trunk/source/gridsim/resFailure/GridResourceWithFailure.java =================================================================== --- trunk/source/gridsim/resFailure/GridResourceWithFailure.java 2008-11-16 10:42:53 UTC (rev 259) +++ trunk/source/gridsim/resFailure/GridResourceWithFailure.java 2009-04-03 04:28:19 UTC (rev 260) @@ -48,7 +48,7 @@ /** a ResourceCalendar object */ protected ResourceCalendar resCalendar_; - /** A resource's scheduler. This object is reponsible in scheduling and + /** A resource's scheduler. This object is responsible for scheduling and * and executing submitted Gridlets. */ protected AllocPolicy policy_; Modified: trunk/source/gridsim/resFailure/RegionalGISWithFailure.java =================================================================== --- trunk/source/gridsim/resFailure/RegionalGISWithFailure.java 2008-11-16 10:42:53 UTC (rev 259) +++ trunk/source/gridsim/resFailure/RegionalGISWithFailure.java 2009-04-03 04:28:19 UTC (rev 260) @@ -18,7 +18,6 @@ import eduni.simjava.*; import gridsim.*; import gridsim.net.Link; -import eduni.simjava.distributions.Sim_uniform_obj; import gridsim.resFailure.FailureMsg; import eduni.simjava.distributions.DiscreteGenerator; import eduni.simjava.distributions.ContinuousGenerator; Modified: trunk/source/gridsim/resFailure/SpaceSharedWithFailure.java =================================================================== --- trunk/source/gridsim/resFailure/SpaceSharedWithFailure.java 2008-11-16 10:42:53 UTC (rev 259) +++ trunk/source/gridsim/resFailure/SpaceSharedWithFailure.java 2009-04-03 04:28:19 UTC (rev 260) @@ -32,6 +32,7 @@ * this Gridlet to one PE. * * @author Agustin Caminero + * @author Marcos Dias de Assuncao (added synchronisation) * @since GridSim Toolkit 4.1 * @see gridsim.SpaceShared * @invariant $none @@ -103,7 +104,7 @@ // if the simulation finishes then exit the loop if (ev.get_tag() == GridSimTags.END_OF_SIMULATION || - super.isEndSimulation() == true) + super.isEndSimulation()) { break; } @@ -137,7 +138,7 @@ * @pre gl != null * @post $none */ - public void gridletSubmit(Gridlet gl, boolean ack) + public synchronized void gridletSubmit(Gridlet gl, boolean ack) { // update the current Gridlets in exec list up to this point in time updateGridletProcessing(); @@ -169,14 +170,14 @@ } // if no available PE then put the ResGridlet into a Queue list - if (success == false) + if (!success) { rgl.setGridletStatus(Gridlet.QUEUED); gridletQueueList_.add(rgl); } // sends back an ack if required - if (ack == true) + if (ack) { super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, true, gl.getGridletID(), gl.getUserID() @@ -194,7 +195,7 @@ * @pre userId > 0 * @post $none */ - public int gridletStatus(int gridletId,int userId) + public synchronized int gridletStatus(int gridletId,int userId) { ResGridlet rgl = null; @@ -256,7 +257,7 @@ * @pre userId > 0 * @post $none */ - public void gridletCancel(int gridletId, int userId) + public synchronized void gridletCancel(int gridletId, int userId) { // cancels a Gridlet ResGridlet rgl = cancel(gridletId, userId); @@ -301,7 +302,7 @@ * @pre userId > 0 * @post $none */ - public void gridletPause(int gridletId, int userId, boolean ack) + public synchronized void gridletPause(int gridletId, int userId, boolean ack) { boolean status = false; @@ -363,7 +364,7 @@ } // sends back an ack if required - if (ack == true) + if (ack) { super.sendAck(GridSimTags.GRIDLET_PAUSE_ACK, status, gridletId, userId); @@ -391,7 +392,7 @@ * @pre destId > 0 * @post $none */ - public void gridletMove(int gridletId, int userId, int destId, boolean ack) + public synchronized void gridletMove(int gridletId, int userId, int destId, boolean ack) { // cancels the Gridlet ResGridlet rgl = cancel(gridletId, userId); @@ -403,7 +404,7 @@ ".SpaceSharedWithFailure.gridletMove(): Cannot find " + "Gridlet #" + gridletId + " for User #" + userId); - if (ack == true) // sends back an ack if required + if (ack) // sends back an ack if required { super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, false, gridletId, userId); @@ -419,7 +420,7 @@ + ".SpaceSharedWithFailure.gridletMove(): Cannot move Gridlet #" + gridletId + " for User #"+ userId+ " since it has FINISHED."); - if (ack == true) // sends back an ack if required + if (ack) // sends back an ack if required { super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, false, gridletId, userId); @@ -453,7 +454,7 @@ * @pre userId > 0 * @post $none */ - public void gridletResume(int gridletId, int userId, boolean ack) + public synchronized void gridletResume(int gridletId, int userId, boolean ack) { boolean status = false; @@ -476,7 +477,7 @@ } // otherwise put into Queue list - if (success == false) + if (!success) { rgl.setGridletStatus(Gridlet.QUEUED); gridletQueueList_.add(rgl); @@ -494,7 +495,7 @@ } // sends back an ack if required - if (ack == true) + if (ack) { super.sendAck(GridSimTags.GRIDLET_RESUME_ACK, status, gridletId, userId); @@ -522,7 +523,7 @@ // allocate the Gridlet into an empty PE slot and remove it from // the queue list boolean success = allocatePEtoGridlet(obj); - if (success == true) { + if (!success) { gridletQueueList_.remove(obj); } } @@ -536,7 +537,7 @@ * @pre $none * @post $none */ - private void updateGridletProcessing() + private synchronized void updateGridletProcessing() { // Identify MI share for the duration (from last event time) double time = GridSim.clock(); @@ -653,7 +654,7 @@ * @pre length >= 0.0 * @post $none */ - private double forecastFinishTime(double availableRating, double length) + private static double forecastFinishTime(double availableRating, double length) { double finishTime = (length / availableRating); @@ -673,7 +674,7 @@ * @pre $none * @post $none */ - private void checkGridletCompletion() + private synchronized void checkGridletCompletion() { ResGridlet obj = null; int i = 0; @@ -733,8 +734,7 @@ * or paused list. * @param gridletId a Gridlet ID * @param userId the user or owner's ID of this Gridlet - * @param an object of ResGridlet or <tt>null</tt> if this Gridlet is not - * found + * @return a ResGridlet or <tt>null</tt> if this Gridlet is not found * @pre gridletId > 0 * @pre userId > 0 * @post $none @@ -797,9 +797,9 @@ * Sets the status of all Gridlets in this resource to <tt>FAILED</tt>. * Then sends them back to users, and clean up the relevant lists. */ - public void setGridletsFailed() + public synchronized void setGridletsFailed() { - ResGridlet rgl; + ResGridlet rgl = null; int gridletPausedList_size = gridletPausedList_.size(); int gridletInExecList_size = gridletInExecList_.size(); @@ -869,7 +869,7 @@ * Then sends them back to users, and clean up the relevant lists. * @param failedMachID the id of the failed machine */ - public void setGridletsFailed(int failedMachID) + public synchronized void setGridletsFailed(int failedMachID) { /*************** // Uncomment this to get more info on the progress of sims @@ -907,5 +907,4 @@ } } } - -} // end class +} Modified: trunk/source/gridsim/resFailure/TimeSharedWithFailure.java =================================================================== --- trunk/source/gridsim/resFailure/TimeSharedWithFailure.java 2008-11-16 10:42:53 UTC (rev 259) +++ trunk/source/gridsim/resFailure/TimeSharedWithFailure.java 2009-04-03 04:28:19 UTC (rev 260) @@ -122,7 +122,7 @@ // if the simulation finishes then exit the loop if (ev.get_tag() == GridSimTags.END_OF_SIMULATION || - super.isEndSimulation() == true) + super.isEndSimulation()) { break; } @@ -154,7 +154,7 @@ * @pre gl != null * @post $none */ - public void gridletSubmit(Gridlet gl, boolean ack) + public synchronized void gridletSubmit(Gridlet gl, boolean ack) { // update Gridlets in execution up to this point in time updateGridletProcessing(); @@ -183,7 +183,7 @@ gridletInExecList_.add(rgl); // add into the execution list // sends back an ack if required - if (ack == true) + if (ack) { super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, true, gl.getGridletID(), gl.getUserID() @@ -204,7 +204,7 @@ * @pre userId > 0 * @post $none */ - public int gridletStatus(int gridletId, int userId) + public synchronized int gridletStatus(int gridletId, int userId) { ResGridlet rgl = null; @@ -256,7 +256,7 @@ * @pre userId > 0 * @post $none */ - public void gridletCancel(int gridletId, int userId) + public synchronized void gridletCancel(int gridletId, int userId) { // Finds the gridlet in execution and paused list ResGridlet rgl = cancel(gridletId, userId); @@ -305,7 +305,7 @@ * @pre userId > 0 * @post $none */ - public void gridletPause(int gridletId, int userId, boolean ack) + public synchronized void gridletPause(int gridletId, int userId, boolean ack) { boolean status = false; @@ -353,7 +353,7 @@ } // sends back an ack - if (ack == true) + if (ack) { super.sendAck(GridSimTags.GRIDLET_PAUSE_ACK, status, gridletId, userId); @@ -381,7 +381,7 @@ * @pre destId > 0 * @post $none */ - public void gridletMove(int gridletId, int userId, int destId, boolean ack) + public synchronized void gridletMove(int gridletId, int userId, int destId, boolean ack) { // cancel the Gridlet first ResGridlet rgl = cancel(gridletId, userId); @@ -393,7 +393,7 @@ ".TimeSharedWithFailure.gridletMove(): Cannot find " + "Gridlet #" + gridletId + " for User #" + userId); - if (ack == true) // sends ack that this operation fails + if (ack) // sends ack that this operation fails { super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, false, gridletId, userId); @@ -413,7 +413,7 @@ + " Gridlet #" + gridletId + " for User #" + userId + " since it has FINISHED."); - if (ack == true) + if (ack) { super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, false, gridletId, userId); @@ -440,7 +440,7 @@ * @pre userId > 0 * @post $none */ - public void gridletResume(int gridletId, int userId, boolean ack) + public synchronized void gridletResume(int gridletId, int userId, boolean ack) { boolean success = false; @@ -474,7 +474,7 @@ } // sends back an ack to sender - if (ack == true) + if (ack) { super.sendAck(GridSimTags.GRIDLET_RESUME_ACK, success, gridletId, userId); @@ -745,7 +745,7 @@ * @pre $none * @post $none */ - private void internalEvent() + private synchronized void internalEvent() { // this is a constraint that prevents an infinite loop // Compare between 2 floating point numbers. This might be incorrect @@ -766,8 +766,7 @@ * or paused list. * @param gridletId a Gridlet ID * @param userId the user or owner's ID of this Gridlet - * @param an object of ResGridlet or <tt>null</tt> if this Gridlet is not - * found + * @return a ResGridlet or <tt>null</tt> if this Gridlet is not found * @pre gridletId > 0 * @pre userId > 0 * @post $none This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |