Package ptolemy.domains.de.lib
Class Server
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,SequenceActor
,TimedActor
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
PreemptableServer
public class Server extends DETransformer
This actor models a preemptive server with a fixed or variable service time. A server is either busy (serving a customer) or not busy at any given time. If an input arrives when the server is not busy, then the input token is produced on the output with a delay given by the serviceTime parameter. If an input arrives while the server is busy, then that input is queued until the server becomes free, at which point it is produced on the output with a delay given by the serviceTime parameter value at the time that the input arrived. If several inputs arrive while the server is busy, then they are served in an order determined by the value of the priority parameter at the time of arrival of the input, and for inputs with identical priorities, on a first-come, first-served basis. On every firing, produce an output indicating the final queue size.The service time and priority used for a job are the most recently arrived values prior to or simultaneous with the arrival of the job (not with the time at which service begins). Thus, if you want each job to have an independent service time or priority, you should provide each parameter as an input synchronized with each new job arrival.
- Since:
- Ptolemy II 0.3
- Version:
- $Id$
- Author:
- Lukito Muliadi, Edward A. Lee, Haiyang Zheng
- See Also:
TimeDelay
- Pt.AcceptedRating:
- Yellow (hyzheng)
- Pt.ProposedRating:
- Yellow (hyzheng)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected Time
_nextTimeFree
Next time the server becomes free.protected long
_queueCounter
The counter for tie-breaking the queue by insertion order.protected java.util.TreeMap<java.lang.Double,java.util.PriorityQueue<ptolemy.domains.de.lib.Server.Job>>
_queues
protected int
_queueSize
Parameter
capacity
The capacity of the queue.PortParameter
priority
The priority.PortParameter
serviceTime
The service time.TypedIOPort
size
The current size of the queue.-
Fields inherited from class ptolemy.domains.de.lib.DETransformer
input, output
-
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.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description Server(CompositeEntity container, java.lang.String name)
Construct an actor with the specified container and name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attributeChanged(Attribute attribute)
If the attribute is serviceTime, then ensure that the value is non-negative, and if the attribute is capacity, then change the capacity of the queue.java.lang.Object
clone(Workspace workspace)
Clone the actor into the specified workspace.void
declareDelayDependency()
Declare that the output does not depend on the input, serviceTime, and priority, in a firing.void
fire()
If there is input, read it and put it in the queue.void
initialize()
Reset the states of the server to indicate that the server is ready to serve.boolean
postfire()
If the server is free and there is at least one token in the queue, request a firing at the current time plus the service time.protected int
queueSize()
void
wrapup()
Clear the queue so that the capacity can be changed.-
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, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate
-
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, 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.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.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
capacity
public Parameter capacity
The capacity of the queue. If the value is positive, then it specifies the capacity of the queue. If it is negative or 0, then it specifies that the capacity is infinite. This is an integer with default 0.
-
size
public TypedIOPort size
The current size of the queue. This port produces an output whenever the size changes. It has type int.
-
serviceTime
public PortParameter serviceTime
The service time. This is a double with default 1.0. It is required to be non-negative.
-
priority
public PortParameter priority
The priority. This is a double with default 0.0. A higher priority implies the task has precedence over tasks with lower priority values.
-
_nextTimeFree
protected Time _nextTimeFree
Next time the server becomes free.
-
_queues
protected java.util.TreeMap<java.lang.Double,java.util.PriorityQueue<ptolemy.domains.de.lib.Server.Job>> _queues
-
_queueSize
protected int _queueSize
-
_queueCounter
protected long _queueCounter
The counter for tie-breaking the queue by insertion order.
-
-
Constructor Detail
-
Server
public Server(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
Construct an actor with the specified container and name.- Parameters:
container
- The composite entity to contain this one.name
- The name of this actor.- Throws:
IllegalActionException
- If the entity cannot be contained by the proposed container.NameDuplicationException
- If the container already has an actor with this name.
-
-
Method Detail
-
attributeChanged
public void attributeChanged(Attribute attribute) throws IllegalActionException
If the attribute is serviceTime, then ensure that the value is non-negative, and if the attribute is capacity, then change the capacity of the queue. If the size of the queue currently exceeds the specified capacity, then throw an exception.- Overrides:
attributeChanged
in classNamedObj
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- If the service time is negative.
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace. Set a type constraint that the output type is the same as the that of input.- Overrides:
clone
in classTypedAtomicActor
- Parameters:
workspace
- The workspace for the new object.- Returns:
- A new actor.
- Throws:
java.lang.CloneNotSupportedException
- If a derived class has has an attribute that cannot be cloned.- See Also:
NamedObj.exportMoML(Writer, int, String)
,NamedObj.setDeferringChangeRequests(boolean)
-
declareDelayDependency
public void declareDelayDependency() throws IllegalActionException
Declare that the output does not depend on the input, serviceTime, and priority, in a firing.- Overrides:
declareDelayDependency
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the causality interface cannot be computed.- See Also:
AtomicActor.getCausalityInterface()
-
fire
public void fire() throws IllegalActionException
If there is input, read it and put it in the queue. If the service time has expired for a token currently in the queue, then send that token on the output. Produce an output indicating the current queue size.- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the serviceTime or priority is invalid, or if an error occurs sending the output token.
-
queueSize
protected int queueSize()
-
initialize
public void initialize() throws IllegalActionException
Reset the states of the server to indicate that the server is ready to serve.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the base class throws it.
-
postfire
public boolean postfire() throws IllegalActionException
If the server is free and there is at least one token in the queue, request a firing at the current time plus the service time.- Specified by:
postfire
in interfaceExecutable
- Overrides:
postfire
in classAtomicActor<TypedIOPort>
- Returns:
- Whatever the superclass returns.
- Throws:
IllegalActionException
- If there is no director.
-
wrapup
public void wrapup() throws IllegalActionException
Clear the queue so that the capacity can be changed.- Specified by:
wrapup
in interfaceInitializable
- Overrides:
wrapup
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the superclass throws it.
-
-