Class 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 an AsyncChannel. 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 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.

    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
    • 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 key eBus.net.selectors contains 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 by eBus.net.selector. and followed by a selector thread, which must appear in the SELECTORS_KEY property.
        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
        The type property is used to specify the ESelector used 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 .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).

        See Also:
        Constant Field Values
      • SPIN_LIMIT_KEY

        public static final String SPIN_LIMIT_KEY
        If the selector type is 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.

        See Also:
        Constant Field Values
      • PARK_TIME_KEY

        public static final String PARK_TIME_KEY
        If the selector type is 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.

        See Also:
        Constant Field Values
      • DEFAULT_PRIORITY

        public static final int DEFAULT_PRIORITY
        The default selector thread priority is normal.
        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
    • Method Detail

      • isKnownSelector

        public static boolean isKnownSelector​(String name)
        Returns true if name is a known selector and false if not known.
        Parameters:
        name - the name to be checked.
        Returns:
        true if name is a known selector.
      • selector

        public static ENetConfigure.SelectorInfo selector​(String name)
        Returns the selector for the given name; returns null if name does 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.