Package gov.nasa.jpl.activity
Class Activity
java.lang.Object
gov.nasa.jpl.activity.Activity
- All Implemented Interfaces:
PropertyChangeListener
,Comparable<Activity>
,EventListener
- Direct Known Subclasses:
InitialConditionActivity
The base Activity class that Blackbird is based on. This holds on to a thread so that when an instance
of a subclass gets its model() method called, the instance can manipulate simulated time via that thread.
Activities support arbitrarily many and deep child activity instances. When activities are created they
automatically register themselves with the engine's ActivityInstanceList.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Recursively add all children to the instance list.void
Not recursive - just child list of this activity, and doesn't remove anything from the instance listint
Natural comparator of Activity instances is by start timevoid
Method called after Activity constructor where one can create child activities according to whatever algorithm and combination of parameters is desired.void
This method recursively deletes all children of the activity.void
We do this so there will be no live references to a thread after it runs, halving memory usageReturns a list of children activities.getCondition
(Class subclass) Returns Condition associated with this Activity typeReturns the duration field of the activity.getEnd()
Returns the end time of this activity instance.getGroup()
getID()
Returns ID associated with instanceReturns ID of activity as string, not UUID objectgetName()
Returns the name attribute of the activity.getNotes()
Object[]
This method is used to return the parameters to an activity as objects, so that they can be used to instantiate a new activity or write to an output file.Returns the parent Activity instance of the calling object.getStart()
Returns the start time of this activity instancegetType()
Returns the name of the activity type, which is based on the class name.Returns a Window with (getStart(), getEnd())boolean
void
model()
Provided for backwards compatibility, this function is called by modelFunc() if modelFunc() has not been specialized.Method called by simulation engine when it reaches the Activity instance's stated start time, which is usually triggered by a REMODEL command being issued.static Time
now()
Returns the current modeling time.void
This method will be called by resources changing - if the condition becomes true we want to call dispatchOnCondition() Should not be called manually by adapters.void
Recursively remove all children from the instance list, but do not clear the children arrays.void
schedule()
Should not be called by adapters, only through Command interface Doesn't actually begin on-line scheduling, just sets it up so it will begin when the next remodel occursvoid
sequence()
Generate sequence fragments that will be added to Sequence objects and eventually written out to files.void
setChildren
(List<Activity> list) Assigns the children list to the given parameter - only used for redecompose commandMain method that adapters can override in order to set condition that will trigger dispatchOnCondition() to run Needs to be overwritten by things that want to be scheduled by get_windows or dispatchOnCondition - template method design patternvoid
setDuration
(Duration newDuration) Updates the duration of the activity, which also updates the end time.void
setEndByChangingDuration
(Time newEnd) This method updates the duration of the activity to give the desired end time.void
Sets the 'group' of the activity, which can be used to assign to GUI legends, waterfall groups, or filtersvoid
Updates the ID of an activity.void
called at the beginning of a modeling run for schedulers by the enginevoid
Sets the name parameter of the activity.void
Sets the 'Notes' attached to the activity, which can be used to explain why a human or scheduler placed an activity where it didvoid
Sets the calling object's parent to the parameter object.void
Only should be used by engine, not adapters.void
Call when instantiating a new activity during decomposition.void
spawnWithNotes
(Activity act, String notes) Calls spawn() then sets the notes field of the supplied activity to the supplied stringvoid
Should not be called by adapters, only by engine.void
waitFor is just a wrapper for waitUntilReturns a Waiter object that can be returned to the modeling engine to execute after waiting for the given amount of time.Returns a Waiter object that can be returned to the modeling engine to execute after waiting for the given amount of time.waitForSignal
(String signalName) A call to this method blocks until another activity throws a Signal of the same String signalName that this activity instance is waiting onwaitForSignal
(String signalName, Consumer<Map> func) Returns a Waiter object that can be returned to the modeling engine to execute after the given signal is raised.waitForSignal
(String signalName, Function<Map, Waiter> func) Returns a Waiter object that can be returned to the modeling engine to execute after the given signal is raised.Executes the given function starting at time startTime up to and including time endTime with each successive time incremented by timeStep.waitLoop
(Time startTime, Time endTime, Duration timeStep, BiConsumer<Time, Time> func, Consumer<Time> endFunc) Executes the given function starting at time startTime up to but not including time endTime with each successive time incremented by timeStep.waitLoop
(Time startTime, Time endTime, Duration timeStep, BiConsumer<Time, Time> func, Function<Time, Waiter> endFunc) Executes the given function starting at time startTime up to but not including time endTime with each successive time incremented by timeStep.Executes the given function starting at time startTime up to and including time endTime with each successive time incremented by timeStep.waitLoop
(Time startTime, Time endTime, Duration timeStep, Consumer<Time> func, Consumer<Time> endFunc) Executes the given function starting at time startTime up to but not including time endTime with each successive time incremented by timeStep.void
Main method adapters have of changing resource timelines at different times during the execution of an activity Without this, all resource changes will happen at the modeled start time of an activity instanceReturns a Waiter object that can be returned to the modeling engine to execute at a time in the future.Returns a Waiter object that can be returned to the modeling engine to execute at a time in the future.
-
Constructor Details
-
Activity
Superconstructor for all Activity types - must be passed all arguments that child class is- Parameters:
t
- The time the activity instance should be startedvarargs
- all other parameters to the child class's constructor
-
-
Method Details
-
decompose
public void decompose()Method called after Activity constructor where one can create child activities according to whatever algorithm and combination of parameters is desired. Blank in the base class but expected to be extended in the subclass an adapter writes if they want to create child activities in that manner. -
modelFunc
Method called by simulation engine when it reaches the Activity instance's stated start time, which is usually triggered by a REMODEL command being issued. Blank in the base class but expected to be filled out by an adapter if they want to have this instance change resource timelines.- Returns:
- null or a Waiter object with a function to be executed in the future.
- Throws:
InterruptedException
- because we can call waitForSignal and have to be interrupted, modeling can (but doesn't have to) throw this exception
-
model
Provided for backwards compatibility, this function is called by modelFunc() if modelFunc() has not been specialized.- Throws:
InterruptedException
- because we can call waitForSignal and have to be interrupted, modeling can (but doesn't have to) throw this exception
-
sequence
public void sequence()Generate sequence fragments that will be added to Sequence objects and eventually written out to files. This is the interface by which command expansion occurs in Blackbird. Blank in the base class but all types that want to write to sequences should fill this out. -
setCondition
Main method that adapters can override in order to set condition that will trigger dispatchOnCondition() to run Needs to be overwritten by things that want to be scheduled by get_windows or dispatchOnCondition - template method design pattern -
setInitialCondition
public void setInitialCondition()called at the beginning of a modeling run for schedulers by the engine -
spawn
Call when instantiating a new activity during decomposition. This method adds the new activity to the children array of the parent activity.- Parameters:
act
-
-
spawnWithNotes
Calls spawn() then sets the notes field of the supplied activity to the supplied string- Parameters:
act
-notes
-
-
getParent
Returns the parent Activity instance of the calling object. All instances have at most one parent.- Returns:
- Activity object, can be null
-
setParent
Sets the calling object's parent to the parameter object. Should only be called by Blackbird core, not by adapters- Parameters:
act
- Activity object
-
deleteChildren
public void deleteChildren()This method recursively deletes all children of the activity. -
removeChildrenFromInstanceList
public void removeChildrenFromInstanceList()Recursively remove all children from the instance list, but do not clear the children arrays. -
addChildrenToInstanceList
public void addChildrenToInstanceList()Recursively add all children to the instance list. -
clearChildrenArrayWithoutDeletingThem
public void clearChildrenArrayWithoutDeletingThem()Not recursive - just child list of this activity, and doesn't remove anything from the instance list -
getChildren
Returns a list of children activities. -
setChildren
Assigns the children list to the given parameter - only used for redecompose command -
isTopLevelActivity
public boolean isTopLevelActivity()- Returns:
- boolean capturing whether the activity is the top of the decomposition tree
-
waitUntil
Main method adapters have of changing resource timelines at different times during the execution of an activity Without this, all resource changes will happen at the modeled start time of an activity instance- Parameters:
t
- Time that the engine should wait until in simulated time before re-waking up the activity and resuming its model() section
-
waitFor
waitFor is just a wrapper for waitUntil- Parameters:
d
- Duration that the engine should wait for in simulated time before re-waking up the activity and resuming its model() section
-
waitForSignal
A call to this method blocks until another activity throws a Signal of the same String signalName that this activity instance is waiting on- Parameters:
signalName
-- Returns:
- Map that contains the contents of the signal
- Throws:
InterruptedException
-
waitUntil
Returns a Waiter object that can be returned to the modeling engine to execute at a time in the future.- Parameters:
t
- time in future to execute the given functionfunc
- the given function- Returns:
- Waiter object
-
waitUntil
Returns a Waiter object that can be returned to the modeling engine to execute at a time in the future.- Parameters:
t
- time in future to execute the given functionfunc
- the given function- Returns:
- Waiter object
-
waitLoop
public Waiter waitLoop(Time startTime, Time endTime, Duration timeStep, BiConsumer<Time, Time> func, Function<Time, Waiter> endFunc) Executes the given function starting at time startTime up to but not including time endTime with each successive time incremented by timeStep. At time endTime the function endFunc is executed.- Parameters:
startTime
- the start time of the loop.endTime
- the end time of the loop.timeStep
- step duration between times.func
- function executed at each time step in [startTime,endTime)endFunc
- function executed at endTime which can return a Waiter to be executed in the future.- Returns:
- a Waiter which implements the loop.
-
waitLoop
public Waiter waitLoop(Time startTime, Time endTime, Duration timeStep, BiConsumer<Time, Time> func, Consumer<Time> endFunc) Executes the given function starting at time startTime up to but not including time endTime with each successive time incremented by timeStep. At time endTime the function endFunc is executed.- Parameters:
startTime
- the start time of the loop.endTime
- the end time of the loop.timeStep
- step duration between times.func
- function executed at each time step in [startTime,endTime)endFunc
- function executed at endTime.- Returns:
- a Waiter which implements the loop.
-
waitLoop
public Waiter waitLoop(Time startTime, Time endTime, Duration timeStep, Consumer<Time> func, Consumer<Time> endFunc) Executes the given function starting at time startTime up to but not including time endTime with each successive time incremented by timeStep. At time endTime the function endFunc is executed.- Parameters:
startTime
- the start time of the loop.endTime
- the end time of the loop.timeStep
- step duration between times.func
- function executed at each time step in [startTime,endTime)endFunc
- function executed at endTime.- Returns:
- a Waiter which implements the loop.
-
waitLoop
Executes the given function starting at time startTime up to and including time endTime with each successive time incremented by timeStep.- Parameters:
startTime
- the start time of the loop.endTime
- the end time of the loop.timeStep
- step duration between times.func
- function executed at each time step in [startTime,endTime]- Returns:
- a Waiter which implements the loop.
-
waitLoop
Executes the given function starting at time startTime up to and including time endTime with each successive time incremented by timeStep.- Parameters:
startTime
- the start time of the loop.endTime
- the end time of the loop.timeStep
- step duration between times.func
- function executed at each time step in [startTime,endTime]- Returns:
- a Waiter which implements the loop.
-
waitFor
Returns a Waiter object that can be returned to the modeling engine to execute after waiting for the given amount of time.- Parameters:
d
- duration to wait before executing the given function.func
- the given function- Returns:
- Waiter object
-
waitFor
Returns a Waiter object that can be returned to the modeling engine to execute after waiting for the given amount of time.- Parameters:
d
- duration to wait before executing the given function.func
- the given function- Returns:
- Waiter object
-
waitForSignal
Returns a Waiter object that can be returned to the modeling engine to execute after the given signal is raised.- Parameters:
signalName
- signal name to wait to be raised.func
- the given function to run when the signal is raised.- Returns:
- Waiter object
-
waitForSignal
Returns a Waiter object that can be returned to the modeling engine to execute after the given signal is raised.- Parameters:
signalName
- signal name to wait to be raised.func
- the given function to run when the signal is raised.- Returns:
- Waiter object
-
schedule
public void schedule()Should not be called by adapters, only through Command interface Doesn't actually begin on-line scheduling, just sets it up so it will begin when the next remodel occurs -
stopScheduling
public void stopScheduling()Should not be called by adapters, only by engine. Once a scheduler has run in one remodel, we typically don't want it to run a second time and this achieves that. -
setDuration
Updates the duration of the activity, which also updates the end time. Cannot be negative.- Parameters:
newDuration
-
-
setEndByChangingDuration
This method updates the duration of the activity to give the desired end time. The start time of the activity is kept constant. This method is safe to use during modeling.- Parameters:
newEnd
-
-
setName
Sets the name parameter of the activity. This determines how the activity name is displayed in the output products or GUIs.- Parameters:
newName
-
-
getStart
Returns the start time of this activity instance- Returns:
-
getEnd
Returns the end time of this activity instance. This is computed by taking the start time from getStart() and adding the duration returned from getDuration(). It does not have anything to do with when the last modeled time that the model() section of the instance sees.- Returns:
-
getWindow
Returns a Window with (getStart(), getEnd())- Returns:
-
getDuration
Returns the duration field of the activity. This is set by setDuration() and does not necessarily have anything to do with how long the model() section of the instance takes to execute in simulated time.- Returns:
-
getName
Returns the name attribute of the activity. Can be set with setName()- Returns:
-
getGroup
- Returns:
- The 'group' of the activity, which can be used to assign to GUI legends, waterfall groups, or filters
-
setGroup
Sets the 'group' of the activity, which can be used to assign to GUI legends, waterfall groups, or filters- Parameters:
group
-
-
getNotes
- Returns:
- The 'Notes' attached to the activity, which can be used to explain why a human or scheduler placed an activity where it did
-
setNotes
Sets the 'Notes' attached to the activity, which can be used to explain why a human or scheduler placed an activity where it did- Parameters:
notes
-
-
now
Returns the current modeling time. Convenience method for adapters.- Returns:
-
getType
Returns the name of the activity type, which is based on the class name.- Returns:
-
compareTo
Natural comparator of Activity instances is by start time- Specified by:
compareTo
in interfaceComparable<Activity>
- Parameters:
act2
-- Returns:
-
setThread
Only should be used by engine, not adapters. Attaches WaitProvider to Activity instance for later processing.- Parameters:
t
-
-
detachThread
public void detachThread()We do this so there will be no live references to a thread after it runs, halving memory usage -
getParameterObjects
This method is used to return the parameters to an activity as objects, so that they can be used to instantiate a new activity or write to an output file.- Returns:
-
setID
Updates the ID of an activity.- Parameters:
newID
-
-
getID
Returns ID associated with instance- Returns:
-
getIDString
Returns ID of activity as string, not UUID object- Returns:
-
getCondition
Returns Condition associated with this Activity type- Parameters:
subclass
-- Returns:
-
propertyChange
This method will be called by resources changing - if the condition becomes true we want to call dispatchOnCondition() Should not be called manually by adapters.- Specified by:
propertyChange
in interfacePropertyChangeListener
-