Class: Celluloid::SupervisionGroup::Member

Inherits:
Object
  • Object
show all
Defined in:
lib/celluloid/supervision_group.rb

Overview

A member of the group

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry, klass, options = {}) ⇒ Member

Returns a new instance of Member.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :args (#call, Object) — default: []

    arguments array for the actor's constructor (lazy evaluation if it responds to #call)


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/celluloid/supervision_group.rb', line 118

def initialize(registry, klass, options = {})
  @registry = registry
  @klass = klass

  # Stringify keys :/
  options = options.each_with_object({}) { |(k,v), h| h[k.to_s] = v }

  @name = options['as']
  @block = options['block']
  @args = prepare_args(options['args'])
  @method = options['method'] || 'new_link'
  @pool = @method == 'pool_link'
  @pool_size = options['size'] if @pool

  start
end

Instance Attribute Details

#actorObject (readonly)

Returns the value of attribute actor


134
135
136
# File 'lib/celluloid/supervision_group.rb', line 134

def actor
  @actor
end

#nameObject (readonly)

Returns the value of attribute name


134
135
136
# File 'lib/celluloid/supervision_group.rb', line 134

def name
  @name
end

Instance Method Details

#cleanupObject


161
162
163
# File 'lib/celluloid/supervision_group.rb', line 161

def cleanup
  @registry.delete(@name) if @name
end

#restartObject


148
149
150
151
152
153
# File 'lib/celluloid/supervision_group.rb', line 148

def restart
  @actor = nil
  cleanup

  start
end

#startObject


136
137
138
139
140
141
142
143
144
145
146
# File 'lib/celluloid/supervision_group.rb', line 136

def start  # when it is a pool, then we don't splat the args
  # and we need to extract the pool size if set

  if @pool
    options = {:args => @args}
    options[:size] = @pool_size if @pool_size
    @args = [options]
  end
  @actor = @klass.send(@method, *@args, &@block)
  @registry[@name] = @actor if @name
end

#terminateObject


155
156
157
158
159
# File 'lib/celluloid/supervision_group.rb', line 155

def terminate
  cleanup
  @actor.terminate if @actor
rescue DeadActorError
end