public final class ENetConfigure extends Object
-Dnet.sf.eBus.config.file=<property file path>.
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" : 500
}
]
(See below for an explanation for each property.)
Note that selector threads are not started at this
time but only when its name referenced by an
AsyncChannel. So if no channels use the
selector during an application run, then the thread is never
started.
Selector threads can also be defined using a Java property
file specified by the command line parameter
-Dnet.sf.eBus.config.file=<property file path>.
The preferred method is to use the typesafe JSON configuration
file. It is an error use both a properties file and a JSON
file.
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 of ThreadType.
This property is required.
eBus.net.selector.name.isDefault:
Set to "true" if this is the default selector. The default
selector is used by all AsyncChannels not
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_PRIORITY
and ≤ Thread.MAX_PRIORITY.
The default value for this setting is
Thread.NORM_PRIORITY.
eBus.net.selector.name.spinLimit:
If type is ThreadType.SPINPARK, then this
property specifies the number of times the thread will spin
on Selector.selectNow() before
parking.
The default value is DEFAULT_SPIN_LIMIT.
eBus.net.selector.name.parkTime:
If type is ThreadType.SPINPARK, then this
property specifies the number of nanoseconds the thread
will park before returning to spinning.
The default value is DEFAULT_PARK_TIME.
| Modifier and Type | Class and Description |
|---|---|
static class |
ENetConfigure.SelectorInfo
This immutable class contains the selector thread
configuration for the named selector.
|
static class |
ENetConfigure.SelectorInfoBuilder
Constructs an
ENetConfigure.SelectorInfo instance based on the
parameters set via the builder's API. |
| Modifier and Type | Field and Description |
|---|---|
static int |
ANY_PORT
Use the value 0 to specify socket is opened and
bound to any port.
|
static int |
DEFAULT_BUFFER_SIZE
The default input and output socket buffer size is
2048 bytes.
|
static String |
DEFAULT_KEY
The boolean "isDefault" property is used to
specify when this selector thread should be used as the
default selector thread.
|
static int |
DEFAULT_PARK_TIME
The default thread park time is 1000 nanoseconds.
|
static int |
DEFAULT_PRIORITY
The default selector thread priority is
normal. |
static ThreadType |
DEFAULT_SELECTOR_TYPE
The default selector type is
ThreadType.BLOCKING. |
static int |
DEFAULT_SPIN_LIMIT
The default select spin limit is 2500000 calls to
Selector.selectNow() before
parking the thread. |
static int |
MAX_PORT
The maximum allowed port number is 65,535.
|
static int |
MIN_PORT
The minimum allowed port number is zero.
|
static String |
NAME_KEY
The "name" property is used to specify the unique
selector name.
|
static String |
PARK_TIME_KEY
If the selector type is
spin+park, then the
integer "parkTime" property may be specified. |
static String |
PRIORITY_KEY
The integer "priority" property is used to
set the select thread priority.
|
static String |
SELECTOR_PREFIX
Selector keys are prefixed by
eBus.net.selector.
and followed by a selector thread, which must appear in
the SELECTORS_KEY property. |
static String |
SELECTORS_KEY
The key
eBus.net.selectors contains a
comma-separated list of selector thread names. |
static String |
SPIN_LIMIT_KEY
If the selector type is
spin+park, then the
integer "spinLimit" property may be specified. |
static String |
TYPE_KEY
The
type property is used to specify
the ESelector used with the selector thread. |
| Modifier and Type | Method and Description |
|---|---|
static String |
asText()
Returns the loaded network configuration as text.
|
static ENetConfigure.SelectorInfo |
defaultSelector() |
static boolean |
isKnownSelector(String name)
Returns
true if name is a known selector
and false if not known. |
static void |
load(com.typesafe.config.Config config)
Returns a selector thread configuration extracted from the
given JSON properties.
|
static void |
load(Properties props)
Returns selector thread configuration extracted from the
given properties.
|
static void |
load(Properties props)
Returns selector thread configuration extracted from the
given properties.
|
static ENetConfigure.SelectorInfo |
selector(String name)
Returns the selector for the given name;
returns
null if name does not reference
a known selector. |
static ENetConfigure.SelectorInfoBuilder |
selectorBuilder()
Returns a builder used to create a
ENetConfigure.SelectorInfo
instance. |
static Map<String,ENetConfigure.SelectorInfo> |
selectors()
Returns the selector thread configurations.
|
public static final int MIN_PORT
public static final int MAX_PORT
public static final int ANY_PORT
public static final String SELECTORS_KEY
eBus.net.selectors contains a
comma-separated list of selector thread names.public static final String SELECTOR_PREFIX
eBus.net.selector.
and followed by a selector thread, which must appear in
the SELECTORS_KEY property.public static final String NAME_KEY
This property is required.
public static final String TYPE_KEY
type property is used to specify
the ESelector used with the selector thread.
This property is required.
public static final String DEFAULT_KEY
.isDefault keys are
ignored.
If no user-defined selector is marked as default, then
a blocking,
normal priority selector
named AsyncChannel.sDefaultSelector is used as the
default selector.
The default value is false
(not the default selector).
public static final String PRIORITY_KEY
The default value is Thread.NORM_PRIORITY.
public static final String SPIN_LIMIT_KEY
spin+park, then the
integer "spinLimit" property may be specified. This
setting defines the number of times the selector thread
may call
Selector.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.
public static final String PARK_TIME_KEY
spin+park, then the
integer "parkTime" property may be specified. This
setting specifies the nanosecond park time taken
between
Selector.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.
public static final int DEFAULT_PRIORITY
normal.public static final int DEFAULT_SPIN_LIMIT
Selector.selectNow() before
parking the thread.public static final int DEFAULT_PARK_TIME
public static final int DEFAULT_BUFFER_SIZE
public static final ThreadType DEFAULT_SELECTOR_TYPE
ThreadType.BLOCKING.public static ENetConfigure.SelectorInfo defaultSelector()
public static boolean isKnownSelector(String name)
true if name is a known selector
and false if not known.name - the name to be checked.true if name is a known selector.public static ENetConfigure.SelectorInfo selector(String name)
null if name does not reference
a known selector.name - selector name.public static Map<String,ENetConfigure.SelectorInfo> selectors()
public static String asText()
public static void load(Properties props)
props - load the selector configuration from here.com.typesafe.config.ConfigException - if props is missing a required property key or a
property contains an invalid value.public static void load(Properties props)
props - load the selector configuration from here.com.typesafe.config.ConfigException - if props is missing a required property key or a
property contains an invalid value.public static void load(com.typesafe.config.Config config)
config - JSON configuration.public static ENetConfigure.SelectorInfoBuilder selectorBuilder()
ENetConfigure.SelectorInfo
instance.ENetConfigure.SelectorInfo builder.Copyright © 2020. All rights reserved.