Package net.sf.eBus.config
Class EConfigure.DispatcherBuilder
- java.lang.Object
-
- net.sf.eBus.config.EConfigure.ThreadBuilder<EConfigure.Dispatcher,EConfigure.DispatcherBuilder>
-
- net.sf.eBus.config.EConfigure.DispatcherBuilder
-
- Enclosing class:
- EConfigure
public static final class EConfigure.DispatcherBuilder extends EConfigure.ThreadBuilder<EConfigure.Dispatcher,EConfigure.DispatcherBuilder>
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:
-
client task queue capacity:
EConfigure.DEFAULT_TASK_QUEUE_CAPACITY. -
run queue capacity:
EConfigure.DEFAULT_RUN_QUEUE_CAPACITY. -
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.
A
Dispatchercan be created programmatically using aDispatchBuilderas follows:Note: This example only works if the dispatcher is created before
MarketDataHandlerinstantiated. If not, theMarketDataHandlerinstance will be assigned to the defaultDispatcher.import net.sf.eBus.client.EFeed; import net.sf.eBus.config.EConfigure.Dispatcher; import net.sf.eBus.config.EConfigure.DispatcherBuilder; import net.sf.eBus.config.EConfigure.DispatcherType; import net.sf.eBus.config.EConfigure.ThreadAffinityConfigure; import net.sf.eBus.config.ThreadType; public static void main(final String[] args) { final Class[] eclients = new Class[] { MarketDataHandler.class }; final ThreadAffinityConfigure threadAffinity = (ThreadAffinityConfigure.builder()).affinityType(ThreadsAffinityConfigure.AffinityType.CPU_ID) .cpuId(7) .bind(true) .wholeCore(true) .build(); final ThreadAffinityConfigure[] threadAffinities = new ThreadAffinityConfigure[] { threadAffinity }; final DispatcherBuilder builder = EConfigure.dispatcherBuilder(); final Dispatcher dispatcher = builder.name("MyDispatcher") .dispatcherType(DispatcherType.EBUS) .taskQueueCapacity(256) .threadType(ThreadType.SPINNING) .runQueueCapacity(32) .numberThreads(1) .isDefault(false) .classes(eclients) .threadAffinity(threadAffinities) .build(); EFeed.createDispatcher(dispatcher); }See
ThreadAffinityConfigure.Builderfor explanation on how to build aThreadAffinityConfigureinstances.- Author:
- Charles W. Rapp
-
-
Field Summary
-
Fields inherited from class net.sf.eBus.config.EConfigure.ThreadBuilder
mAffinity, mName, mNumThreads, mParkTime, mPriority, mSpinLimit, mThreadType
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected EConfigure.DispatcherbuildImpl()Returns new subclass instance based on builder settings.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.DispatcherBuildernumberThreads(int numThreads)Sets the number of threads used by the run queue.EConfigure.DispatcherBuilderquantum(Duration quantum)Sets the run quantum assigned to each eBus client.EConfigure.DispatcherBuilderrunQueueCapacity(int capacity)Sets run queue capacity.EConfigure.DispatcherBuilderrunQueueType(ThreadType type)Sets run queue thread type.protected EConfigure.DispatcherBuilderself()Returns subclassthisreference.EConfigure.DispatcherBuildertaskQueueCapacity(int capacity)Sets eBus client task queue capacity.protected Validatorvalidate(Validator problems)Validates theDispatcherbuilder parameters.-
Methods inherited from class net.sf.eBus.config.EConfigure.ThreadBuilder
build, name, parkTime, priority, spinLimit, threadAffinity, threadAffinity
-
-
-
-
Method Detail
-
self
protected EConfigure.DispatcherBuilder self()
Description copied from class:EConfigure.ThreadBuilderReturns subclassthisreference.- Specified by:
selfin classEConfigure.ThreadBuilder<EConfigure.Dispatcher,EConfigure.DispatcherBuilder>- Returns:
this.
-
buildImpl
protected EConfigure.Dispatcher buildImpl()
Description copied from class:EConfigure.ThreadBuilderReturns new subclass instance based on builder settings.- Specified by:
buildImplin classEConfigure.ThreadBuilder<EConfigure.Dispatcher,EConfigure.DispatcherBuilder>- Returns:
- new subclass instance.
-
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.- Overrides:
configurationin classEConfigure.ThreadBuilder<EConfigure.Dispatcher,EConfigure.DispatcherBuilder>- Parameters:
config- copy settings from this configuration.- Returns:
thisdispatcher builder.
-
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.
-
taskQueueCapacity
public EConfigure.DispatcherBuilder taskQueueCapacity(int capacity)
Sets eBus client task queue capacity. This capacity is applied to each eBus client. The capacity should be a 2 power value. If not, run queue capacity is set to the next 2 power value > given capacity.- Parameters:
capacity- task queue maximum capacity.- Returns:
thisdispatcher builder.- Throws:
com.typesafe.config.ConfigException- ifcapacityis ≤ zero.
-
runQueueType
public EConfigure.DispatcherBuilder runQueueType(ThreadType type)
Sets run queue thread type.- Parameters:
type- thread type.- Returns:
thisthread builder.
-
runQueueCapacity
public EConfigure.DispatcherBuilder runQueueCapacity(int capacity)
Sets run queue capacity. This setting is used only for non-blocking Dispatcher thread type. The capacity should be a 2 power value. If not, run queue capacity is set to the next 2 power value > given capacity.- Parameters:
capacity- run queue maximum capacity.- Returns:
thisdispatcher builder.- Throws:
com.typesafe.config.ConfigException- ifcapacityis ≤ zero.
-
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.
-
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.- Overrides:
validatein classEConfigure.ThreadBuilder<EConfigure.Dispatcher,EConfigure.DispatcherBuilder>- Parameters:
problems- record configuration problems in this list.- Returns:
problemssovalidatecalls may be chained together.
-
-