Class EConfigure.DispatcherBuilder

  • Enclosing class:
    EConfigure

    public static final class EConfigure.DispatcherBuilder
    extends EConfigure.ThreadBuilder<EConfigure.Dispatcher,​EConfigure.DispatcherBuilder>
    Constructs an EConfigure.Dispatcher configuration 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 either EConfigure.DispatcherType.SWING or EConfigure.DispatcherType.JAVAFX. For a EConfigure.DispatcherType.EBUS Dispatcher 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:

    A Dispatcher can be created programmatically using a DispatchBuilder as follows:

    Note: This example only works if the dispatcher is created before MarketDataHandler instantiated. If not, the MarketDataHandler instance will be assigned to the default Dispatcher.

    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.Builder for explanation on how to build a ThreadAffinityConfigure instances.

    Author:
    Charles W. Rapp
    • Method Detail

      • dispatcherType

        public EConfigure.DispatcherBuilder dispatcherType​(EConfigure.DispatcherType type)
        Sets the dispatcher type.
        Parameters:
        type - dispatcher type.
        Returns:
        this dispatcher builder.
        Throws:
        com.typesafe.config.ConfigException - if type is null or 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:
        this dispatcher builder.
        Throws:
        com.typesafe.config.ConfigException - if capacity is ≤ zero.
      • 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:
        this dispatcher builder.
        Throws:
        com.typesafe.config.ConfigException - if capacity is ≤ zero.
      • quantum

        public EConfigure.DispatcherBuilder quantum​(Duration quantum)
        Sets the run quantum assigned to each eBus client.
        Parameters:
        quantum - run quantum.
        Returns:
        this dispatcher builder.
        Throws:
        com.typesafe.config.ConfigException - if quantum is null or < zero.
      • isDefault

        public EConfigure.DispatcherBuilder isDefault​(boolean flag)
        If flag is true, then marks the dispatcher as the default dispatcher.
        Parameters:
        flag - true marks the dispatcher as the default.
        Returns:
        this dispatcher builder.
      • classes

        public EConfigure.DispatcherBuilder classes​(Class<?>[] classes)
        Lists the classes assigned to the dispatcher. If the default dispatcher, this list is ignored and classes may be null or empty. If the dispatcher is not default, then classes must be defined as a non-null, non-empty array.

        This parameter is checked when the dispatcher is built since the validation depends on whether the dispatcher is default or not.

        Parameters:
        classes - eBus client classes assigned to the Dispatcher.
        Returns:
        this dispatcher builder.