Class: Pregel::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/pregel/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graph = []) ⇒ Worker

Returns a new instance of Worker.



5
6
7
8
9
# File 'lib/pregel/worker.rb', line 5

def initialize(graph = [])
  raise 'empty worker graph' if graph.empty?
  @vertices = graph
  @active   = graph.size
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



3
4
5
# File 'lib/pregel/worker.rb', line 3

def active
  @active
end

#verticesObject (readonly)

Returns the value of attribute vertices.



3
4
5
# File 'lib/pregel/worker.rb', line 3

def vertices
  @vertices
end

Instance Method Details

#superstepObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pregel/worker.rb', line 11

def superstep
  Thread.new do
    @vertices.each do |v|
      v.messages = PostOffice.instance.read(v.id)
      v.active! if v.messages.size > 0
    end

    active = @vertices.select {|v| v.active?}
    active.each {|v| v.step}

    @active = active.select {|v| v.active?}.size
  end
end