Class Broker.Builder<V>

  • Enclosing class:
    Broker<V>

    public static class Broker.Builder<V>
    extends Object
    A Builder interface for constructing a Broker.
    • Constructor Detail

      • Builder

        public Builder()
    • Method Detail

      • addConsumer

        public Broker.Builder<V> addConsumer​(Consumer<? super V> consumer)
        Adds a consumer.
        Parameters:
        consumer - the consumer
        Returns:
        the builder
      • addConsumer

        public Broker.Builder<V> addConsumer​(Consumer<? super V> consumer,
                                             int number)
        Adds a consumer and will run it on a number of threads.
        Parameters:
        consumer - the consumer
        number - the number of threads to run the consumer on.
        Returns:
        the builder
      • addConsumers

        public Broker.Builder<V> addConsumers​(Collection<? extends Consumer<? super V>> consumers)
        Add a collection of consumers.
        Parameters:
        consumers - the consumers
        Returns:
        the builder
      • addProducer

        public Broker.Builder<V> addProducer​(Broker.Producer<V> producer,
                                             int number)
        Adds producer and sets it to run on a number of threads. Note that the producer must be thread safe.
        Parameters:
        producer - the producer
        number - the number of threads to run the producer on.
        Returns:
        the builder
      • addProducer

        public Broker.Builder<V> addProducer​(Broker.Producer<V> producer)
        Adds a producer
        Parameters:
        producer - the producer
        Returns:
        the builder
      • bufferSize

        public Broker.Builder<V> bufferSize​(int size)
        The size of the buffer.
        Parameters:
        size - the size
        Returns:
        the builder
      • build

        public Broker<V> build()
        Builds A Broker. If no queue size was given than it will default to 2 * (number of producers + number of consumers)
        Returns:
        the producer consumer