Class: Celluloid::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/celluloid/group.rb,
lib/celluloid/group/pool.rb,
lib/celluloid/group/spawner.rb

Direct Known Subclasses

Pool, Spawner

Defined Under Namespace

Classes: Pool, Spawner

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGroup


5
6
7
8
9
10
# File 'lib/celluloid/group.rb', line 5

def initialize
  @pid = $$
  @mutex = Mutex.new
  @group = []
  @running = true
end

Instance Attribute Details

#groupObject

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


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

def active?
  @running
end

#assert_activeObject


12
13
14
# File 'lib/celluloid/group.rb', line 12

def assert_active
  fail Celluloid::NotActive unless active?
end

#assert_inactiveObject


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
    fail Celluloid::StillActive
  end
end

#createObject


59
60
61
# File 'lib/celluloid/group.rb', line 59

def create
  fail NotImplementedError
end

#eachObject


25
26
27
# File 'lib/celluloid/group.rb', line 25

def each
  to_a.each { |thread| yield thread }
end

#each_actor(&block) ⇒ Object


47
48
49
# File 'lib/celluloid/group.rb', line 47

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 != $$
end

#getObject


55
56
57
# File 'lib/celluloid/group.rb', line 55

def get
  fail NotImplementedError
end

#purge(thread) ⇒ Object


40
41
42
43
44
45
# File 'lib/celluloid/group.rb', line 40

def purge(thread)
  @mutex.synchronize do
    @group.delete(thread)
    thread.kill rescue nil
  end
end

#shutdownObject


63
64
65
# File 'lib/celluloid/group.rb', line 63

def shutdown
  fail NotImplementedError
end

#to_aObject


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