Class Activity

java.lang.Object
gov.nasa.jpl.activity.Activity
All Implemented Interfaces:
PropertyChangeListener, Comparable<Activity>, EventListener
Direct Known Subclasses:
InitialConditionActivity

public class Activity extends Object implements Comparable<Activity>, PropertyChangeListener
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
    Constructor
    Description
    Activity(Time t, Object... varargs)
    Superconstructor for all Activity types - must be passed all arguments that child class is
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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 list
    int
    Natural comparator of Activity instances is by start time
    void
    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 usage
    Returns a list of children activities.
    getCondition(Class subclass)
    Returns Condition associated with this Activity type
    Returns the duration field of the activity.
    Returns the end time of this activity instance.
     
    Returns ID associated with instance
    Returns ID of activity as string, not UUID object
    Returns the name attribute of the activity.
     
    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.
    Returns the start time of this activity instance
    Returns the name of the activity type, which is based on the class name.
    Returns a Window with (getStart(), getEnd())
    boolean
     
    void
    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
    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
    void
    Generate sequence fragments that will be added to Sequence objects and eventually written out to files.
    void
    Assigns the children list to the given parameter - only used for redecompose command
    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
    void
    setDuration(Duration newDuration)
    Updates the duration of the activity, which also updates the end time.
    void
    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 filters
    void
    setID(UUID newID)
    Updates the ID of an activity.
    void
    called at the beginning of a modeling run for schedulers by the engine
    void
    setName(String newName)
    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 did
    void
    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
    Calls spawn() then sets the notes field of the supplied activity to the supplied string
    void
    Should not be called by adapters, only by engine.
    void
    waitFor is just a wrapper for waitUntil
    Returns 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 on
    waitForSignal(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.
    waitLoop(Time startTime, Time endTime, Duration timeStep, BiConsumer<Time,Time> func)
    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.
    waitLoop(Time startTime, Time endTime, Duration timeStep, Consumer<Time> func)
    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 instance
    Returns 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Activity

      public Activity(Time t, Object... varargs)
      Superconstructor for all Activity types - must be passed all arguments that child class is
      Parameters:
      t - The time the activity instance should be started
      varargs - 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

      public Waiter modelFunc() throws InterruptedException
      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

      public void model() throws InterruptedException
      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

      public Condition 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

      public void spawn(Activity act)
      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

      public void spawnWithNotes(Activity act, String notes)
      Calls spawn() then sets the notes field of the supplied activity to the supplied string
      Parameters:
      act -
      notes -
    • getParent

      public Activity getParent()
      Returns the parent Activity instance of the calling object. All instances have at most one parent.
      Returns:
      Activity object, can be null
    • setParent

      public void setParent(Activity act)
      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

      public List<Activity> getChildren()
      Returns a list of children activities.
    • setChildren

      public void setChildren(List<Activity> list)
      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

      public void waitUntil(Time t)
      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

      public void waitFor(Duration d)
      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

      public Map waitForSignal(String signalName) throws InterruptedException
      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

      public Waiter waitUntil(Time t, Supplier<Waiter> func)
      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 function
      func - the given function
      Returns:
      Waiter object
    • waitUntil

      public Waiter waitUntil(Time t, Runnable func)
      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 function
      func - 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

      public Waiter waitLoop(Time startTime, Time endTime, Duration timeStep, Consumer<Time> func)
      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

      public Waiter waitLoop(Time startTime, Time endTime, Duration timeStep, BiConsumer<Time,Time> func)
      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

      public Waiter waitFor(Duration d, Supplier<Waiter> func)
      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

      public Waiter waitFor(Duration d, Runnable func)
      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

      public Waiter waitForSignal(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.
      Parameters:
      signalName - signal name to wait to be raised.
      func - the given function to run when the signal is raised.
      Returns:
      Waiter object
    • waitForSignal

      public Waiter 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.
      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

      public void setDuration(Duration newDuration)
      Updates the duration of the activity, which also updates the end time. Cannot be negative.
      Parameters:
      newDuration -
    • setEndByChangingDuration

      public void setEndByChangingDuration(Time newEnd)
      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

      public void setName(String newName)
      Sets the name parameter of the activity. This determines how the activity name is displayed in the output products or GUIs.
      Parameters:
      newName -
    • getStart

      public Time getStart()
      Returns the start time of this activity instance
      Returns:
    • getEnd

      public Time 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

      public Window getWindow()
      Returns a Window with (getStart(), getEnd())
      Returns:
    • getDuration

      public Duration 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

      public String getName()
      Returns the name attribute of the activity. Can be set with setName()
      Returns:
    • getGroup

      public String getGroup()
      Returns:
      The 'group' of the activity, which can be used to assign to GUI legends, waterfall groups, or filters
    • setGroup

      public void setGroup(String group)
      Sets the 'group' of the activity, which can be used to assign to GUI legends, waterfall groups, or filters
      Parameters:
      group -
    • getNotes

      public String 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

      public void setNotes(String notes)
      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

      public static Time now()
      Returns the current modeling time. Convenience method for adapters.
      Returns:
    • getType

      public String getType()
      Returns the name of the activity type, which is based on the class name.
      Returns:
    • compareTo

      public int compareTo(Activity act2)
      Natural comparator of Activity instances is by start time
      Specified by:
      compareTo in interface Comparable<Activity>
      Parameters:
      act2 -
      Returns:
    • setThread

      public void setThread(WaitProvider t)
      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

      public Object[] 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

      public void setID(UUID newID)
      Updates the ID of an activity.
      Parameters:
      newID -
    • getID

      public UUID getID()
      Returns ID associated with instance
      Returns:
    • getIDString

      public String getIDString()
      Returns ID of activity as string, not UUID object
      Returns:
    • getCondition

      public Condition getCondition(Class subclass)
      Returns Condition associated with this Activity type
      Parameters:
      subclass -
      Returns:
    • propertyChange

      public void propertyChange(PropertyChangeEvent evt)
      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 interface PropertyChangeListener