Class ProcessClock

All Implemented Interfaces:
NamedObjectOps

public class ProcessClock extends DefaultSimObject
Process-clock service. Some processes can work on only one task at a time. A good example is a CPU. This class models the time consumed by such processes. Requests to advance the clock are posted, given the time interval to advance the clock and a priority for the request. If resources are available, the request is handled immediately, otherwise it is queued. Once dequeued, a request will not be preempted. Until a request executes, it can be canceled. Once the request can be handled, the clock will advance by the time given in the request's interval argument before the requested action occurs.
  • Constructor Details

    • ProcessClock

      public ProcessClock(Simulation sim, boolean intern)
      Constructor.
      Parameters:
      sim - the simulation
      intern - true of the queue should be interned in the simulation's name table; false otherwise
    • ProcessClock

      public ProcessClock(Simulation sim, String name, boolean intern) throws IllegalArgumentException
      Constructor for a named ProcessClock.
      Parameters:
      sim - the simulation
      name - the name for the queue
      intern - true of the queue should be interned in the simulation's name table; false otherwise
      Throws:
      IllegalArgumentException - typically means a name is already in use
  • Method Details

    • advance

      public SimulationEvent advance(Callable callable, int priority, long interval)
      Advance a clock once resources are available and then call a Callable.
      Parameters:
      callable - the Callable to use
      priority - the priority for callable
      interval - the process-clock time consumed
      Returns:
      the SimulationEvent created
    • advance

      public SimulationEvent advance(Runnable runnable, int priority, long interval)
      Advance a clock once resources are available and then start a TaskThread using a Runnable.
      Parameters:
      runnable - the Runnable to use
      priority - the priority for the Runnable
      interval - the process-clock time consumed
      Returns:
      the SimulationEvent created
    • advance

      public void advance(int priority, long interval) throws IllegalStateException
      Advance a clock once resources are available with a TaskThread pausing until this operation is complete.
      Parameters:
      priority - the priority for callable to be added
      interval - the process-clock time consumed
      Throws:
      IllegalStateException
    • advance

      public void advance(int priority, long interval, SimEventCallable callable) throws IllegalStateException
      Advance a clock once resources are available with a TaskThread pausing until this operation is complete but allowing for cancellation.
      Parameters:
      priority - the priority for callable to be added
      interval - the process-clock time consumed
      callable - this argument's call method will be run when the event is scheduled and will be passed a simulation event (e.g., to store the event to allow the event to be canceled)
      Throws:
      IllegalStateException
    • printConfiguration

      public void printConfiguration(String iPrefix, String prefix, boolean printName, PrintWriter out)
      Print this simulation object's configuration. Documentation for the use of this method is provided by the documentation for the SimObject method SimObject.printConfiguration(String,String,boolean,PrintWriter).

      When the third argument has a value of true, the object name and class name will be printed in a standard format with its indentation provided by the iPrefix argument. In addition, the configuration that is printed includes the following\ items:

      Defined in ProcessClock:

      • the configuration for an internal priority task queue.
      Overrides:
      printConfiguration in class DefaultSimObject
      Parameters:
      iPrefix - the prefix to use for an initial line when printName is true with null treated as an empty string
      prefix - a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is true
      printName - requests printing the name of an object
      out - the output print writer
    • printState

      public void printState(String iPrefix, String prefix, boolean printName, PrintWriter out)
      Print this simulation object's state. Documentation for the use of this method is provided by the documentation for the SimObject method SimObject.printState(String,String,boolean,PrintWriter).

      When the second argument has a value of true, the object name and class name will be printed in a standard format with its indentation provided by the iPrefix argument. In addition, the state that is printed includes the following items.

      Defined in ProcessClock:

      • the state for an internal priority task queue.
      Overrides:
      printState in class DefaultSimObject
      Parameters:
      iPrefix - the prefix to use for an initial line when printName is true with null treated as an empty string
      prefix - a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is true
      printName - requests printing the name of an object
      out - the output print writer
    • clone

      protected Object clone() throws CloneNotSupportedException
      Creates and returns a copy of this object. This method will throw the exception CloneNotSupportedException if the object is interned.
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException - a clone could not be created
      See Also:
    • isInterned

      public boolean isInterned()
      Determine if an object is interned in a object namer's tables.
      Specified by:
      isInterned in interface NamedObjectOps
      Returns:
      true if the object is interned; false if not
    • getObjectNamer

      protected Simulation getObjectNamer()
      Get the object namer for a named object.
      Returns:
      the object namer for this named object
    • getName

      public final String getName()
      Get an object's name.
      Specified by:
      getName in interface NamedObjectOps
      Returns:
      the name of the object
    • canDelete

      public boolean canDelete()
      Determine if this named object can be deleted. A named object can be deleted if the method delete has not been called and if the object is not in a state that prevents the object from being deleted. Subclasses that override this method must call canDelete() for their superclasses and return false if the superclass' canDelete method returns false. The default method returns true if delete() has not been called and returned true.
      Specified by:
      canDelete in interface NamedObjectOps
      Returns:
      true if this object can be deleted; false otherwise
    • delete

      public final boolean delete()
      Delete an object. An object can only be deleted once. If this method returns true, the object (if interned) will have been removed from the object namer tables.

      The implementations provided by DefaultNamedObect and generated because of a @NamedObject annotation provide a protected method named onDelete. A subclass that overrides onDelete() must call the onDelete method of its superclass after it's onDelete method has been called and any cleanup actions performed. In some cases, this may happen at a later time (e.g., if a thread is used for some of the cleanup operations or if it is otherwise necessary to wait).

      Specified by:
      delete in interface NamedObjectOps
      Returns:
      true if the deletion request was accepted; false otherwise
    • isDeleted

      public final boolean isDeleted()
      Determine if an object has been deleted. An object is deleted if the method delete() has been called and returned true.
      Specified by:
      isDeleted in interface NamedObjectOps
      Returns:
      true if deleted; false otherwise
    • deletePending

      public final boolean deletePending()
      Determine if an object is being deleted. An deletion is pending if the method delete() has been called and returned true but the deletion has not been completed.
      Specified by:
      deletePending in interface NamedObjectOps
      Returns:
      true if deletion is pending; false otherwise