Package bbflow

Class ff_farm<T,U>

java.lang.Object
bbflow.block<T,U>
bbflow.ff_node<T,U>
bbflow.ff_farm<T,U>
Type Parameters:
T - Custom type input
U - Custom type output

public class ff_farm<T,U> extends ff_node<T,U>
Fundamental block modeling the Farm paradigm Composed by one emitter (single input by default), n_workers workers and one collector Worker must be implemented; the function runJob or runJobMulti contains the computation part. See details below or the thesis Collector has by default one output channel If collector is not needed and the job ends in the workers, just avoid sending data to the channel between workers and collector, and it will be ignored
  • Field Details

  • Constructor Details

    • ff_farm

      public ff_farm(LinkedList<defaultJob<T,U>> worker_job, int emitter_strategy, int collector_strategy, int bufferSize)
      constructor given a list of defaultJob, Emitter strategy, Collector strategy and buffer size
      Parameters:
      worker_job - the list of jobs (one for each worker) to be executed of type bbflow.defaultJob. They can be different if needed
      emitter_strategy - Emitter communication strategy chosen between ROUNDROBIN, SCATTER and BROADCAST
      collector_strategy - Collector communication strategy chosen between FIRSTCOME, ROUNDROBIN and GATHER
    • ff_farm

      public ff_farm(LinkedList<defaultJob<T,U>> worker_job, int emitter_strategy)
      constructor given a list of defaultJob and the Emitter strategy
      Parameters:
      worker_job - list of defaultJob
      emitter_strategy - Emitter strategy between ROUNDROBIN, SCATTER, BROADCAST
    • ff_farm

      public ff_farm(LinkedList<defaultJob<T,U>> worker_job)
      constructor given a list of defaultJob
      Parameters:
      worker_job - list of defaultJob
    • ff_farm

      public ff_farm(int n_workers, defaultJob<T,U> workerJob, int emitter_strategy, int collector_strategy, int bufferSize)
      constructor for workerJob of anonymous type
      Parameters:
      n_workers - number of workers
      workerJob - worker_job the worker job declared inline (as anonymous class)
      emitter_strategy - emitter strategy between ROUNDROBIN, SCATTER, BROADCAST
      collector_strategy - collector strategy between ROUNDROBIN, FIRSTCOME, GATHER
      bufferSize - buffer size of channels
    • ff_farm

      public ff_farm(int n_workers, defaultJob<T,U> worker_job, int emitter_strategy)
      Create a new farm with Emitter in 'emitter_strategy' and default Collector in ROUNDROBIN
      Parameters:
      n_workers - number of workers
      worker_job - the worker job declared inline (as anonymous class)
      emitter_strategy - emitter strategy between ROUNDROBIN, SCATTER, BROADCAST
    • ff_farm

      public ff_farm(int n_workers, defaultJob<T,U> worker_job)
      Create a new farm with default Emitter in ROUNDROBING and Collector in ROUNDROBIN
      Parameters:
      n_workers - number of workers
      worker_job - the worker job declared inline (as anonymous class)
  • Method Details

    • preload

      public static void preload()
    • create_farm

      private void create_farm(LinkedList<defaultJob<T,U>> worker_job, int emitter_strategy, int collector_strategy, int bufferSize)
      constructor given a list of defaultJob and the Emitter strategy
      Parameters:
      worker_job - list of defaultJob
      emitter_strategy - Emitter strategy between ROUNDROBIN, SCATTER, BROADCAST
      collector_strategy - Collector strategy between ROUNDROBIN, FIRSTCOME, GATHER
      bufferSize - buffer size of channels
    • connectEmitterWorkers

      public void connectEmitterWorkers()
      connect emitter to workers creating channels
    • connectWorkersCollector

      public void connectWorkersCollector()
      connect workers to the collector creating channels
    • start

      public void start()
      main method to start all farm threads
      Overrides:
      start in class ff_node<T,U>
    • join

      public void join()
      wait the farm to finish after EOS sent in the network
      Overrides:
      join in class ff_node<T,U>
    • pushElement

      public void pushElement(T i) throws InterruptedException
      Push element inside input stream at the bottom of the list
      Parameters:
      i - element to push
      Throws:
      InterruptedException
    • addInputChannel

      public void addInputChannel(ff_queue<T> input)
      add a new input channel to the farm (commonly one) - to the emitter
      Overrides:
      addInputChannel in class ff_node<T,U>
      Parameters:
      input - input channel
    • addOutputChannel

      public void addOutputChannel(ff_queue<U> output)
      add a new output channel to the collector
      Overrides:
      addOutputChannel in class ff_node<T,U>
      Parameters:
      output - output channel
    • removeEmitter

      public void removeEmitter()
      remove Emitter from farm, including channels between emitter and workers
    • removeCollector

      public void removeCollector()
      remove Collector from farm, including channels between workers and collector