Class: Celluloid::Group
- Inherits:
-
Object
- Object
- Celluloid::Group
- Defined in:
- lib/celluloid/group.rb,
lib/celluloid/group/pool.rb,
lib/celluloid/group/spawner.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#group ⇒ Object
Returns the value of attribute group.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #assert_active ⇒ Object
- #assert_inactive ⇒ Object
- #create ⇒ Object
- #each ⇒ Object
- #each_actor(&block) ⇒ Object
- #forked? ⇒ Boolean
- #get ⇒ Object
-
#initialize ⇒ Group
constructor
A new instance of Group.
- #purge(thread) ⇒ Object
- #shutdown ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize ⇒ Group
Returns a new instance of Group.
5 6 7 8 9 10 |
# File 'lib/celluloid/group.rb', line 5 def initialize @pid = $PROCESS_ID @mutex = Mutex.new @group = [] @running = true end |
Instance Attribute Details
#group ⇒ Object
Returns the value of attribute group.
3 4 5 |
# File 'lib/celluloid/group.rb', line 3 def group @group end |
Instance Method Details
#active? ⇒ Boolean
55 56 57 |
# File 'lib/celluloid/group.rb', line 55 def active? @running end |
#assert_active ⇒ Object
12 13 14 |
# File 'lib/celluloid/group.rb', line 12 def assert_active raise Celluloid::NotActive unless active? end |
#assert_inactive ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/celluloid/group.rb', line 16 def assert_inactive return unless active? if RUBY_PLATFORM == "java" Celluloid.logger.warn "Group is still active" else raise Celluloid::StillActive end end |
#create ⇒ Object
63 64 65 |
# File 'lib/celluloid/group.rb', line 63 def create raise NotImplementedError end |
#each ⇒ Object
25 26 27 |
# File 'lib/celluloid/group.rb', line 25 def each to_a.each { |thread| yield thread } end |
#each_actor(&block) ⇒ Object
51 52 53 |
# File 'lib/celluloid/group.rb', line 51 def each_actor(&block) to_a.lazy.select { |t| t[:celluloid_role] == :actor }.each(&block) end |
#forked? ⇒ Boolean
29 30 31 |
# File 'lib/celluloid/group.rb', line 29 def forked? @pid != $PROCESS_ID end |
#get ⇒ Object
59 60 61 |
# File 'lib/celluloid/group.rb', line 59 def get raise NotImplementedError end |
#purge(thread) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/celluloid/group.rb', line 40 def purge(thread) @mutex.synchronize do @group.delete(thread) begin thread.kill rescue nil end end end |
#shutdown ⇒ Object
67 68 69 |
# File 'lib/celluloid/group.rb', line 67 def shutdown raise NotImplementedError end |
#to_a ⇒ Object
33 34 35 36 37 38 |
# File 'lib/celluloid/group.rb', line 33 def to_a return [] if forked? res = nil @mutex.synchronize { res = @group.dup } res end |