Class ENetConfigure
- java.lang.Object
-
- net.sf.eBus.config.ENetConfigure
-
public final class ENetConfigure extends Object
This immutable class contains selector thread configuration extracted from properties. Selector threads configuration is taken from the typesafe JSON file specified by the command line parameter-Dnet.sf.eBus.config.jsonFile=<conf file path>. Selector threads may not be created at runtime but only on JVM start up. That said, selector threads are not started on JVM start time but only when its name referenced by anAsyncChannel. So if no channels use the selector during an application run, then the thread is never started.Selector thread configuration uses the following property keys:
-
eBus.net.selectors: a comma-separated list of selector thread names. The names should be unique (no duplicates). All duplicates are logged and ignored. The selector thread name is used to retrieve the remaining keys. -
eBus.net.selector.name.type: The selector thread type must be one ofThreadType.This property is required.
-
eBus.net.selector.name.isDefault: Set to "true" if this is the default selector. The default selector is used by allAsyncChannelsnot explicitly assigned to a selector. If multiple selectors are designated as the default, then it cannot be determined which selector will be used as the default.The default value for this setting is
false. -
eBus.net.selector.name.priority: The selector thread runs at this thread priority. The specified value must be ≥Thread.MIN_PRIORITYand ≤Thread.MAX_PRIORITY.The default value for this setting is
Thread.NORM_PRIORITY. -
eBus.net.selector.name.spinLimit: IftypeisThreadType.SPINPARK, then this property specifies the number of times the thread will spin onSelector.selectNow()before parking.The default value is
DEFAULT_SPIN_LIMIT. -
eBus.net.selector.name.parkTime: IftypeisThreadType.SPINPARK, then this property specifies the number of nanoseconds the thread will park before returning to spinning.The default value is
DEFAULT_PARK_TIME.
Example select thread configuration:
selectors : [ { name : faster // required, must be unique. type : spinning // required. isDefault : false // optional, defaults to false. priority : 10 // optional, defaults to Thread.NORM_PRIORITY }, { name : slower type" : "spin+park" isDefault : true priority : 7 spinLimit : 1000000 parkTime : 500ns } ]- Author:
- Charles W. Rapp
- See Also:
ENetConfigure.SelectorInfo,ENetConfigure.SelectorInfoBuilder
-
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classENetConfigure.SelectorInfoThis immutable class contains the selector thread configuration for the named selector.static classENetConfigure.SelectorInfoBuilderConstructs anENetConfigure.SelectorInfoinstance based on the parameters set via the builder's API.
-
Field Summary
Fields Modifier and Type Field Description static StringAFFINITY_KEYOptional thread affinity configuration.static intANY_PORTUse the value 0 to specify socket is opened and bound to any port.static intDEFAULT_BUFFER_SIZEThe default input and output socket buffer size is 2048 bytes.static StringDEFAULT_KEYThe boolean "isDefault" property is used to specify when this selector thread should be used as the default selector thread.static DurationDEFAULT_PARK_TIMEThe default thread park time is 1 microsecond.static intDEFAULT_PRIORITYThe default selector thread priority isnormal.static ThreadTypeDEFAULT_SELECTOR_TYPEThe default selector type isThreadType.BLOCKING.static intDEFAULT_SPIN_LIMITThe default select spin limit is 2500000 calls toSelector.selectNow()before parking the thread.static intMAX_PORTThe maximum allowed port number is 65,535.static intMIN_PORTThe minimum allowed port number is zero.static StringNAME_KEYThe "name" property is used to specify the unique selector name.static StringPARK_TIME_KEYIf the selector type isspin+park, then the integer "parkTime" property may be specified.static StringPRIORITY_KEYThe integer "priority" property is used to set the select thread priority.static StringSELECTOR_PREFIXSelector keys are prefixed byeBus.net.selector.and followed by a selector thread, which must appear in theSELECTORS_KEYproperty.static StringSELECTORS_KEYThe keyeBus.net.selectorscontains a comma-separated list of selector thread names.static StringSPIN_LIMIT_KEYIf the selector type isspin+park, then the integer "spinLimit" property may be specified.static StringTYPE_KEYThetypeproperty is used to specify theESelectorused with the selector thread.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringasText()Returns the loaded network configuration as text.static ENetConfigure.SelectorInfodefaultSelector()static booleanisKnownSelector(String name)Returnstrueifnameis a known selector andfalseif not known.static voidload(com.typesafe.config.Config config)Returns a selector thread configuration extracted from the given JSON properties.static ENetConfigure.SelectorInfoselector(String name)Returns the selector for the given name; returnsnullifnamedoes not reference a known selector.static ENetConfigure.SelectorInfoBuilderselectorBuilder()Returns a builder used to create aENetConfigure.SelectorInfoinstance.static Map<String,ENetConfigure.SelectorInfo>selectors()Returns the selector thread configurations.
-
-
-
Field Detail
-
MIN_PORT
public static final int MIN_PORT
The minimum allowed port number is zero.- See Also:
- Constant Field Values
-
MAX_PORT
public static final int MAX_PORT
The maximum allowed port number is 65,535.- See Also:
- Constant Field Values
-
ANY_PORT
public static final int ANY_PORT
Use the value 0 to specify socket is opened and bound to any port.- See Also:
- Constant Field Values
-
SELECTORS_KEY
public static final String SELECTORS_KEY
The keyeBus.net.selectorscontains a comma-separated list of selector thread names.- See Also:
- Constant Field Values
-
SELECTOR_PREFIX
public static final String SELECTOR_PREFIX
Selector keys are prefixed byeBus.net.selector.and followed by a selector thread, which must appear in theSELECTORS_KEYproperty.- See Also:
- Constant Field Values
-
NAME_KEY
public static final String NAME_KEY
The "name" property is used to specify the unique selector name. Uniqueness is within the JVM.This property is required.
- See Also:
- Constant Field Values
-
TYPE_KEY
public static final String TYPE_KEY
Thetypeproperty is used to specify theESelectorused with the selector thread.This property is required.
- See Also:
- Constant Field Values
-
DEFAULT_KEY
public static final String DEFAULT_KEY
The boolean "isDefault" property is used to specify when this selector thread should be used as the default selector thread. At most one selector should be designated as the default selector. If more than one is so designated, the subsequent.isDefaultkeys are ignored.If no user-defined selector is marked as default, then a
blocking,normal priorityselector namedAsyncChannel.sDefaultSelectoris used as the default selector.The default value is
false(not the default selector).- See Also:
- Constant Field Values
-
PRIORITY_KEY
public static final String PRIORITY_KEY
The integer "priority" property is used to set the select thread priority.The default value is
Thread.NORM_PRIORITY.- See Also:
- Constant Field Values
-
SPIN_LIMIT_KEY
public static final String SPIN_LIMIT_KEY
If the selector type isspin+park, then the integer "spinLimit" property may be specified. This setting defines the number of times the selector thread may callSelector.selectNow()before parking.This value must be > zero.
Default values is
DEFAULT_SPIN_LIMIT.This property is ignored is the selector type is not spin+park.
- See Also:
- Constant Field Values
-
PARK_TIME_KEY
public static final String PARK_TIME_KEY
If the selector type isspin+park, then the integer "parkTime" property may be specified. This setting specifies the nanosecond park time taken betweenSelector.selectNow()spin cycles.This value must be > zero.
Default values is
DEFAULT_PARK_TIME.This property is ignored is the selector type is not spin+park.
- See Also:
- Constant Field Values
-
AFFINITY_KEY
public static final String AFFINITY_KEY
Optional thread affinity configuration. May benull. Thread affinity is best used when thread type isThreadType.SPINNING.- See Also:
- Constant Field Values
-
DEFAULT_PRIORITY
public static final int DEFAULT_PRIORITY
The default selector thread priority isnormal.- See Also:
- Constant Field Values
-
DEFAULT_SPIN_LIMIT
public static final int DEFAULT_SPIN_LIMIT
The default select spin limit is 2500000 calls toSelector.selectNow()before parking the thread.- See Also:
- Constant Field Values
-
DEFAULT_PARK_TIME
public static final Duration DEFAULT_PARK_TIME
The default thread park time is 1 microsecond.
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
The default input and output socket buffer size is 2048 bytes.- See Also:
- Constant Field Values
-
DEFAULT_SELECTOR_TYPE
public static final ThreadType DEFAULT_SELECTOR_TYPE
The default selector type isThreadType.BLOCKING.
-
-
Method Detail
-
defaultSelector
public static ENetConfigure.SelectorInfo defaultSelector()
-
isKnownSelector
public static boolean isKnownSelector(String name)
Returnstrueifnameis a known selector andfalseif not known.- Parameters:
name- the name to be checked.- Returns:
trueifnameis a known selector.
-
selector
public static ENetConfigure.SelectorInfo selector(String name)
Returns the selector for the given name; returnsnullifnamedoes not reference a known selector.- Parameters:
name- selector name.- Returns:
- configured selector information.
-
selectors
public static Map<String,ENetConfigure.SelectorInfo> selectors()
Returns the selector thread configurations. The returned list is unmodifiable.- Returns:
- selector thread configurations.
-
asText
public static String asText()
Returns the loaded network configuration as text.- Returns:
- textual representation of network configuration.
-
load
public static void load(com.typesafe.config.Config config)
Returns a selector thread configuration extracted from the given JSON properties.- Parameters:
config- JSON configuration.
-
selectorBuilder
public static ENetConfigure.SelectorInfoBuilder selectorBuilder()
Returns a builder used to create aENetConfigure.SelectorInfoinstance.- Returns:
ENetConfigure.SelectorInfobuilder.
-
-