Package io.engineblock.core
Class ScenarioController
- java.lang.Object
-
- io.engineblock.core.ScenarioController
-
public class ScenarioController extends java.lang.ObjectA ScenarioController provides a way to start Activities, modify them while running, and forceStopMotors, pause or restart them.
-
-
Constructor Summary
Constructors Constructor Description ScenarioController()
-
Method Summary
Modifier and Type Method Description voidapply(java.util.Map<java.lang.String,java.lang.String> appliedParams)Apply any parameter changes to a defined activity, or start a new one.booleanawaitActivity(io.engineblock.activityimpl.ActivityDef activityDef)booleanawaitActivity(java.lang.String alias)booleanawaitActivity(java.util.Map<java.lang.String,java.lang.String> activityDefMap)booleanawaitCompletion(int waitTimeMillis)Await completion of all running activities, but do not force shutdownActivity.voidforceStopScenario(int waitTimeMillis)Force the scenario to stop running.io.engineblock.activityimpl.ActivityDefgetActivityDef(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()booleanisRunningActivity(io.engineblock.activityimpl.ActivityDef activityDef)booleanisRunningActivity(java.lang.String alias)booleanisRunningActivity(java.util.Map<java.lang.String,java.lang.String> activityDefMap)voidmodify(java.lang.String alias, java.lang.String param, java.lang.String value)Modify one of the parameters in a defined activity.voidreportMetrics()voidrun(int timeout, io.engineblock.activityimpl.ActivityDef activityDef)Synchronously run the defined activity with a timeout in seconds.voidrun(int timeout, java.lang.String activityDefString)voidrun(int timeout, java.util.Map<java.lang.String,java.lang.String> activityDefMap)voidrun(io.engineblock.activityimpl.ActivityDef activityDef)voidrun(java.lang.String activityDefString)voidrun(java.util.Map<java.lang.String,java.lang.String> activityDefMap)voidstart(io.engineblock.activityimpl.ActivityDef activityDef)Start an activity, given the activity definition for it.voidstart(java.lang.String alias)Start an activity, given the name by which it is known already in the scenario.voidstart(java.util.Map<java.lang.String,java.lang.String> activityDefMap)Start an activity, given a map which holds the activity definition for it.voidstop(io.engineblock.activityimpl.ActivityDef activityDef)Stop an activity, given an activity def.voidstop(java.lang.String alias)Stop an activity, given the name by which it is known already in the scenario.voidstop(java.util.Map<java.lang.String,java.lang.String> activityDefMap)Stop an activity, given an activity def map.voidwaitMillis(long waitMillis)Wait for a bit.
-
-
-
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 namevalue- 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()
-
-