Class Philosopher
- java.lang.Object
- 
- ptolemy.kernel.util.NamedObj
- 
- ptolemy.kernel.InstantiableNamedObj
- 
- ptolemy.kernel.Entity<T>
- 
- ptolemy.kernel.ComponentEntity<T>
- 
- ptolemy.actor.AtomicActor<TypedIOPort>
- 
- ptolemy.actor.TypedAtomicActor
- 
- ptolemy.domains.csp.kernel.CSPActor
- 
- ptolemy.domains.csp.demo.DiningPhilosophers.Philosopher
 
 
 
 
 
 
 
 
- 
- All Implemented Interfaces:
- java.lang.Cloneable,- Actor,- Executable,- FiringsRecordable,- Initializable,- TypedActor,- BranchActor,- Changeable,- Debuggable,- DebugListener,- Derivable,- Instantiable,- ModelErrorHandler,- MoMLExportable,- Moveable,- Nameable
 
 public class Philosopher extends CSPActor A philosopher sits at a table with 4 other philosophers. Between each two philosophers there is a chopstick. A Philosopher eats when he has both chopsticks next to him. A Philosopher thinks for a while, then tries to eat. When he succeeds in obtaining both chopsticks he eats for a while, then puts both chopsticks back on the table and continues thinking.Due to the rendezvous nature of communication in the CSP domain, a philosopher stalls if it tries to get a chopstick but cannot. When it acquires the chopstick, it eats for a while and then sends a message to the chopstick to say that it is finished using it. Note this actor has been slowed down with Thread.sleep() statements to mimic the eating nature of the philosophers in real time. This actor is parameterized by three parameters: "eatingRate" which controls the distribution of the eating times, and "thinkingRate" which controls the distribution of the thinking times. Both these rates characterize a uniform distribution between 0 and the rate. - Since:
- Ptolemy II 0.3
- Version:
- $Id$
- Author:
- Neil Smyth
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Red (nsmyth)
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class ptolemy.kernel.EntityEntity.ContainedObjectsIterator
 
- 
 - 
Field SummaryFields Modifier and Type Field Description ParametereatingThis parameter determines the rate at which this philosopher will spend time eating.booleangotLeftbooleangotRightTypedIOPortleftInThe port through which this philosopher is granted access to the left chopstick.TypedIOPortleftOutThe port through which this philosopher releases access to the left chopstick.TypedIOPortrightInThe port through which this philosopher is granted access to the right chopstick.TypedIOPortrightOutThe port through which this philosopher releases access to the right chopstick.ParameterthinkingThis parameter determines the rate at which this philosopher will spend time thinking.booleanwaitingLeftbooleanwaitingRight- 
Fields inherited from class ptolemy.actor.TypedAtomicActor_typesValid
 - 
Fields inherited from class ptolemy.actor.AtomicActor_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 - 
Fields inherited from class ptolemy.kernel.util.NamedObj_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 - 
Fields inherited from interface ptolemy.actor.ExecutableCOMPLETED, NOT_READY, STOP_ITERATING
 
- 
 - 
Constructor SummaryConstructors Constructor Description Philosopher(TypedCompositeActor container, java.lang.String name)Construct a Philosopher in the specified container with the specified name.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_notifyListeners()Notify any PhilosopherListeners that have registered an interest/dependency in this Philosopher.voidaddPhilosopherListener(PhilosopherListener newListener)Register a PhilosopherListener with this Philosopher.voidfire()Executes the code in this actor.booleanpostfire()Return true if this actor is enabled to proceed with additional iterations; return false otherwise.voidpreinitialize()Set this actor to its initial state, i.e.- 
Methods inherited from class ptolemy.domains.csp.kernel.CSPActor_cancelDelay, _continue, _waitForDeadlock, chooseBranch, clone, delay, getBranchController, initialize, terminate
 - 
Methods inherited from class ptolemy.actor.TypedAtomicActor_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
 - 
Methods inherited from class ptolemy.actor.AtomicActor_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, prefire, 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_addPort, _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, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, decorators, 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, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 - 
Methods inherited from class java.lang.Objectequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface ptolemy.actor.ActorcreateReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 - 
Methods inherited from interface ptolemy.kernel.util.DerivablegetDerivedLevel, getDerivedList, propagateValue
 - 
Methods inherited from interface ptolemy.actor.ExecutableisFireFunctional, isStrict, iterate, prefire, stop, stopFire
 - 
Methods inherited from interface ptolemy.actor.InitializableaddInitializable, removeInitializable, wrapup
 - 
Methods inherited from interface ptolemy.kernel.util.Nameabledescription, getContainer, getDisplayName, getFullName, getName, getName, setName
 
- 
 
- 
- 
- 
Field Detail- 
leftInpublic TypedIOPort leftIn The port through which this philosopher is granted access to the left chopstick.
 - 
leftOutpublic TypedIOPort leftOut The port through which this philosopher releases access to the left chopstick.
 - 
rightInpublic TypedIOPort rightIn The port through which this philosopher is granted access to the right chopstick.
 - 
rightOutpublic TypedIOPort rightOut The port through which this philosopher releases access to the right chopstick.
 - 
eatingpublic Parameter eating This parameter determines the rate at which this philosopher will spend time eating.
 - 
thinkingpublic Parameter thinking This parameter determines the rate at which this philosopher will spend time thinking.
 - 
gotLeftpublic boolean gotLeft 
 - 
gotRightpublic boolean gotRight 
 - 
waitingLeftpublic boolean waitingLeft 
 - 
waitingRightpublic boolean waitingRight 
 
- 
 - 
Constructor Detail- 
Philosopherpublic Philosopher(TypedCompositeActor container, java.lang.String name) throws IllegalActionException, NameDuplicationException Construct a Philosopher 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. The actor is created with two input ports and two output ports, all of width one. The input ports are called "leftIn" and "rightIn", and similarly, the output ports are called "leftOut" and "rightOut".The default values of the eatingRate and thinkingRate parameters are 1.0. - Parameters:
- container- The TypedCompositeActor that contains this actor.
- name- The actor's name.
- Throws:
- IllegalActionException- If the entity cannot be contained by the proposed container.
- NameDuplicationException- If the name argument coincides with an entity already in the container.
 
 
- 
 - 
Method Detail- 
addPhilosopherListenerpublic void addPhilosopherListener(PhilosopherListener newListener) Register a PhilosopherListener with this Philosopher.
 - 
firepublic void fire() throws IllegalActionExceptionExecutes the code in this actor. This actor randomly chooses whether to grab the chopstick to the left or right of it first. When it has one chopstick, it then tries to grab the other chopstick beside it. This process mimics the eating action of the philosopher twenty times, and then finishes normally.- Specified by:
- firein interface- Executable
- Overrides:
- firein class- AtomicActor<TypedIOPort>
- Throws:
- IllegalActionException- If an error occurs during executing the process.
 
 - 
postfirepublic boolean postfire() Return true if this actor is enabled to proceed with additional iterations; return false otherwise.- Specified by:
- postfirein interface- Executable
- Overrides:
- postfirein class- CSPActor
- Returns:
- True if continued execution is enabled; false otherwise.
 
 - 
preinitializepublic void preinitialize() throws IllegalActionExceptionSet this actor to its initial state, i.e. not having nor waiting for any chopsticks.- Specified by:
- preinitializein interface- Initializable
- Overrides:
- preinitializein class- AtomicActor<TypedIOPort>
- Throws:
- IllegalActionException- Not thrown in this base class.
 
 - 
_notifyListenersprotected void _notifyListeners() Notify any PhilosopherListeners that have registered an interest/dependency in this Philosopher.
 
- 
 
-