Class ResourcePool

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

    public class ResourcePool
    extends TypedAtomicActor
    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 rendezvous 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.

    The behavior of this actor is similar to that of the Merge actor, except that the Merge actor does no buffering. That is, while this actor is always ready to rendezvous with any input, the Merge actor is ready to rendezvous with an input only after it has delivered the previous input to the output.

    Since:
    Ptolemy II 5.1
    Version:
    $Id$
    Author:
    Edward A. Lee
    See Also:
    Merge
    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.