ptolemy.domains.csp.lib
Class ResourcePool

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by ptolemy.domains.csp.kernel.CSPActor
                              extended by ptolemy.domains.csp.lib.ResourcePool
All Implemented Interfaces:
java.io.Serializable, 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: ResourcePool.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Yellow (eal)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private  boolean _branchEnabled
          Indicator that a branch was successfully enabled in the fire() method.
private  java.util.List _pool
          The current resource pool.
private static boolean _VERBOSE_DEBUGGING
          Flag to set verbose debugging messages.
 TypedIOPort grant
          The output port through which this actor grants resources.
 Parameter initialPool
          The initial resource pool.
 TypedIOPort release
          The input port through which other actors release resources.
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
ResourcePool(CompositeEntity container, java.lang.String name)
          Construct an actor in the specified container with the specified name.
 
Method Summary
 void attributeChanged(Attribute attribute)
          Override the base class to reset the resource pool to match the specified initialPool value.
 java.lang.Object clone(Workspace workspace)
          Override the base class to set the type constraints.
 void fire()
          If there are available resources, then perform a conditional branch on any release input or grant output.
 boolean postfire()
          Return true unless none of the branches were enabled in the most recent invocation of fire().
 
Methods inherited from class ptolemy.domains.csp.kernel.CSPActor
_cancelDelay, _continue, _waitForDeadlock, chooseBranch, delay, getBranchController, initialize, terminate
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, prefire, stop, stopFire
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

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).


_pool

private java.util.List _pool
The current resource pool.


_branchEnabled

private boolean _branchEnabled
Indicator that a branch was successfully enabled in the fire() method.


_VERBOSE_DEBUGGING

private static boolean _VERBOSE_DEBUGGING
Flag to set verbose debugging messages.

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
Throws:
IllegalActionException - If an error occurs during executing the process.
TerminateProcessException - If the process termination is requested by the director.

postfire

public boolean postfire()
Return true unless none of the branches were enabled in the most recent invocation of fire().

Specified by:
postfire in interface Executable
Overrides:
postfire in class CSPActor
Returns:
True if another iteration can occur.