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

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

#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

Returns:

  • (Boolean)


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

def active?
  @running
end

#assert_activeObject



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

def assert_active
  raise 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
    raise Celluloid::StillActive
  end
end

#createObject

Raises:

  • (NotImplementedError)


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

def create
  raise 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



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

Returns:

  • (Boolean)


29
30
31
# File 'lib/celluloid/group.rb', line 29

def forked?
  @pid != $PROCESS_ID
end

#getObject

Raises:

  • (NotImplementedError)


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

#shutdownObject

Raises:

  • (NotImplementedError)


67
68
69
# File 'lib/celluloid/group.rb', line 67

def shutdown
  raise 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