GridSim 5.0 beta

gridsim
Class ARPolicy

Object
  extended by Thread
      extended by Sim_entity
          extended by AllocPolicy
              extended by ARPolicy
All Implemented Interfaces:
Cloneable, Runnable
Direct Known Subclasses:
ARSimpleSpaceShared

public abstract class ARPolicy
extends AllocPolicy

ARPolicy is an abstract class that handles the internal GridResource allocation policy related to Advanced Reservation functionalities. New scheduling algorithms can be added into a GridResource entity by extending this class and implement the required abstract methods. AllocPolicy abstract methods are also need to be implemented.

All the implementation details and the data structures chosen are up to the child class. All the protected methods and attributes are available to code things easier. Child classes should use replyXXXReservation() methods where XXX = Cancel / Commit / Query / Time / Create. This is because these methods send a correct format or message to AdvanceReservation class. Sending an incorrect message will caused an exception on the receiver's side.

Since:
GridSim Toolkit 3.0
Author:
Anthony Sulistio
See Also:
GridSim, ResourceCharacteristics, AdvanceReservation, AllocPolicy
Invariant:
$none

Nested Class Summary
 
Nested classes/interfaces inherited from class Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected static int MILLI_SEC
          A constant variable that represents 1 second in 1,000 milliseconds.
 
Fields inherited from class AllocPolicy
initTime_, myId_, outputPort_, resCalendar_, resId_, resName_, resource_, totalPE_
 
Fields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected ARPolicy(String resourceName, String entityName)
          Allocates a new ARPolicy object.
 
Method Summary
protected  int approxBusyTime(long time)
          Approximates busy time
protected  long getCurrentTime()
          Gets the current time.
abstract  void handleCancelReservation(int reservationID, int senderID, ArrayList list, int sendTag)
          An abstract method that handles a cancel reservation request.
abstract  void handleCancelReservation(int reservationID, int senderID, int sendTag)
          An abstract method that handles a cancel reservation request.
abstract  void handleCancelReservation(int reservationID, int senderID, int gridletID, int sendTag)
          An abstract method that handles a cancel reservation request.
abstract  void handleCommitOnly(int reservationID, int senderID, int sendTag)
          An abstract method that handles a commit reservation request.
abstract  void handleCommitReservation(int reservationID, int senderID, int sendTag, Gridlet gridlet)
          An abstract method that handles a commit reservation request.
abstract  void handleCommitReservation(int reservationID, int senderID, int sendTag, GridletList list)
          An abstract method that handles a commit reservation request.
abstract  void handleCreateReservation(ARObject obj, int senderID, int sendTag)
          An abstract method that handles a new advanced reservation request.
abstract  void handleImmediateReservation(ARObject obj, int senderID, int sendTag)
          An abstract method that handles a new immediate reservation request.
abstract  void handleModifyReservation(ARObject obj, int senderID, int sendTag)
          An abstract method that handles a modify reservation request.
abstract  void handleQueryBusyTime(long from, long to, int senderID, int sendTag, double userTimeZone)
          An abstract method that handles a query busy time request.
abstract  void handleQueryFreeTime(long from, long to, int senderID, int sendTag, double userTimeZone)
          An abstract method that handles a query free time request.
abstract  void handleQueryReservation(int reservationID, int senderID, int sendTag)
          An abstract method that handles a query reservation request.
protected  void replyCancelReservation(int destID, int tag, int result)
          Sends a result of a cancel reservation request.
protected  void replyCommitReservation(int destID, int tag, int result)
          Sends a result of a commit reservation request.
protected  void replyCreateReservation(int destID, int tag, long expiryTime, int reservID)
          Sends a result of a create reservation request.
protected  void replyModifyReservation(int destID, int tag, int result)
          Sends a result of a modify reservation request.
protected  void replyQueryReservation(int destID, int tag, int result)
          Sends a result of a query reservation request.
protected  void replyTimeReservation(int destID, int tag, ArrayList result, double userTimeZone)
          Sends a result of a query busy or free time request.
protected  int searchReservation(Collection obj, int reservationID)
          Search for a particular reservation in a data structure
 
Methods inherited from class AllocPolicy
addTotalLoad, calculateTotalLoad, findGridlet, getTotalLoad, gridletCancel, gridletMigrate, gridletMove, gridletPause, gridletResume, gridletStatus, gridletSubmit, init, isEndSimulation, processOtherEvent, sendAck, sendCancelGridlet, sendFinishGridlet, sendInternalEvent, sendInternalEvent, setEndSimulation
 
Methods inherited from class Sim_entity
add_generator, add_param, add_port, body, clone, get_id, get_name, get_port, get_port, get_stat, run, send_on, set_invisible, set_stat, sim_cancel, sim_completed, sim_current, sim_get_next, sim_get_next, sim_hold_for, sim_hold, sim_pause_for, sim_pause_for, sim_pause_until, sim_pause_until, sim_pause, sim_process_for, sim_process_for, sim_process_until, sim_process_until, sim_process, sim_putback, sim_schedule, sim_schedule, sim_schedule, sim_schedule, sim_schedule, sim_schedule, sim_select, sim_trace, sim_wait_for, sim_wait_for, sim_wait_for, sim_wait, sim_waiting, sim_waiting
 
Methods inherited from class Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MILLI_SEC

protected static final int MILLI_SEC
A constant variable that represents 1 second in 1,000 milliseconds.

See Also:
Constant Field Values
Constructor Detail

ARPolicy

protected ARPolicy(String resourceName,
                   String entityName)
            throws Exception
Allocates a new ARPolicy object. A child class should call this method during its constructor. The name of this entity (or the child class that inherits this class) will be "resName_entityName".

Parameters:
resourceName - the GridResource entity name that will contain this allocation policy
entityName - this object entity name
Throws:
Exception - This happens when one of the following scenarios occur:
  • creating this entity before initializing GridSim package
  • this entity name is null or empty
  • this entity has zero number of PEs (Processing Elements).
    No PEs mean the Gridlets can't be processed. A GridResource must contain one or more Machines. A Machine must contain one or more PEs.
See Also:
GridSim.init(int, Calendar, boolean), GridSim.init(int, Calendar, boolean, String[], String[], String)
Pre Condition:
resourceName != null, entityName != null
Post Condition:
$none
Method Detail

handleImmediateReservation

public abstract void handleImmediateReservation(ARObject obj,
                                                int senderID,
                                                int sendTag)
An abstract method that handles a new immediate reservation request. replyCreateReservation(int, int, long, int) method should be used to send a result back to sender or user.

An immediate reservation requests a reservation immediately, i.e. the current time is used as the start time with/without specifying duration or end time.
Immediate reservation can be done by one of the following ways:

  1. start time = 0 (in long) and duration > 0.
    If successful, expiry time should be set like this: expiry time = current time + duration.

  2. start time = 0 (in long) and duration = 0.
    This means a reservation is running as long as there are empty PEs available.
    NOTE: using this approach, a reservation is having a risk of being pre-empted or terminated by a resource scheduler when new AR requests come. In addition, due to complexity, a resource's scheduler might not support this method. Finally, expiry time = 0 since a scheduler can not determine it.

Parameters:
obj - a reservation object
senderID - a sender or user ID
sendTag - a tag to send to the user
Pre Condition:
obj != null, senderID > 0
Post Condition:
$none

handleCreateReservation

public abstract void handleCreateReservation(ARObject obj,
                                             int senderID,
                                             int sendTag)
An abstract method that handles a new advanced reservation request. replyCreateReservation(int, int, long, int) method should be used to send a result back to sender or user.

Parameters:
obj - a reservation object
senderID - a sender or user ID
sendTag - a tag to send to the user
Pre Condition:
obj != null, senderID > 0
Post Condition:
$none

handleModifyReservation

public abstract void handleModifyReservation(ARObject obj,
                                             int senderID,
                                             int sendTag)
An abstract method that handles a modify reservation request. replyModifyReservation(int, int, int) method should be used to send a result back to sender or user.

Parameters:
obj - a reservation object
senderID - a sender or user ID
sendTag - a tag to send to the user
Pre Condition:
obj != null, senderID > 0
Post Condition:
$none

handleCancelReservation

public abstract void handleCancelReservation(int reservationID,
                                             int senderID,
                                             int gridletID,
                                             int sendTag)
An abstract method that handles a cancel reservation request. This method cancels only for a particular Gridlet. replyCancelReservation(int, int, int) method should be used to send a result back to sender or user.

Parameters:
reservationID - a reservation ID
senderID - a sender or user ID
gridletID - a gridlet ID
sendTag - a tag to send to the user
Pre Condition:
reservationID > 0, senderID > 0
Post Condition:
$none

handleCancelReservation

public abstract void handleCancelReservation(int reservationID,
                                             int senderID,
                                             ArrayList list,
                                             int sendTag)
An abstract method that handles a cancel reservation request. This method cancels a list of Gridlet IDs. replyCancelReservation(int, int, int) method should be used to send a result back to sender or user.

Parameters:
reservationID - a reservation ID
senderID - a sender or user ID
list - a list of Gridlet IDs (each ID is represented as an Integer object)
sendTag - a tag to send to the user
Pre Condition:
reservationID > 0, senderID > 0, list != null
Post Condition:
$none

handleCancelReservation

public abstract void handleCancelReservation(int reservationID,
                                             int senderID,
                                             int sendTag)
An abstract method that handles a cancel reservation request. This method cancels all Gridlets for a given reservation ID. replyCancelReservation(int, int, int) method should be used to send a result back to sender or user.

Parameters:
reservationID - a reservation ID
senderID - a sender or user ID
sendTag - a tag to send to the user
Pre Condition:
reservationID > 0, senderID > 0
Post Condition:
$none

handleCommitOnly

public abstract void handleCommitOnly(int reservationID,
                                      int senderID,
                                      int sendTag)
An abstract method that handles a commit reservation request. This method commits a reservation only. Gridlets are submitted using handleCommitReservation(int, int, int, Gridlet) or handleCommitReservation(int, int, int, GridletList) method.
replyCommitReservation(int, int, int) method should be used to send a result back to sender or user.

Parameters:
reservationID - a reservation ID
senderID - a sender or user ID
sendTag - a tag to send to the user
Pre Condition:
reservationID > 0, senderID > 0
Post Condition:
$none

handleCommitReservation

public abstract void handleCommitReservation(int reservationID,
                                             int senderID,
                                             int sendTag,
                                             Gridlet gridlet)
An abstract method that handles a commit reservation request. This method commits a reservation and submits a Gridlet to be processed as well. replyCommitReservation(int, int, int) method should be used to send a result back to sender or user.

Parameters:
reservationID - a reservation ID
senderID - a sender or user ID
sendTag - a tag to send to the user
gridlet - a Gridlet object
Pre Condition:
reservationID > 0, senderID > 0, gridlet != null
Post Condition:
$none

handleCommitReservation

public abstract void handleCommitReservation(int reservationID,
                                             int senderID,
                                             int sendTag,
                                             GridletList list)
An abstract method that handles a commit reservation request. This method commits a reservation and submits a list of Gridlets to be processed as well. replyCommitReservation(int, int, int) method should be used to send a result back to sender or user.

Parameters:
reservationID - a reservation ID
senderID - a sender or user ID
sendTag - a tag to send to the user
list - a list of Gridlet objects
Pre Condition:
reservationID > 0, senderID > 0, list != null
Post Condition:
$none

handleQueryReservation

public abstract void handleQueryReservation(int reservationID,
                                            int senderID,
                                            int sendTag)
An abstract method that handles a query reservation request. replyQueryReservation(int, int, int) method should be used to send a result back to sender or user.

Parameters:
reservationID - a reservation ID
senderID - a sender or user ID
sendTag - a tag to send to the user
Pre Condition:
reservationID > 0, senderID > 0
Post Condition:
$none

handleQueryBusyTime

public abstract void handleQueryBusyTime(long from,
                                         long to,
                                         int senderID,
                                         int sendTag,
                                         double userTimeZone)
An abstract method that handles a query busy time request. replyTimeReservation(int, int, ArrayList, double) method should be used to send a result back to sender or user.

Parameters:
from - starting period time (local resource time)
to - ending period time (local resource time)
senderID - a sender or user ID
sendTag - a tag to send to the user
Pre Condition:
from > 0, to > 0, senderID > 0
Post Condition:
$none

handleQueryFreeTime

public abstract void handleQueryFreeTime(long from,
                                         long to,
                                         int senderID,
                                         int sendTag,
                                         double userTimeZone)
An abstract method that handles a query free time request. replyTimeReservation(int, int, ArrayList, double) method should be used to send a result back to sender or user.

Parameters:
from - starting period time (local resource time)
to - ending period time (local resource time)
senderID - a sender or user ID
sendTag - a tag to send to the user
Pre Condition:
from > 0, to > 0, senderID > 0
Post Condition:
$none

replyCreateReservation

protected void replyCreateReservation(int destID,
                                      int tag,
                                      long expiryTime,
                                      int reservID)
Sends a result of a create reservation request.

Parameters:
destID - a destination or user ID
tag - a tag to send to the user
expiryTime - reservation expiry time. If no empty slots, then expiryTime should be set to -1
reservID - a reservation ID. If no empty slots, then reservID should be set to one of GridSimTags.AR_CREATE_XXXX tags where XXXX = a specific tag name.
See Also:
GridSimTags
Pre Condition:
destID > 0
Post Condition:
$none

replyCancelReservation

protected void replyCancelReservation(int destID,
                                      int tag,
                                      int result)
Sends a result of a cancel reservation request.

Parameters:
destID - a destination or user ID
tag - a tag to send to the user
result - a result tag. This tag should be one of GridSimTags.AR_CANCEL_XXXX where XXXX = a specific tag name.
See Also:
GridSimTags
Pre Condition:
destID > 0, tag > 0
Post Condition:
$none

replyCommitReservation

protected void replyCommitReservation(int destID,
                                      int tag,
                                      int result)
Sends a result of a commit reservation request.

Parameters:
destID - a destination or user ID
tag - a tag to send to the user
result - a result tag. This tag should be one of GridSimTags.AR_COMMIT_XXXX where XXXX = a specific tag name.
See Also:
GridSimTags
Pre Condition:
destID > 0, tag > 0
Post Condition:
$none

replyQueryReservation

protected void replyQueryReservation(int destID,
                                     int tag,
                                     int result)
Sends a result of a query reservation request.

Parameters:
destID - a destination or user ID
tag - a tag to send to the user
result - a result tag. This tag should be one of GridSimTags.AR_STATUS_XXXX where XXXX = a specific tag name.
See Also:
GridSimTags
Pre Condition:
destID > 0, tag > 0
Post Condition:
$none

replyModifyReservation

protected void replyModifyReservation(int destID,
                                      int tag,
                                      int result)
Sends a result of a modify reservation request.

Parameters:
destID - a destination or user ID
tag - a tag to send to the user
result - a result tag. This tag should be one of GridSimTags.AR_MODIFY_XXXX where XXXX = a specific tag name.
See Also:
GridSimTags
Pre Condition:
destID > 0, tag > 0
Post Condition:
$none

replyTimeReservation

protected void replyTimeReservation(int destID,
                                    int tag,
                                    ArrayList result,
                                    double userTimeZone)
Sends a result of a query busy or free time request.

Parameters:
destID - a destination or user ID
tag - a tag to send to the user
result - a list of results. Each object inside ArrayList is long array[3], with:
  • array[0] = start time
  • array[1] = duration time
  • array[2] = number of PEs
See Also:
GridSimTags
Pre Condition:
destID > 0
Post Condition:
$none

getCurrentTime

protected long getCurrentTime()
Gets the current time. Time is calculated from simulation init time + (GridSim.clock() * MILLI_SEC), where MILLI_SEC = 1000.

Returns:
current time in milliseconds
Pre Condition:
$none
Post Condition:
$result > 0

searchReservation

protected int searchReservation(Collection obj,
                                int reservationID)
Search for a particular reservation in a data structure

Parameters:
obj - a data structure
reservationID - a reservation ID
Returns:
location in the data structure or -1 if not found
Pre Condition:
obj != null
Post Condition:
$none

approxBusyTime

protected int approxBusyTime(long time)
Approximates busy time

Parameters:
time - busy time
Returns:
a time interval tag. This tag should be one of GridSimTags.AR_CREATE_FAIL_RESOURCE_FULL_IN_XXXX where XXXX = a specific time interval.

GridSim 5.0 beta

The University of Melbourne, Australia, 2009