Class ScenarioController


  • public class ScenarioController
    extends java.lang.Object
    A ScenarioController provides a way to start Activities, modify them while running, and forceStopMotors, pause or restart them.
    • Method Summary

      Modifier and Type Method Description
      void apply​(java.util.Map<java.lang.String,​java.lang.String> appliedParams)
      Apply any parameter changes to a defined activity, or start a new one.
      boolean awaitActivity​(io.engineblock.activityimpl.ActivityDef activityDef)  
      boolean awaitActivity​(java.lang.String alias)  
      boolean awaitActivity​(java.util.Map<java.lang.String,​java.lang.String> activityDefMap)  
      boolean awaitCompletion​(int waitTimeMillis)
      Await completion of all running activities, but do not force shutdownActivity.
      void forceStopScenario​(int waitTimeMillis)
      Force the scenario to stop running.
      io.engineblock.activityimpl.ActivityDef getActivityDef​(java.lang.String alias)
      Get the named activity def, if it is known to this scenario.
      java.util.List<io.engineblock.activityimpl.ActivityDef> getActivityDefs()
      Return all the activity definitions that are known to this scenario.
      java.util.Map<java.lang.String,​ActivityExecutor> getActivityExecutorMap()  
      java.util.Set<java.lang.String> getAliases()
      Return all the names of the activites that are known to this scenario.
      java.util.Collection<io.engineblock.activityapi.core.ProgressMeter> getProgressMeters()  
      boolean isRunningActivity​(io.engineblock.activityimpl.ActivityDef activityDef)  
      boolean isRunningActivity​(java.lang.String alias)  
      boolean isRunningActivity​(java.util.Map<java.lang.String,​java.lang.String> activityDefMap)  
      void modify​(java.lang.String alias, java.lang.String param, java.lang.String value)
      Modify one of the parameters in a defined activity.
      void reportMetrics()  
      void run​(int timeout, io.engineblock.activityimpl.ActivityDef activityDef)
      Synchronously run the defined activity with a timeout in seconds.
      void run​(int timeout, java.lang.String activityDefString)  
      void run​(int timeout, java.util.Map<java.lang.String,​java.lang.String> activityDefMap)  
      void run​(io.engineblock.activityimpl.ActivityDef activityDef)  
      void run​(java.lang.String activityDefString)  
      void run​(java.util.Map<java.lang.String,​java.lang.String> activityDefMap)  
      void start​(io.engineblock.activityimpl.ActivityDef activityDef)
      Start an activity, given the activity definition for it.
      void start​(java.lang.String alias)
      Start an activity, given the name by which it is known already in the scenario.
      void start​(java.util.Map<java.lang.String,​java.lang.String> activityDefMap)
      Start an activity, given a map which holds the activity definition for it.
      void stop​(io.engineblock.activityimpl.ActivityDef activityDef)
      Stop an activity, given an activity def.
      void stop​(java.lang.String alias)
      Stop an activity, given the name by which it is known already in the scenario.
      void stop​(java.util.Map<java.lang.String,​java.lang.String> activityDefMap)
      Stop an activity, given an activity def map.
      void waitMillis​(long waitMillis)
      Wait for a bit.
      • Methods inherited from class java.lang.Object

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

      • ScenarioController

        public ScenarioController()
    • Method Detail

      • start

        public void start​(io.engineblock.activityimpl.ActivityDef activityDef)
        Start an activity, given the activity definition for it. The activity will be known in the scenario by the alias parameter.
        Parameters:
        activityDef - string in alias=value1;type=value2;... format
      • start

        public void start​(java.util.Map<java.lang.String,​java.lang.String> activityDefMap)
        Start an activity, given a map which holds the activity definition for it. The activity will be known in the scenario by the alias parameter.
        Parameters:
        activityDefMap - A map containing the activity definition
      • start

        public void start​(java.lang.String alias)
        Start an activity, given the name by which it is known already in the scenario. This is useful if you have stopped an activity and want to start it again.
        Parameters:
        alias - the alias of an activity that is already known to the scenario
      • run

        public void run​(int timeout,
                        java.util.Map<java.lang.String,​java.lang.String> activityDefMap)
      • run

        public void run​(int timeout,
                        io.engineblock.activityimpl.ActivityDef activityDef)
        Synchronously run the defined activity with a timeout in seconds.
        Parameters:
        timeout - seconds to await completion of the activity.
        activityDef - A definition for an activity to run
      • run

        public void run​(int timeout,
                        java.lang.String activityDefString)
      • run

        public void run​(java.util.Map<java.lang.String,​java.lang.String> activityDefMap)
      • run

        public void run​(java.lang.String activityDefString)
      • run

        public void run​(io.engineblock.activityimpl.ActivityDef activityDef)
      • isRunningActivity

        public boolean isRunningActivity​(java.lang.String alias)
      • isRunningActivity

        public boolean isRunningActivity​(io.engineblock.activityimpl.ActivityDef activityDef)
      • isRunningActivity

        public boolean isRunningActivity​(java.util.Map<java.lang.String,​java.lang.String> activityDefMap)
      • stop

        public void stop​(io.engineblock.activityimpl.ActivityDef activityDef)

        Stop an activity, given an activity def. The only part of the activity def that is important is the alias parameter. This method retains the activity def signature to provide convenience for scripting.

        For example, sc.stop("alias=foo")

        Parameters:
        activityDef - An activity def, including at least the alias parameter.
      • stop

        public void stop​(java.util.Map<java.lang.String,​java.lang.String> activityDefMap)

        Stop an activity, given an activity def map. The only part of the map that is important is the alias parameter. This method retains the map signature to provide convenience for scripting.

        Parameters:
        activityDefMap - A map, containing at least the alias parameter
      • stop

        public void stop​(java.lang.String alias)
        Stop an activity, given the name by which it is known already in the scenario. This causes the activity to stop all threads, but keeps the thread objects handy for starting again. This can be useful for certain testing scenarios in which you want to stop some workloads and start others based on other conditions.
        Parameters:
        alias - The name of the activity that is already known to the scenario
      • modify

        public void modify​(java.lang.String alias,
                           java.lang.String param,
                           java.lang.String value)
        Modify one of the parameters in a defined activity. Any observing activity components will be notified of the changes made to activity parameters.
        Parameters:
        alias - The name of an activity that is already known to the scenario.
        param - The parameter name
        value - a new parameter value
      • apply

        public void apply​(java.util.Map<java.lang.String,​java.lang.String> appliedParams)
        Apply any parameter changes to a defined activity, or start a new one. This method is syntactical sugar for scripting. Each of the parameters in the map is checked against existing values, and per-field modifications are applied one at a time, only if the values have changed.
        Parameters:
        appliedParams - Map of new values.
      • waitMillis

        public void waitMillis​(long waitMillis)
        Wait for a bit. This is not the best approach, and will be replace with a different system in the future.
        Parameters:
        waitMillis - time to wait, in milliseconds
      • getAliases

        public java.util.Set<java.lang.String> getAliases()
        Return all the names of the activites that are known to this scenario.
        Returns:
        set of activity names
      • getActivityDefs

        public java.util.List<io.engineblock.activityimpl.ActivityDef> getActivityDefs()
        Return all the activity definitions that are known to this scenario.
        Returns:
        list of activity defs
      • getActivityDef

        public io.engineblock.activityimpl.ActivityDef getActivityDef​(java.lang.String alias)
        Get the named activity def, if it is known to this scenario.
        Parameters:
        alias - The name by which the activity is known to this scenario.
        Returns:
        an ActivityDef instance
        Throws:
        java.lang.RuntimeException - if the alias is not known to the scenario
      • forceStopScenario

        public void forceStopScenario​(int waitTimeMillis)
        Force the scenario to stop running. Stop all activity threads, and after waitTimeMillis, force stop all activity threads. An activity will stop its threads cooperatively in this time as long as the internal cycles complete before the timer expires.
        Parameters:
        waitTimeMillis - grace period during which an activity may cooperatively shut down
      • awaitCompletion

        public boolean awaitCompletion​(int waitTimeMillis)
        Await completion of all running activities, but do not force shutdownActivity. This method is meant to provide the blocking point for calling logic. It waits.
        Parameters:
        waitTimeMillis - The time to wait, usually set very high
        Returns:
        true, if all activities completed before the timer expired, false otherwise
      • awaitActivity

        public boolean awaitActivity​(java.util.Map<java.lang.String,​java.lang.String> activityDefMap)
      • awaitActivity

        public boolean awaitActivity​(java.lang.String alias)
      • awaitActivity

        public boolean awaitActivity​(io.engineblock.activityimpl.ActivityDef activityDef)
      • getActivityExecutorMap

        public java.util.Map<java.lang.String,​ActivityExecutor> getActivityExecutorMap()
        Returns:
        an unmodifyable String to executor map of all activities known to this scenario
      • reportMetrics

        public void reportMetrics()
      • getProgressMeters

        public java.util.Collection<io.engineblock.activityapi.core.ProgressMeter> getProgressMeters()