Class ThreadAffinityConfigure.Builder
- java.lang.Object
-
- net.sf.eBus.config.ThreadAffinityConfigure.Builder
-
- Enclosing class:
- ThreadAffinityConfigure
public static final class ThreadAffinityConfigure.Builder extends Object
Constructs aThreadAffinityConfigureinstance based on the builder settings.Builderis the only means available to create a thread affinity configuration and the only way to acquire a builder instance is viaThreadAffinityConfigure.builder().The builder default setting is for an unbound
ThreadAffinityConfigure.AffinityType.ANY_CPU.The only required setting is
affinity type. That said, if affinity type is set certain values, then other properties are then required: , then the is required.-
CPU_ID: requirescpu IDbe set. -
CPU_LAST_MINUS: requirescpu offsetbe set. -
CPU_STRATEGIES: requiresstrateiesbe set.
Please see
ThreadAffinityConfigurefor detailed discussion on how to configure thread affinity.Example building a
ThreadAffinityConfigureinstanceCreates a thread affinity configuration in which the affinity is for a particular CPU identifier, the thread is bound to the affinity lock, and the whole core is reserved for the thread.
final ThreadAffinityConfigure.Builder builder = ThreadAffinityConfigure.builder(); final ThreadAffinityConfigure taConfig = builder.affinityType(ThreadAffinityConfigure.AffinityType.CPU_ID) .cpuId(7) .bind(true) .wholeCore(true) .build();- See Also:
ThreadAffinityConfigure
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ThreadAffinityConfigure.BuilderaffinityType(ThreadAffinityConfigure.AffinityType type)Sets affinity type to the given value overriding default settingThreadAffinityConfigure.AffinityType.ANY_CPU.ThreadAffinityConfigure.Builderbind(boolean flag)Sets flag for binding thread to affinity lock overriding default settingfalse.ThreadAffinityConfigurebuild()Returns newThreadAffinityConfigureinstance created fromthis Builder's settings.ThreadAffinityConfigure.BuildercpuId(int id)Sets CPU_ID identifier used byThreadAffinityConfigure.AffinityType.CPU_IDaffinity type.ThreadAffinityConfigure.BuilderlastMinusOffset(int n)Sets positive integer offset used byThreadAffinityConfigure.AffinityType.CPU_LAST_MINUSaffinity type.ThreadAffinityConfigure.Builderstrategies(List<net.openhft.affinity.AffinityStrategies> strategies)Sets CPU selection strategies used byThreadAffinityConfigure.AffinityType.CPU_STRATEGIESaffinity type.ThreadAffinityConfigure.Builderstrategies(net.openhft.affinity.AffinityStrategies... strategies)Sets CPU selection strategies used byThreadAffinityConfigure.AffinityType.CPU_STRATEGIESaffinity type.ThreadAffinityConfigure.BuilderwholeCore(boolean flag)Sets flag reserving the entire core and not allowing hyper-threading on that core.
-
-
-
Method Detail
-
affinityType
public ThreadAffinityConfigure.Builder affinityType(ThreadAffinityConfigure.AffinityType type)
Sets affinity type to the given value overriding default settingThreadAffinityConfigure.AffinityType.ANY_CPU.- Parameters:
type- desired thread affinity type.- Returns:
this Builderinstance to allow for method chaining.- Throws:
NullPointerException- iftypeisnull.
-
bind
public ThreadAffinityConfigure.Builder bind(boolean flag)
Sets flag for binding thread to affinity lock overriding default settingfalse.- Parameters:
flag- iftruethen bind thread to affinity lock.- Returns:
this Builderinstance to allow for method chaining.
-
wholeCore
public ThreadAffinityConfigure.Builder wholeCore(boolean flag)
Sets flag reserving the entire core and not allowing hyper-threading on that core. Default settings isfalse. This flag is used only whenbind(boolean)is set totrue; otherwise it is ignored.- Parameters:
flag- iftruethen binding reserves whole core.- Returns:
this Builderinstance to allow for method chaining.
-
cpuId
public ThreadAffinityConfigure.Builder cpuId(int id)
Sets CPU_ID identifier used byThreadAffinityConfigure.AffinityType.CPU_IDaffinity type. This value must be set when usingCPU_IDaffinity type and is ignored for all others.Note:
idis not checked to see if it is a valid CPU_ID identifier beyond making sure it is ≥ zero.- Parameters:
id- CPU_ID identifier.- Returns:
this Builderinstance to allow for method chaining.- Throws:
IllegalArgumentException- ifidis < zero.
-
lastMinusOffset
public ThreadAffinityConfigure.Builder lastMinusOffset(int n)
Sets positive integer offset used byThreadAffinityConfigure.AffinityType.CPU_LAST_MINUSaffinity type. This value must be set when usingCPU_LAST_MINUSaffinity type and is ignored for all others.Note:
nis not checked to see if it is a valid CPU offset beyond making sure it is > zero.- Parameters:
n- offset from end used to select CPU.- Returns:
this Builderinstance to allow for method chaining.- Throws:
IllegalArgumentException- ifnis ≤ zero.
-
strategies
public ThreadAffinityConfigure.Builder strategies(net.openhft.affinity.AffinityStrategies... strategies)
Sets CPU selection strategies used byThreadAffinityConfigure.AffinityType.CPU_STRATEGIESaffinity type. This list must be set when usingCPU_STRATEGIESaffinity type and is ignored for all others.Note: strategy ordering is important. The
ANYstrategy must appear as the last listed strategy. This allows any CPU to be selected in case none of the other strategies found an acceptable CPU.- Parameters:
strategies- CPU selection strategies list.- Returns:
this Builderinstance to allow for method chaining.- Throws:
NullPointerException- ifstrategiesisnull.IllegalArgumentException- ifstrategiesis an empty list or the final element is notAffinityStrategies.ANY.- See Also:
strategies(List)
-
strategies
public ThreadAffinityConfigure.Builder strategies(List<net.openhft.affinity.AffinityStrategies> strategies)
Sets CPU selection strategies used byThreadAffinityConfigure.AffinityType.CPU_STRATEGIESaffinity type. This list must be set when usingCPU_STRATEGIESaffinity type and is ignored for all others.Note: strategy ordering is important. The
ANYstrategy must appear as the last listed strategy. This allows any CPU to be selected in case none of the other strategies found an acceptable CPU.- Parameters:
strategies- CPU selection strategies list.- Returns:
this Builderinstance to allow for method chaining.- Throws:
NullPointerException- ifstrategiesisnull.IllegalArgumentException- ifstrategiesis an empty list or the final element is notAffinityStrategies.ANY.- See Also:
strategies(AffinityStrategies...)
-
build
public ThreadAffinityConfigure build()
Returns newThreadAffinityConfigureinstance created fromthis Builder's settings.- Returns:
- new
ThreadAffinityConfigureinstance. - Throws:
com.typesafe.config.ConfigException- if builder settings are invalid. This happens when required settings are not provided for the affinity type.
-
-