public class LocalClock extends AbstractSettableAttribute
The local time is not allowed to move backwards past the committed time, but ahead of that time, it can move around at will.
There is no way of explicitly committing time, but
several methods have the side effect of committing the current
local time. For example, setClockDrift(double)
will commit
the current local time and change the clock drift. So will
start()
and stop()
This class implements the AbstractSettableAttribute interface because we want the localClock to be shown as a parameter in the editor dialogue of a director. A better implementation would be to derive LocalClock from Attribute and make changes to vergil such that Attributes are displayed in the dialogue, however, for the moment, the required changes are too complex. The value of the clock is exposed as an attribute that, by default, is non editable. The clock drift is a contained attribute that can be modified.
This class also specifies a globalTimeResolution parameter. This is a double with default 1E-10, which is 10-10. All time values are rounded to the nearest multiple of this value. If the value is changed during a run, an exception is thrown. This is a shared parameter, which means that all instances of Director in the model will have the same value for this parameter. Changing one of them changes all of them.
FIXME: Setting of clock drift must be controlled because it commits time.
red (eal) |
yellow (eal) |
NamedObj.ContainedObjectsIterator
Settable.Visibility
Modifier and Type | Field and Description |
---|---|
Parameter |
clockDrift
The drift of the local clock with respect to the environment
clock.
|
SharedParameter |
globalTimeResolution
The time precision used by this director.
|
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
EXPERT, FULL, NONE, NOT_EDITABLE
Constructor and Description |
---|
LocalClock(NamedObj container,
java.lang.String name)
Construct an attribute with the given name contained by the specified
entity.
|
Modifier and Type | Method and Description |
---|---|
void |
addValueListener(ValueListener listener)
This method has to be implemented for the AbstractSettableAttribute
interface.
|
void |
attributeChanged(Attribute attribute)
Delegate the call to the director, which handles changes
to the parameters of the clock.
|
java.lang.Object |
clone(Workspace workspace)
Clone the object into the specified workspace.
|
double |
getClockDrift()
Get clock drift.
|
Time |
getEnvironmentTimeForLocalTime(Time time)
Get the environment time that corresponds to the given local time.
|
java.lang.String |
getExpression()
Return the local time.
|
Time |
getLocalTime()
Get current local time.
|
Time |
getLocalTimeForCurrentEnvironmentTime()
Get the local time that corresponds to the current environment time.
|
Time |
getLocalTimeForEnvironmentTime(Time time)
Get the local time that corresponds to the given environment time.
|
double |
getTimeResolution()
Get the time resolution of the model.
|
Settable.Visibility |
getVisibility()
The LocalClock is not editable, thus visibility is
always set to NOT_EDITABLE.
|
void |
initialize()
Initialize parameters that cannot be initialized in the
constructor.
|
void |
removeValueListener(ValueListener listener)
This method has to be implemented for the AbstractSettableAttribute
interface.
|
void |
resetLocalTime(Time time)
Set local time and commit.
|
void |
setClockDrift(double drift)
Set the new clock drift and commit it.
|
void |
setLocalTime(Time time)
Set local time without committing.
|
void |
setTimeResolution(double timeResolution)
Set time resolution.
|
void |
setVisibility(Settable.Visibility visibility)
This method has to be implemented for the AbstractSettableAttribute
interface.
|
void |
start()
Start the clock with the current drift as specified by the
last call to
setClockDrift(double) . |
void |
stop()
Stop the clock.
|
java.util.Collection |
validate()
This method has to be implemented for the AbstractSettableAttribute
interface.
|
getDefaultExpression, getValueAsString, setExpression
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setContainer, setName, updateContent
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _description, _executeChangeRequests, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getDisplayName
description, getContainer, getFullName, getName, getName, setName
public SharedParameter globalTimeResolution
public Parameter clockDrift
public LocalClock(NamedObj container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container.name
- The name of this attribute.IllegalActionException
- If the attribute is not of an
acceptable class for the container, or if the name contains a period.NameDuplicationException
- If the name coincides with
an attribute already in the container.public void addValueListener(ValueListener listener)
listener
- The listener to be added.removeValueListener(ValueListener)
public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class NamedObj
attribute
- The attribute that changed.IllegalActionException
- If the director throws it.public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class Attribute
workspace
- The workspace for the cloned object.java.lang.CloneNotSupportedException
- If thrown by super class.NamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public double getClockDrift()
setClockDrift(double)
public Time getEnvironmentTimeForLocalTime(Time time) throws IllegalActionException
time
- The local Time.IllegalActionException
- If the specified local time
is in the past, or if Time objects cannot be created.public java.lang.String getExpression()
Settable.setExpression(String)
public Time getLocalTime()
setLocalTime(Time)
.setLocalTime(Time)
public Time getLocalTimeForCurrentEnvironmentTime() throws IllegalActionException
IllegalActionException
- If Time objects cannot be created, or
if the current environment time is less than the time
corresponding to the last committed local time.public Time getLocalTimeForEnvironmentTime(Time time) throws IllegalActionException
time
- The environment time.IllegalActionException
- If the specified environment time
is less than the environment time corresponding to the last
committed local time, or if Time objects cannot be created.public final double getTimeResolution()
setTimeResolution(double)
public Settable.Visibility getVisibility()
Settable.setVisibility(Visibility)
public void initialize()
public void removeValueListener(ValueListener listener)
listener
- The listener to be removed.addValueListener(ValueListener)
public void resetLocalTime(Time time)
time
- The new local time.public void setClockDrift(double drift) throws IllegalActionException
drift
- New clock drift.IllegalActionException
- If the specified drift is
non-positive.getClockDrift()
public void setLocalTime(Time time) throws IllegalActionException
time
- The new local time.IllegalActionException
- If the specified time is
earlier than the current time.getLocalTime()
public void setTimeResolution(double timeResolution)
timeResolution
- The new time resolution.getTimeResolution()
public void setVisibility(Settable.Visibility visibility)
visibility
- The new visibility.getVisibility()
public void start()
setClockDrift(double)
.
If setClockDrift(double)
has never been called, then
the drift is 1.0.
This method commits current local time.public void stop()
start()
.
This method commits current local time.public java.util.Collection validate() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.