Class ThreadAffinityConfigure.Builder

  • Enclosing class:
    ThreadAffinityConfigure

    public static final class ThreadAffinityConfigure.Builder
    extends Object
    Constructs a ThreadAffinityConfigure instance based on the builder settings. Builder is the only means available to create a thread affinity configuration and the only way to acquire a builder instance is via ThreadAffinityConfigure.builder().

    The builder default setting is for an unbound ThreadAffinityConfigure.AffinityType.ANY_CPU.

    The only required setting is affinity type. That said, if affinity type is set certain values, then other properties are then required: , then the is required.

    Please see ThreadAffinityConfigure for detailed discussion on how to configure thread affinity.

    Example building a ThreadAffinityConfigure instance

    Creates a thread affinity configuration in which the affinity is for a particular CPU identifier, the thread is bound to the affinity lock, and the whole core is reserved for the thread.

    final ThreadAffinityConfigure.Builder builder = ThreadAffinityConfigure.builder();
    final ThreadAffinityConfigure taConfig = builder.affinityType(ThreadAffinityConfigure.AffinityType.CPU_ID)
                                                    .cpuId(7)
                                                    .bind(true)
                                                    .wholeCore(true)
                                                    .build();
    See Also:
    ThreadAffinityConfigure
    • Method Detail

      • bind

        public ThreadAffinityConfigure.Builder bind​(boolean flag)
        Sets flag for binding thread to affinity lock overriding default setting false.
        Parameters:
        flag - if true then bind thread to affinity lock.
        Returns:
        this Builder instance to allow for method chaining.
      • wholeCore

        public ThreadAffinityConfigure.Builder wholeCore​(boolean flag)
        Sets flag reserving the entire core and not allowing hyper-threading on that core. Default settings is false. This flag is used only when bind(boolean) is set to true; otherwise it is ignored.
        Parameters:
        flag - if true then binding reserves whole core.
        Returns:
        this Builder instance to allow for method chaining.
      • cpuId

        public ThreadAffinityConfigure.Builder cpuId​(int id)
        Sets CPU_ID identifier used by ThreadAffinityConfigure.AffinityType.CPU_ID affinity type. This value must be set when using CPU_ID affinity type and is ignored for all others.

        Note: id is not checked to see if it is a valid CPU_ID identifier beyond making sure it is ≥ zero.

        Parameters:
        id - CPU_ID identifier.
        Returns:
        this Builder instance to allow for method chaining.
        Throws:
        IllegalArgumentException - if id is < zero.
      • lastMinusOffset

        public ThreadAffinityConfigure.Builder lastMinusOffset​(int n)
        Sets positive integer offset used by ThreadAffinityConfigure.AffinityType.CPU_LAST_MINUS affinity type. This value must be set when using CPU_LAST_MINUS affinity type and is ignored for all others.

        Note: n is not checked to see if it is a valid CPU offset beyond making sure it is > zero.

        Parameters:
        n - offset from end used to select CPU.
        Returns:
        this Builder instance to allow for method chaining.
        Throws:
        IllegalArgumentException - if n is ≤ zero.
      • strategies

        public ThreadAffinityConfigure.Builder strategies​(net.openhft.affinity.AffinityStrategies... strategies)
        Sets CPU selection strategies used by ThreadAffinityConfigure.AffinityType.CPU_STRATEGIES affinity type. This list must be set when using CPU_STRATEGIES affinity type and is ignored for all others.

        Note: strategy ordering is important. The ANY strategy must appear as the last listed strategy. This allows any CPU to be selected in case none of the other strategies found an acceptable CPU.

        Parameters:
        strategies - CPU selection strategies list.
        Returns:
        this Builder instance to allow for method chaining.
        Throws:
        NullPointerException - if strategies is null.
        IllegalArgumentException - if strategies is an empty list or the final element is not AffinityStrategies.ANY.
        See Also:
        strategies(List)
      • strategies

        public ThreadAffinityConfigure.Builder strategies​(List<net.openhft.affinity.AffinityStrategies> strategies)
        Sets CPU selection strategies used by ThreadAffinityConfigure.AffinityType.CPU_STRATEGIES affinity type. This list must be set when using CPU_STRATEGIES affinity type and is ignored for all others.

        Note: strategy ordering is important. The ANY strategy must appear as the last listed strategy. This allows any CPU to be selected in case none of the other strategies found an acceptable CPU.

        Parameters:
        strategies - CPU selection strategies list.
        Returns:
        this Builder instance to allow for method chaining.
        Throws:
        NullPointerException - if strategies is null.
        IllegalArgumentException - if strategies is an empty list or the final element is not AffinityStrategies.ANY.
        See Also:
        strategies(AffinityStrategies...)
      • build

        public ThreadAffinityConfigure build()
        Returns new ThreadAffinityConfigure instance created from this Builder's settings.
        Returns:
        new ThreadAffinityConfigure instance.
        Throws:
        com.typesafe.config.ConfigException - if builder settings are invalid. This happens when required settings are not provided for the affinity type.