Class ResourcePool

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, BranchActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class ResourcePool
    extends CSPActor
    This actor manages a pool of resources, where each resource is represented by a token with an arbitrary value. Resources are granted on the grant output port and released on the release input port. These ports are both multiports, so resources can be granted to multiple users of the resources, and released by multiple actors.

    The initial pool of resources is provided by the initialPool parameter, which is an array of arbitrary type. The grant output port and release input port are constrained to have compatible types. Specifically, the grant output port must be able to send tokens with types that match the elements of this array, and it must also be able to send tokens with types that match inputs provided at the release input.

    This actor is designed for use in the CSP domain, where it will execute in its own thread. At all times, it is ready to rendezvous with any other actor connected to its release input port. When such a rendezvous occurs, the token provided at that input is added to the resource pool. In addition, whenever the resource pool is non-empty, this actor is ready to rendezvous with any actor connected to its grant output port. When such a rendezvous occurs, it sends the first token in the resource pool to that output port and removes that token from the resource pool.

    Since:
    Ptolemy II 5.2
    Version:
    $Id$
    Author:
    Edward A. Lee
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Yellow (eal)
    • Field Detail

      • grant

        public TypedIOPort grant
        The output port through which this actor grants resources. This port has type equal to the element type of the initialPool parameter.
      • release

        public TypedIOPort release
        The input port through which other actors release resources. This port has type equal to the element type of the initialPool parameter.
      • initialPool

        public Parameter initialPool
        The initial resource pool. This is an array with default value {1} (an integer array with one entry with value 1).
    • Constructor Detail

      • ResourcePool

        public ResourcePool​(CompositeEntity container,
                            java.lang.String name)
                     throws IllegalActionException,
                            NameDuplicationException
        Construct an actor in the specified container with the specified name. The name must be unique within the container or an exception is thrown. The container argument must not be null, or a NullPointerException will be thrown.
        Parameters:
        container - The container.
        name - The name.
        Throws:
        IllegalActionException - If the actor cannot be contained by the proposed container.
        NameDuplicationException - If the name coincides with an actor already in the container.
    • Method Detail

      • attributeChanged

        public void attributeChanged​(Attribute attribute)
                              throws IllegalActionException
        Override the base class to reset the resource pool to match the specified initialPool value.
        Overrides:
        attributeChanged in class NamedObj
        Parameters:
        attribute - The attribute that changed.
        Throws:
        IllegalActionException - If the change is not acceptable to this container (not thrown in this base class).
      • clone

        public java.lang.Object clone​(Workspace workspace)
                               throws java.lang.CloneNotSupportedException
        Override the base class to set the type constraints.
        Overrides:
        clone in class CSPActor
        Parameters:
        workspace - The workspace for the cloned object.
        Returns:
        A new ResourcePool actor.
        Throws:
        java.lang.CloneNotSupportedException - If cloned ports cannot have as their container the cloned entity (this should not occur), or if one of the attributes cannot be cloned.
        See Also:
        NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)
      • fire

        public void fire()
                  throws IllegalActionException
        If there are available resources, then perform a conditional branch on any release input or grant output. If the selected branch is a release input, then add the provided token to the end of the resource pool. If it is a grant output, then remove the first element from the resource pool and send it to the output. If there are no available resources, then perform a conditional branch only on the release inputs.
        Specified by:
        fire in interface Executable
        Overrides:
        fire in class AtomicActor<TypedIOPort>
        Throws:
        IllegalActionException - If an error occurs during executing the process.
        TerminateProcessException - If the process termination is requested by the director.