Package io.engineblock.activityimpl
Class SimpleActivity
- java.lang.Object
-
- io.engineblock.activityimpl.SimpleActivity
-
- All Implemented Interfaces:
Activity,ActivityDefObserver,java.lang.Comparable<Activity>
public class SimpleActivity extends java.lang.Object implements Activity
A default implementation of an Activity, suitable for building upon.
-
-
Field Summary
Fields Modifier and Type Field Description protected ActivityDefactivityDef
-
Constructor Summary
Constructors Constructor Description SimpleActivity(ActivityDef activityDef)SimpleActivity(java.lang.String activityDefString)
-
Method Summary
Modifier and Type Method Description voidcloseAutoCloseables()Close all autocloseables that have been registered with this Activity.intcompareTo(Activity o)ActionDispensergetActionDispenserDelegate()ActivityControllergetActivityController()ActivityDefgetActivityDef()RateLimitergetCycleLimiter()Get the current cycle rate limiter for this activity.RateLimitergetCycleRateLimiter(java.util.function.Supplier<? extends RateLimiter> s)Get or create the cycle rate limiter in a safe way.InputDispensergetInputDispenserDelegate()ActivityInstrumentationgetInstrumentation()Get or create the instrumentation needed for this activity.OutputDispensergetMarkerDispenserDelegate()MotorDispensergetMotorDispenserDelegate()RateLimitergetPhaseLimiter()Get the current phase rate limiter for this activity.RateLimitergetPhaseRateLimiter(java.util.function.Supplier<? extends RateLimiter> supplier)Get or create the phaseRateLimiterin a concurrent-safe way.IntPredicateDispensergetResultFilterDispenserDelegate()com.codahale.metrics.TimergetResultTimer()RunStategetRunState()RateLimitergetStrideLimiter()Get the current stride rate limiter for this activity.RateLimitergetStrideRateLimiter(java.util.function.Supplier<? extends RateLimiter> s)Get or create the strideRateLimiterin a concurrent-safe way.voidinitActivity()voidonActivityDefUpdate(ActivityDef activityDef)voidregisterAutoCloseable(java.lang.AutoCloseable closeable)Register an object which should be closed after this activity is shutdown.voidsetActionDispenserDelegate(ActionDispenser actionDispenser)voidsetActivityController(ActivityController activityController)Provide the activity with the controls needed to stop itself.voidsetCycleLimiter(RateLimiter rateLimiter)Set the cycle rate limiter for this activity.voidsetDefaultsFromOpSequence(OpSequence seq)Modify the provided ActivityDef with defaults for stride and cycles, if they haven't been provided, based on the length of the sequence as determined by the provided ratios.voidsetInputDispenserDelegate(InputDispenser inputDispenser)voidsetMotorDispenserDelegate(MotorDispenser motorDispenser)voidsetOutputDispenserDelegate(OutputDispenser outputDispenser)voidsetPhaseLimiter(RateLimiter rateLimiter)Set the phase rate limiter for this activity.voidsetResultFilterDispenserDelegate(IntPredicateDispenser resultFilterDispenser)voidsetRunState(RunState runState)voidsetStrideLimiter(RateLimiter rateLimiter)Set the stride rate limiter for this activity.java.lang.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.engineblock.activityapi.core.Activity
getAlias, getCycleSummary, getParams, shutdownActivity
-
-
-
-
Field Detail
-
activityDef
protected ActivityDef activityDef
-
-
Constructor Detail
-
SimpleActivity
public SimpleActivity(ActivityDef activityDef)
-
SimpleActivity
public SimpleActivity(java.lang.String activityDefString)
-
-
Method Detail
-
initActivity
public void initActivity()
- Specified by:
initActivityin interfaceActivity
-
getRunState
public RunState getRunState()
- Specified by:
getRunStatein interfaceActivity
-
setRunState
public void setRunState(RunState runState)
- Specified by:
setRunStatein interfaceActivity
-
getMotorDispenserDelegate
public final MotorDispenser getMotorDispenserDelegate()
- Specified by:
getMotorDispenserDelegatein interfaceActivity
-
setMotorDispenserDelegate
public final void setMotorDispenserDelegate(MotorDispenser motorDispenser)
- Specified by:
setMotorDispenserDelegatein interfaceActivity
-
getInputDispenserDelegate
public final InputDispenser getInputDispenserDelegate()
- Specified by:
getInputDispenserDelegatein interfaceActivity
-
setInputDispenserDelegate
public final void setInputDispenserDelegate(InputDispenser inputDispenser)
- Specified by:
setInputDispenserDelegatein interfaceActivity
-
getActionDispenserDelegate
public final ActionDispenser getActionDispenserDelegate()
- Specified by:
getActionDispenserDelegatein interfaceActivity
-
setActionDispenserDelegate
public final void setActionDispenserDelegate(ActionDispenser actionDispenser)
- Specified by:
setActionDispenserDelegatein interfaceActivity
-
getResultFilterDispenserDelegate
public IntPredicateDispenser getResultFilterDispenserDelegate()
- Specified by:
getResultFilterDispenserDelegatein interfaceActivity
-
setResultFilterDispenserDelegate
public void setResultFilterDispenserDelegate(IntPredicateDispenser resultFilterDispenser)
- Specified by:
setResultFilterDispenserDelegatein interfaceActivity
-
getMarkerDispenserDelegate
public OutputDispenser getMarkerDispenserDelegate()
- Specified by:
getMarkerDispenserDelegatein interfaceActivity
-
setOutputDispenserDelegate
public void setOutputDispenserDelegate(OutputDispenser outputDispenser)
- Specified by:
setOutputDispenserDelegatein interfaceActivity
-
getActivityDef
public ActivityDef getActivityDef()
- Specified by:
getActivityDefin interfaceActivity
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
compareTo
public int compareTo(Activity o)
- Specified by:
compareToin interfacejava.lang.Comparable<Activity>
-
getActivityController
public ActivityController getActivityController()
- Specified by:
getActivityControllerin interfaceActivity
-
setActivityController
public void setActivityController(ActivityController activityController)
Description copied from interface:ActivityProvide the activity with the controls needed to stop itself.- Specified by:
setActivityControllerin interfaceActivity- Parameters:
activityController- The dedicated control interface for this activity
-
registerAutoCloseable
public void registerAutoCloseable(java.lang.AutoCloseable closeable)
Description copied from interface:ActivityRegister an object which should be closed after this activity is shutdown.- Specified by:
registerAutoCloseablein interfaceActivity- Parameters:
closeable- An Autocloseable object
-
closeAutoCloseables
public void closeAutoCloseables()
Description copied from interface:ActivityClose all autocloseables that have been registered with this Activity.- Specified by:
closeAutoCloseablesin interfaceActivity
-
getCycleLimiter
public RateLimiter getCycleLimiter()
Description copied from interface:ActivityGet the current cycle rate limiter for this activity. The cycle rate limiter is used to throttle the rate at which cycles are dispatched across all threads in the activity- Specified by:
getCycleLimiterin interfaceActivity- Returns:
- the cycle
RateLimiter
-
setCycleLimiter
public void setCycleLimiter(RateLimiter rateLimiter)
Description copied from interface:ActivitySet the cycle rate limiter for this activity. This method should only be used in a non-concurrent context. Otherwise, the supplier versionActivity.getCycleRateLimiter(Supplier)should be used.- Specified by:
setCycleLimiterin interfaceActivity- Parameters:
rateLimiter- The cycleRateLimiterfor this activity
-
getCycleRateLimiter
public RateLimiter getCycleRateLimiter(java.util.function.Supplier<? extends RateLimiter> s)
Description copied from interface:ActivityGet or create the cycle rate limiter in a safe way. Implementations should ensure that this method is synchronized or that each requester gets the same cycle rate limiter for the activity.- Specified by:
getCycleRateLimiterin interfaceActivity- Parameters:
s- ARateLimiterSupplier- Returns:
- An extant or newly created cycle
RateLimiter
-
getStrideLimiter
public RateLimiter getStrideLimiter()
Description copied from interface:ActivityGet the current stride rate limiter for this activity. The stride rate limiter is used to throttle the rate at which new strides are dispatched across all threads in an activity.- Specified by:
getStrideLimiterin interfaceActivity- Returns:
- The stride
RateLimiter
-
setStrideLimiter
public void setStrideLimiter(RateLimiter rateLimiter)
Description copied from interface:ActivitySet the stride rate limiter for this activity. This method should only be used in a non-concurrent context. Otherwise, the supplier versionActivity.getStrideRateLimiter(Supplier)} should be used.- Specified by:
setStrideLimiterin interfaceActivity- Parameters:
rateLimiter- The strideRateLimiterfor this activity.
-
getStrideRateLimiter
public RateLimiter getStrideRateLimiter(java.util.function.Supplier<? extends RateLimiter> s)
Description copied from interface:ActivityGet or create the strideRateLimiterin a concurrent-safe way. Implementations should ensure that this method is synchronized or that each requester gets the same stride rate limiter for the activity.- Specified by:
getStrideRateLimiterin interfaceActivity- Parameters:
s- ARateLimiterSupplier- Returns:
- An extant or newly created stride
RateLimiter
-
getPhaseLimiter
public RateLimiter getPhaseLimiter()
Description copied from interface:ActivityGet the current phase rate limiter for this activity. The phase rate limiter is used to throttle the rate at which new phases are dispatched across all threads in an activity.- Specified by:
getPhaseLimiterin interfaceActivity- Returns:
- The stride
RateLimiter
-
getResultTimer
public com.codahale.metrics.Timer getResultTimer()
- Specified by:
getResultTimerin interfaceActivity
-
setPhaseLimiter
public void setPhaseLimiter(RateLimiter rateLimiter)
Description copied from interface:ActivitySet the phase rate limiter for this activity. This method should only be used in a non-concurrent context. Otherwise, the supplier versionActivity.getPhaseRateLimiter(Supplier)} should be used.- Specified by:
setPhaseLimiterin interfaceActivity- Parameters:
rateLimiter- The phaseRateLimiterfor this activity.
-
getPhaseRateLimiter
public RateLimiter getPhaseRateLimiter(java.util.function.Supplier<? extends RateLimiter> supplier)
Description copied from interface:ActivityGet or create the phaseRateLimiterin a concurrent-safe way. Implementations should ensure that this method is synchronized or that each requester gets the same phase rate limiter for the activity.- Specified by:
getPhaseRateLimiterin interfaceActivity- Parameters:
supplier- ARateLimiterSupplier- Returns:
- An extant or newly created phase
RateLimiter
-
getInstrumentation
public ActivityInstrumentation getInstrumentation()
Description copied from interface:ActivityGet or create the instrumentation needed for this activity. This provides a single place to find and manage, and document instrumentation that is uniform across all activities.- Specified by:
getInstrumentationin interfaceActivity- Returns:
- A new or existing instrumentation object for this activity.
-
onActivityDefUpdate
public void onActivityDefUpdate(ActivityDef activityDef)
- Specified by:
onActivityDefUpdatein interfaceActivityDefObserver
-
setDefaultsFromOpSequence
public void setDefaultsFromOpSequence(OpSequence seq)
Modify the provided ActivityDef with defaults for stride and cycles, if they haven't been provided, based on the length of the sequence as determined by the provided ratios. Also, modify the ActivityDef with reasonable defaults when requested.
-
-