Package org.agrona.concurrent
Class ControllableIdleStrategy
java.lang.Object
org.agrona.concurrent.ControllableIdleStrategy
- All Implemented Interfaces:
IdleStrategy
IdleStrategy
which can be controlled by a counter so its mode of operation can be switched between
doing nothing (NOOP), busy spinning by calling Thread.onSpinWait()
, yielding by calling
Thread.yield()
, or sleeping for the minimum period by calling LockSupport.parkNanos(long)
when
work count is zero, so it idles.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Name to be returned fromalias()
.static final int
ApplyBusySpinIdleStrategy
.static final int
ApplyNoOpIdleStrategy
.static final int
Not controlled so will go with default ofPARK
.static final int
ApplySleepingIdleStrategy
with minimum sleep interval.private static final long
private final StatusIndicatorReader
static final int
ApplyYieldingIdleStrategy
. -
Constructor Summary
ConstructorsConstructorDescriptionControllableIdleStrategy
(StatusIndicatorReader statusIndicator) Configure idle strategy taking an indicator of which strategy should be applied. -
Method Summary
Modifier and TypeMethodDescriptionalias()
Simple name by which the strategy can be identified.void
idle()
Perform current idle action (e.g.void
idle
(int workCount) Idle based on current status indication value.void
reset()
Reset the internal state in preparation for entering an idle state again.toString()
-
Field Details
-
ALIAS
Name to be returned fromalias()
.- See Also:
-
NOT_CONTROLLED
public static final int NOT_CONTROLLEDNot controlled so will go with default ofPARK
.- See Also:
-
NOOP
public static final int NOOPApplyNoOpIdleStrategy
.- See Also:
-
BUSY_SPIN
public static final int BUSY_SPINApplyBusySpinIdleStrategy
.- See Also:
-
YIELD
public static final int YIELDApplyYieldingIdleStrategy
.- See Also:
-
PARK
public static final int PARKApplySleepingIdleStrategy
with minimum sleep interval.- See Also:
-
PARK_PERIOD_NANOSECONDS
private static final long PARK_PERIOD_NANOSECONDS- See Also:
-
statusIndicator
-
-
Constructor Details
-
ControllableIdleStrategy
Configure idle strategy taking an indicator of which strategy should be applied.- Parameters:
statusIndicator
- indicator of which strategy should be applied.
-
-
Method Details
-
idle
public void idle(int workCount) Idle based on current status indication value.- Specified by:
idle
in interfaceIdleStrategy
- Parameters:
workCount
- performed in last duty cycle.- See Also:
-
idle
public void idle()Perform current idle action (e.g. nothing/yield/sleep). To be used in conjunction withIdleStrategy.reset()
to clear internal state when idle period is over (or before it begins). Callers are expected to follow this pattern:while (isRunning) { if (!hasWork()) { idleStrategy.reset(); while (!hasWork()) { if (!isRunning) { return; } idleStrategy.idle(); } } doWork(); }
- Specified by:
idle
in interfaceIdleStrategy
-
reset
public void reset()Reset the internal state in preparation for entering an idle state again.- Specified by:
reset
in interfaceIdleStrategy
-
alias
Simple name by which the strategy can be identified.- Specified by:
alias
in interfaceIdleStrategy
- Returns:
- simple name by which the strategy can be identified.
-
toString
-