Class: Celluloid::Actor::System

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/celluloid/actor/system.rb

Constant Summary collapse

ROOT_SERVICES =
[
  {
    as: :notifications_fanout,
    type: Celluloid::Notifications::Fanout
  },
  {
    as: :public_services,
    type: Celluloid::Supervision::Service::Public,
    accessors: [:services],
    supervise: []
  }
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSystem

Returns a new instance of System.

[View source]

35
36
37
38
39
40
# File 'lib/celluloid/actor/system.rb', line 35

def initialize
  @tree = nil
  @group = Celluloid.group_class.new
  @registry = Internals::Registry.new
  @root = ROOT_SERVICES
end

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group.


23
24
25
# File 'lib/celluloid/actor/system.rb', line 23

def group
  @group
end

#registryObject (readonly)

Returns the value of attribute registry.


23
24
25
# File 'lib/celluloid/actor/system.rb', line 23

def registry
  @registry
end

Instance Method Details

#assert_inactiveObject

[View source]

138
139
140
# File 'lib/celluloid/actor/system.rb', line 138

def assert_inactive
  @group.assert_inactive
end

#clear_registryObject

[View source]

78
79
80
# File 'lib/celluloid/actor/system.rb', line 78

def clear_registry
  @registry.clear
end

#get_threadObject

[View source]

59
60
61
62
63
64
# File 'lib/celluloid/actor/system.rb', line 59

def get_thread
  @group.get do
    Thread.current[:celluloid_actor_system] = self
    yield
  end
end

#registeredObject

[View source]

74
75
76
# File 'lib/celluloid/actor/system.rb', line 74

def registered
  @registry.names
end

#root_configurationObject

[View source]

31
32
33
# File 'lib/celluloid/actor/system.rb', line 31

def root_configuration
  @root
end

#root_servicesObject

the root of the supervisor tree is established at supervision/root

[View source]

27
28
29
# File 'lib/celluloid/actor/system.rb', line 27

def root_services
  @tree
end

#runningObject

[View source]

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/celluloid/actor/system.rb', line 82

def running
  actors = []
  @group.each do |t|
    next unless t.role == :actor
    actor = t.actor

    # NOTE - these are in separate statements, since on JRuby t.actor may
    # become nil befor .behavior_proxy() is called
    next unless actor
    next unless actor.respond_to?(:behavior_proxy)
    proxy = actor.behavior_proxy
    actors << proxy
  end
  actors
end

#running?Boolean

Returns:

  • (Boolean)
[View source]

98
99
100
# File 'lib/celluloid/actor/system.rb', line 98

def running?
  @group.active?
end

#shutdownObject

Shut down all running actors

[View source]

103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/celluloid/actor/system.rb', line 103

def shutdown
  actors = running
  Timeout.timeout(shutdown_timeout) do
    Internals::Logger.debug "Terminating #{actors.size} #{actors.size > 1 ? 'actors' : 'actor'}..." unless actors.empty?

    # Actors cannot self-terminate, you must do it for them
    actors.each do |actor|
      begin
        actor.terminate!
      rescue DeadActorError
      end
    end

    actors.each do |actor|
      begin
        Actor.join(actor)
      rescue DeadActorError
      end
    end
  end
rescue Timeout::Error
  Internals::Logger.error("Couldn't cleanly terminate all actors in #{shutdown_timeout} seconds!")
  unless RUBY_PLATFORM == "java" || RUBY_ENGINE == "rbx"
    actors.each do |actor|
      begin
        Actor.kill(actor)
      rescue DeadActorError, MailboxDead
      end
    end
  end
ensure
  @group.shutdown
  clear_registry
end

#shutdown_timeoutObject

[View source]

142
143
144
# File 'lib/celluloid/actor/system.rb', line 142

def shutdown_timeout
  Celluloid.shutdown_timeout
end

#stack_dumpObject

[View source]

66
67
68
# File 'lib/celluloid/actor/system.rb', line 66

def stack_dump
  Internals::Stack::Dump.new(@group)
end

#stack_summaryObject

[View source]

70
71
72
# File 'lib/celluloid/actor/system.rb', line 70

def stack_summary
  Internals::Stack::Summary.new(@group)
end

#startObject

Launch default services

[View source]

43
44
45
46
47
48
49
# File 'lib/celluloid/actor/system.rb', line 43

def start
  within do
    @root = Supervision::Service::Root.define
    @tree = root_configuration.deploy
  end
  true
end

#withinObject

[View source]

51
52
53
54
55
56
57
# File 'lib/celluloid/actor/system.rb', line 51

def within
  old = Thread.current[:celluloid_actor_system]
  Thread.current[:celluloid_actor_system] = self
  yield
ensure
  Thread.current[:celluloid_actor_system] = old
end