Class: Droonga::Distributor

Inherits:
Object
  • Object
show all
Includes:
TSort
Defined in:
lib/droonga/distributor.rb

Defined Under Namespace

Classes: CyclicStepsError, UndefinedInputError

Instance Method Summary collapse

Constructor Details

#initialize(dispatcher) ⇒ Distributor

Returns a new instance of Distributor.



40
41
42
# File 'lib/droonga/distributor.rb', line 40

def initialize(dispatcher)
  @dispatcher = dispatcher
end

Instance Method Details

#distribute(plan) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/droonga/distributor.rb', line 44

def distribute(plan)
  @dependency = {}
  plan.each do |step|
    @dependency[step] = step["inputs"]
    next unless step["outputs"]
    step["outputs"].each do |output|
      @dependency[output] = [step]
    end
  end
  steps = []
  each_strongly_connected_component do |cs|
    raise CyclicStepsError.new(cs) if cs.size > 1
    steps.concat(cs) unless cs.first.is_a? String
  end
  @dispatcher.dispatch_steps(steps)
end