Class: Celluloid::Links

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/vendor/celluloid/lib/celluloid/links.rb

Overview

Thread safe storage of inter-actor links

Instance Method Summary collapse

Methods included from Enumerable

#to_json

Constructor Details

#initializeLinks

Returns a new instance of Links.



8
9
10
11
# File 'lib/vendor/celluloid/lib/celluloid/links.rb', line 8

def initialize
  @links = {}
  @lock  = Mutex.new
end

Instance Method Details

#<<(actor) ⇒ Object

Add an actor to the current links



14
15
16
17
18
19
# File 'lib/vendor/celluloid/lib/celluloid/links.rb', line 14

def <<(actor)
  @lock.synchronize do
    @links[actor.mailbox.address] = actor
  end
  actor
end

#delete(actor) ⇒ Object

Remove an actor from the links



29
30
31
32
33
34
# File 'lib/vendor/celluloid/lib/celluloid/links.rb', line 29

def delete(actor)
  @lock.synchronize do
    @links.delete actor.mailbox.address
  end
  actor
end

#eachObject

Iterate through all links



37
38
39
40
41
# File 'lib/vendor/celluloid/lib/celluloid/links.rb', line 37

def each
  @lock.synchronize do
    @links.each { |_, actor| yield(actor) }
  end
end

#include?(actor) ⇒ Boolean

Do links include the given actor?

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/vendor/celluloid/lib/celluloid/links.rb', line 22

def include?(actor)
  @lock.synchronize do
    @links.has_key? actor.mailbox.address
  end
end

#inspectObject

Generate a string representation



56
57
58
59
# File 'lib/vendor/celluloid/lib/celluloid/links.rb', line 56

def inspect
  links = self.map(&:inspect).join(',')
  "#<#{self.class}[#{links}]>"
end

#mapObject

Map across links



44
45
46
47
48
# File 'lib/vendor/celluloid/lib/celluloid/links.rb', line 44

def map
  result = []
  each { |actor| result << yield(actor) }
  result
end

#send_event(event) ⇒ Object

Send an event message to all actors



51
52
53
# File 'lib/vendor/celluloid/lib/celluloid/links.rb', line 51

def send_event(event)
  each { |actor| actor.mailbox.system_event event }
end