Package net.sf.eBus.config
Class EConfigure.ThreadBuilder<T extends EConfigure.ThreadConfig,B extends EConfigure.ThreadBuilder>
- java.lang.Object
-
- net.sf.eBus.config.EConfigure.ThreadBuilder<T,B>
-
- Type Parameters:
T- target class built.B- thread builder subclass.
- Direct Known Subclasses:
EConfigure.DispatcherBuilder,EConfigure.ScheduledExecutorBuilder
- Enclosing class:
- EConfigure
protected abstract static class EConfigure.ThreadBuilder<T extends EConfigure.ThreadConfig,B extends EConfigure.ThreadBuilder> extends Object
Contains configuration settings common toEConfigure.DispatcherBuilderandEConfigure.ScheduledExecutorBuilder.
-
-
Field Summary
Fields Modifier and Type Field Description protected ThreadAffinityConfigure[]mAffinityprotected StringmNameprotected intmNumThreadsprotected DurationmParkTimeprotected intmPriorityprotected longmSpinLimitprotected ThreadTypemThreadType
-
Constructor Summary
Constructors Modifier Constructor Description protectedThreadBuilder(int numThreads)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Tbuild()Returns the target configuration instance built from previously set parameters.protected abstract TbuildImpl()Returns new subclass instance based on builder settings.Bconfiguration(T config)Bname(String name)Sets scheduled executor name.BparkTime(Duration time)Sets theThreadType.SPINPARKpark time limit.Bpriority(int priority)Sets the thread priority.protected abstract Bself()Returns subclassthisreference.BspinLimit(long limit)Sets theThreadType.SPINPARKorThreadType.SPINYIELDspin limit.BthreadAffinity(List<ThreadAffinityConfigure> affinities)Sets optional thread affinity to the given configuration list .BthreadAffinity(ThreadAffinityConfigure[] affinities)Sets optional thread affinity to the given configuration list .protected Validatorvalidate(Validator problems)Validates theDispatcherbuilder parameters.
-
-
-
Field Detail
-
mNumThreads
protected int mNumThreads
-
mName
protected String mName
-
mThreadType
protected ThreadType mThreadType
-
mSpinLimit
protected long mSpinLimit
-
mParkTime
protected Duration mParkTime
-
mPriority
protected int mPriority
-
mAffinity
protected ThreadAffinityConfigure[] mAffinity
-
-
Method Detail
-
self
protected abstract B self()
Returns subclassthisreference.- Returns:
this.
-
buildImpl
protected abstract T buildImpl()
Returns new subclass instance based on builder settings.- Returns:
- new subclass instance.
-
name
public final B name(String name)
Sets scheduled executor name. Used to create thread name.- Parameters:
name- scheduled executor name.- Returns:
thisthread builder.- Throws:
com.typesafe.config.ConfigException- ifnameis null or empty.
-
spinLimit
public final B spinLimit(long limit)
Sets theThreadType.SPINPARKorThreadType.SPINYIELDspin limit. This setting is ignored for any other run queue thread type.- Parameters:
limit- spin limit.- Returns:
thisthread builder.- Throws:
com.typesafe.config.ConfigException- iflimit< zero.
-
parkTime
public final B parkTime(Duration time)
Sets theThreadType.SPINPARKpark time limit. This setting is ignored for any other run queue thread type.- Parameters:
time- park time limit.- Returns:
thisthread builder.- Throws:
com.typesafe.config.ConfigException- iftimeisnullor < zero.
-
priority
public final B priority(int priority)
Sets the thread priority. Must be ≥Thread.MIN_PRIORITYand ≤Thread.MAX_PRIORITY.- Parameters:
priority- assigned thread priority for scheduled executor thread.- Returns:
thisthread builder.- Throws:
com.typesafe.config.ConfigException- ifpriority< zero or >Thread.MAX_PRIORITY.
-
threadAffinity
public final B threadAffinity(List<ThreadAffinityConfigure> affinities)
Sets optional thread affinity to the given configuration list . Thread affinity should be considered when using spinning thread type.- Parameters:
affinities- thread affinity configuration. May benullor empty.- Returns:
thisthread builder.
-
threadAffinity
public final B threadAffinity(ThreadAffinityConfigure[] affinities)
Sets optional thread affinity to the given configuration list . Thread affinity should be considered when using spinning thread type.- Parameters:
affinities- thread affinity configuration. May benullor empty.- Returns:
thisthread builder.
-
build
public T build()
Returns the target configuration instance built from previously set parameters.- Returns:
- an eBus thread configuration subclass instance.
- Throws:
com.typesafe.config.ConfigException- if either the Dispatcher name, Dispatcher type, or run queue thread type are not set, or if the Dispatcher is not marked as default and no classes were provided.
-
validate
protected Validator validate(Validator problems)
Validates theDispatcherbuilder parameters. This validation is "fail slow" meaning that a single validation call will determine all configuration errors.- Parameters:
problems- record configuration problems in this list.- Returns:
problemssovalidatecalls may be chained together.
-
-