Package org.agrona.concurrent
Class ControllableIdleStrategy
- java.lang.Object
-
- org.agrona.concurrent.ControllableIdleStrategy
-
- All Implemented Interfaces:
IdleStrategy
public final class ControllableIdleStrategy extends java.lang.Object implements IdleStrategy
IdleStrategy
which can be controlled by a counter so its mode of operation can be switched between doing nothing (NOOP), busy spinning by callingThreadHints.onSpinWait()
, yielding by callingThread.yield()
, or sleeping for the minimum period by callingLockSupport.parkNanos(long)
when work count is zero, so it idles.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ALIAS
Name to be returned fromalias()
.static int
BUSY_SPIN
ApplyBusySpinIdleStrategy
.static int
NOOP
ApplyNoOpIdleStrategy
.static int
NOT_CONTROLLED
Not controlled so will go with default ofPARK
.static int
PARK
ApplySleepingIdleStrategy
with minimum sleep interval.private static long
PARK_PERIOD_NANOSECONDS
private StatusIndicatorReader
statusIndicator
static int
YIELD
ApplyYieldingIdleStrategy
.
-
Constructor Summary
Constructors Constructor Description ControllableIdleStrategy(StatusIndicatorReader statusIndicator)
Configure idle strategy taking an indicator of which strategy should be applied.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
alias()
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 valuevoid
reset()
Reset the internal state in preparation for entering an idle state again.java.lang.String
toString()
-
-
-
Field Detail
-
ALIAS
public static final java.lang.String ALIAS
Name to be returned fromalias()
.- See Also:
- Constant Field Values
-
NOT_CONTROLLED
public static final int NOT_CONTROLLED
Not controlled so will go with default ofPARK
.- See Also:
- Constant Field Values
-
NOOP
public static final int NOOP
ApplyNoOpIdleStrategy
.- See Also:
- Constant Field Values
-
BUSY_SPIN
public static final int BUSY_SPIN
ApplyBusySpinIdleStrategy
.- See Also:
- Constant Field Values
-
YIELD
public static final int YIELD
ApplyYieldingIdleStrategy
.- See Also:
- Constant Field Values
-
PARK
public static final int PARK
ApplySleepingIdleStrategy
with minimum sleep interval.- See Also:
- Constant Field Values
-
PARK_PERIOD_NANOSECONDS
private static final long PARK_PERIOD_NANOSECONDS
- See Also:
- Constant Field Values
-
statusIndicator
private final StatusIndicatorReader statusIndicator
-
-
Constructor Detail
-
ControllableIdleStrategy
public ControllableIdleStrategy(StatusIndicatorReader statusIndicator)
Configure idle strategy taking an indicator of which strategy should be applied.- Parameters:
statusIndicator
- indicator of which strategy should be applied.
-
-
Method Detail
-
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:
IdleStrategy.idle(int)
-
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
public java.lang.String 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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-