Package net.sf.eBus.config
Class EConfigure.DispatcherBuilder
- java.lang.Object
-
- net.sf.eBus.config.EConfigure.DispatcherBuilder
-
- Enclosing class:
- EConfigure
public static final class EConfigure.DispatcherBuilder extends Object
Constructs anEConfigure.Dispatcherconfiguration instance based on the parameters set via the builder's API. The minimally allowed configuration is the Dispatcher name and Dispatcher type if that type is eitherEConfigure.DispatcherType.SWINGorEConfigure.DispatcherType.JAVAFX. For aEConfigure.DispatcherType.EBUSDispatcher type, then the thread type must be provided. If this Dispatcher is not marked as the default, then the classes assigned to this Dispatcher must be provided.The remaining properties are set to the following defaults:
-
spin limit:
EConfigure.DEFAULT_SPIN_LIMIT. -
park time:
EConfigure.DEFAULT_PARK_TIME. -
priority:
Thread.NORM_PRIORITY. -
quantum:
EConfigure.DEFAULT_QUANTUM. -
thread count:
EConfigure.DEFAULT_NUMBER_THREADS. -
default Dispatcher:
false. -
thread affinity:
null.
Note: there is no example of how to build a
Dispatcherin application code because eBus dispatchers must be created on system start. Once the applicationmainmethod is reached, it is too late to create a dispatcher.- Author:
- Charles W. Rapp
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EConfigure.Dispatcherbuild()Returns the eBus Dispatcher configuration built from the previously set parameters.EConfigure.DispatcherBuilderclasses(Class<?>[] classes)Lists the classes assigned to the dispatcher.EConfigure.DispatcherBuilderconfiguration(EConfigure.Dispatcher config)Copies in the settings fromconfigto this builder.EConfigure.DispatcherBuilderdispatcherType(EConfigure.DispatcherType type)Sets the dispatcher type.EConfigure.DispatcherBuilderisDefault(boolean flag)Ifflagistrue, then marks the dispatcher as the default dispatcher.EConfigure.DispatcherBuildername(String name)Sets the dispatcher name.EConfigure.DispatcherBuildernumberThreads(int numThreads)Sets the number of threads used by the run queue.EConfigure.DispatcherBuilderparkTime(Duration time)Sets theThreadType.SPINPARKpark time limit.EConfigure.DispatcherBuilderpriority(int priority)Sets the run queue thread priority.EConfigure.DispatcherBuilderquantum(Duration quantum)Sets the run quantum assigned to each eBus client.EConfigure.DispatcherBuilderspinLimit(long limit)Sets theThreadType.SPINPARKorThreadType.SPINYIELDspin limit.EConfigure.DispatcherBuilderthreadAffinity(List<ThreadAffinityConfigure> affinities)Sets optional thread affinity to the given configuration list .EConfigure.DispatcherBuilderthreadAffinity(ThreadAffinityConfigure[] affinities)Sets optional thread affinity to the given configuration list .EConfigure.DispatcherBuilderthreadType(ThreadType type)Sets the run queue thread type.
-
-
-
Method Detail
-
configuration
public EConfigure.DispatcherBuilder configuration(EConfigure.Dispatcher config)
Copies in the settings fromconfigto this builder. This method is provided for making changes to an existing configuration sinceEConfigure.Dispatcheris immutable.if
configisnull, then nothing is done and the builder remains unchanged.- Parameters:
config- copy settings from this configuration.- Returns:
thisdispatcher builder.
-
name
public EConfigure.DispatcherBuilder name(String name)
Sets the dispatcher name.- Parameters:
name- dispatcher name.- Returns:
thisdispatcher builder.- Throws:
com.typesafe.config.ConfigException- ifnameis null or empty.
-
dispatcherType
public EConfigure.DispatcherBuilder dispatcherType(EConfigure.DispatcherType type)
Sets the dispatcher type.- Parameters:
type- dispatcher type.- Returns:
thisdispatcher builder.- Throws:
com.typesafe.config.ConfigException- iftypeisnullor an unknown dispatcher type.
-
threadType
public EConfigure.DispatcherBuilder threadType(ThreadType type)
Sets the run queue thread type. This setting is ignored if the Dispatcher type isEConfigure.DispatcherType.SWINGorEConfigure.DispatcherType.JAVAFX.- Parameters:
type- thread type.- Returns:
thisdispatcher builder.- Throws:
com.typesafe.config.ConfigException- iftypeisnullor an unknown thread type.
-
spinLimit
public EConfigure.DispatcherBuilder spinLimit(long limit)
Sets theThreadType.SPINPARKorThreadType.SPINYIELDspin limit. This setting is ignored for any other run queue thread type.- Parameters:
limit- spin limit.- Returns:
thisdispatcher builder.- Throws:
com.typesafe.config.ConfigException- iflimit< zero.
-
parkTime
public EConfigure.DispatcherBuilder 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:
thisdispatcher builder.- Throws:
com.typesafe.config.ConfigException- iftimeisnullor < zero.
-
priority
public EConfigure.DispatcherBuilder priority(int priority)
Sets the run queue thread priority. Must be ≥Thread.MIN_PRIORITYand ≤Thread.MAX_PRIORITY. This setting is ignored if the Dispatcher type isEConfigure.DispatcherType.SWINGorEConfigure.DispatcherType.JAVAFX.- Parameters:
priority- assigned thread priority for run queue threads.- Returns:
thisdispatcher builder.- Throws:
com.typesafe.config.ConfigException- ifpriority< zero or >Thread.MAX_PRIORITY.
-
quantum
public EConfigure.DispatcherBuilder quantum(Duration quantum)
Sets the run quantum assigned to each eBus client.- Parameters:
quantum- run quantum.- Returns:
thisdispatcher builder.- Throws:
com.typesafe.config.ConfigException- ifquantumisnullor < zero.
-
numberThreads
public EConfigure.DispatcherBuilder numberThreads(int numThreads)
Sets the number of threads used by the run queue. This setting is ignored if the Dispatcher type isEConfigure.DispatcherType.SWINGorEConfigure.DispatcherType.JAVAFX.- Parameters:
numThreads- number of run queue threads.- Returns:
thisdispatcher builder.- Throws:
com.typesafe.config.ConfigException- ifnumThreads< zero.
-
isDefault
public EConfigure.DispatcherBuilder isDefault(boolean flag)
Ifflagistrue, then marks the dispatcher as the default dispatcher.- Parameters:
flag-truemarks the dispatcher as the default.- Returns:
thisdispatcher builder.
-
classes
public EConfigure.DispatcherBuilder classes(Class<?>[] classes)
Lists the classes assigned to the dispatcher. If the default dispatcher, this list is ignored andclassesmay benullor empty. If the dispatcher is not default, thenclassesmust be defined as a non-null, non-empty array.This parameter is checked when the dispatcher is
builtsince the validation depends on whether the dispatcher is default or not.- Parameters:
classes- eBus client classes assigned to the Dispatcher.- Returns:
thisdispatcher builder.
-
threadAffinity
public EConfigure.DispatcherBuilder 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:
thisdispatcher builder.
-
threadAffinity
public EConfigure.DispatcherBuilder 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:
thisdispatcher builder.
-
build
public EConfigure.Dispatcher build()
Returns the eBus Dispatcher configuration built from the previously set parameters.- Returns:
- an eBus Dispatcher configuration.
- 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.
-
-