celluloid-supervision-0.20.5/0000755000004100000410000000000012613521246016170 5ustar www-datawww-datacelluloid-supervision-0.20.5/.env-ci0000644000004100000410000000020312613521246017345 0ustar www-datawww-dataCELLULOID_SPECS_LOG_STRATEGY=stderr CELLULOID_SPECS_LOG_LEVEL=3 CELLULOID_SPECS_LOG_FILE=log/ci.log CELLULOID_SPECS_LOG_SYNC=false celluloid-supervision-0.20.5/Rakefile0000644000004100000410000000031512613521246017634 0ustar www-datawww-datarequire "bundler/gem_tasks" Dir["tasks/**/*.rake"].each { |task| load task } default_tasks = ["spec"] default_tasks << "rubocop" unless ENV["CI"] task default: default_tasks task ci: %w(spec benchmark) celluloid-supervision-0.20.5/Gemfile0000644000004100000410000000012512613521246017461 0ustar www-datawww-datarequire File.expand_path("../culture/sync", __FILE__) Celluloid::Sync::Gemfile[self] celluloid-supervision-0.20.5/.coveralls.yml0000644000004100000410000000000012613521246020751 0ustar www-datawww-datacelluloid-supervision-0.20.5/.rspec0000644000004100000410000000011712613521246017304 0ustar www-datawww-data--color --format documentation --order random --warnings --require spec_helper celluloid-supervision-0.20.5/.travis.yml0000644000004100000410000000172612613521246020307 0ustar www-datawww-datascript: rake ci language: ruby rvm: - rbx-2 - jruby - 2.2.2 - 2.2.0 - 2.1.4 - 2.0.0 - 1.9.3 - ruby-head - jruby-head matrix: fast_finish: true allow_failures: - rvm: 1.9.3 - rvm: ruby-head - rvm: jruby-head - env: CELLULOID_BACKPORTED=true - env: CELLULOID_BACKPORTED=false CELLULOID_TASK_CLASS=Threaded - env: CELLULOID_BACKPORTED=true CELLULOID_TASK_CLASS=Threaded env: global: - NUMBER_OF_PROCESSORS=4 CELLULOID_CONFIG_FILE=.env-ci matrix: - CELLULOID_BACKPORTED=true - CELLULOID_BACKPORTED=false - CELLULOID_BACKPORTED=false CELLULOID_TASK_CLASS=Threaded - CELLULOID_BACKPORTED=true CELLULOID_TASK_CLASS=Threaded notifications: irc: "irc.freenode.org#celluloid" before_install: # Only use 1 job until Travis fixes the rbx --jobs issue. - if [ "$TRAVIS_RUBY_VERSION" == "rbx-2" ] ; then export BUNDLE_JOBS=1 ; else export BUNDLE_JOBS=4; fi sudo: false install: bundle install --without=development celluloid-supervision-0.20.5/lib/0000755000004100000410000000000012613521246016736 5ustar www-datawww-datacelluloid-supervision-0.20.5/lib/celluloid/0000755000004100000410000000000012613521246020712 5ustar www-datawww-datacelluloid-supervision-0.20.5/lib/celluloid/supervision/0000755000004100000410000000000012613521246023300 5ustar www-datawww-datacelluloid-supervision-0.20.5/lib/celluloid/supervision/configuration.rb0000644000004100000410000001107412613521246026477 0ustar www-datawww-datamodule Celluloid module Supervision class Configuration class << self def deploy(options={}) define(options).deploy end def define(options={}) new(options) end end extend Forwardable def_delegators :current_instance, :delete, :key?, :set, :get, :[], :[]=, :injection!, :injections! attr_accessor :instances def initialize(options={}) @instances = [Instance.new] @branch = :services @i = 0 # incrementer of instances in this branch resync_accessors @configuration = options if options.is_a? Hash options[:configuration] ||= Container::Behavior.configure(options) @configuration = instance_eval(&options[:configuration]) @supervisor ||= @configuration.fetch(:supervisor, :"Celluloid.services") end @supervisor ||= :"Celluloid.services" if (@configuration.is_a?(Hash) || @configuration.is_a?(Array)) && @configuration.any? define(@configuration) end end def provider @provider ||= if @supervisor.is_a? Hash @supervisor[:type].run!(@supervisor) elsif @supervisor.is_a? Symbol @supervisor = Object.module_eval(@supervisor.to_s) provider elsif @supervisor.is_a? Class @supervisor.run! elsif @supervisor.respond_to? :supervise @supervisor else fail Error::InvalidSupervisor end end def deploy(options={}) define(options) if options.any? @instances.each do |instance| provider.add instance.merge(branch: @branch) end provider end def count @instances.count end def each(&block) @instances.each(&block) end def resync_accessors # methods for setting and getting the usual defaults Configuration.parameters(:mandatory, :optional, :plugins, :meta).each do |key| [:"#{key}!", :"#{key}="].each do |m| self.class.instance_eval do remove_method :"#{m}" rescue nil # avoid warnings in tests define_method(m) { |p| current_instance.send(m, p) } end end [:"#{key}?", :"#{key}"].each do |m| self.class.instance_eval do remove_method :"#{m}" rescue nil # avoid warnings in tests define_method(m) { current_instance.send(m) } end end end Configuration.aliases.each do |_alias, _original| ["!", :"=", :"?", :""]. each do |m| self.class.instance_eval do remove_method :"#{_alias}#{m}" rescue nil # avoid warnings in tests alias_method :"#{_alias}#{m}", :"#{_original}#{m}" end end end end def merge!(values) if values.is_a?(Configuration) || values.is_a?(Hash) current_instance.merge!(values) else fail Error::Invalid end end def merge(values) if values.is_a?(Configuration) || values.is_a?(Hash) current_instance.merge(values) else fail Error::Invalid end end def export return current_instance.to_hash if @i == 0 @instances.map(&:export) end def include?(name) @instances.map(&:name).include? name end def define(configuration, fail=false) if configuration.is_a? Array configuration.each { |c| define(c, fail) } else unless include? configuration[:as] begin current_instance.define(configuration, fail) rescue Error::AlreadyDefined increment retry end end end self end def increment @i += 1 end alias_method :another, :increment def add(options) define(options) provider.supervise options if Configuration.valid? options end def shutdown @provider.shutdown end private def current_instance @instances[@i] ||= Instance.new end def invoke_injection(_point) # de puts "injection? #{point}" end end end end celluloid-supervision-0.20.5/lib/celluloid/supervision/validation.rb0000644000004100000410000000246512613521246025766 0ustar www-datawww-datamodule Celluloid module Supervision class Configuration class << self def valid?(configuration, fails=false) parameters(:mandatory).each do |k| unless configuration.key? k if fails fail Error::Incomplete, "Missing `:#{k}` in supervision configuration." else return false end end end arity.each do |klass, args| unless configuration[args].is_a? Proc __a = configuration[args] && configuration[args].count || 0 __arity = configuration[klass].allocate.method(:initialize).arity unless (__arity < 0 && __a >= __arity.abs - 1) || __a == __arity.abs if fails fail ArgumentError.new("#{__a} vs. #{__arity}") else return false end end end end true end def options(config={}, options={}) configuration = config.merge(options) return configuration if configuration.is_a? Configuration configuration[:configuration] = Container::Behavior.configure(configuration) valid?(configuration, true) configuration end end end end end celluloid-supervision-0.20.5/lib/celluloid/supervision/container.rb0000644000004100000410000000710112613521246025606 0ustar www-datawww-datamodule Celluloid # Supervise actor instances in a container. module Supervision class Container include Celluloid trap_exit :restart_actor class << self def define(options) Configuration.define(top(options)) end def deploy(options) Configuration.deploy(top(options)) end def top(options) { as: (options.delete(:as)), type: (options.delete(:type) || self), branch: (options.delete(:branch) || :services), supervise: options.delete(:supervise) || [], } end # Actors or sub-applications to be supervised def blocks @blocks ||= [] end # Start this application (and watch it with a supervisor) def run!(options={}) container = new(options) do |g| blocks.each do |block| block.call(g) end end container end # Run the application in the foreground with a simple watchdog def run(options={}) loop do supervisor = run!(options) # Take five, toplevel supervisor sleep 5 while supervisor.alive? # Why 5? Internals::Logger.error "!!! Celluloid::Supervision::Container #{self} crashed. Restarting..." end end end finalizer :finalize attr_accessor :registry # Start the container. def initialize(options={}) options = {registry: options} if options.is_a? Internals::Registry @state = :initializing @actors = [] # instances in the container @registry = options.delete(:registry) || Celluloid.actor_system.registry @branch = options.delete(:branch) || :services yield current_actor if block_given? end execute_block_on_receiver :initialize, :supervise, :supervise_as def add(configuration) Configuration.valid?(configuration, true) @actors << Instance.new(configuration.merge(registry: @registry, branch: @branch)) @state = :running add_accessors configuration Actor.current end def add_accessors(configuration) if configuration[:as] unless methods.include? configuration[:as] self.class.instance_eval do define_method(configuration[:as]) do @registry[configuration[:as]] end end end end end def remove_accessors end def remove(actor) actor = Celluloid::Actor[actor] if actor.is_a? Symbol instance = find(actor) instance.terminate if instance end def actors @actors.map(&:actor) end def find(actor) @actors.find do |instance| instance.actor == actor end end def [](actor_name) @registry[actor_name] end # Restart a crashed actor def restart_actor(actor, reason) return if @state == :shutdown instance = find(actor) fail "a container instance went missing. This shouldn't be!" unless instance if reason exclusive { instance.restart } else instance.cleanup @actors.delete(instance) end end def shutdown @state = :shutdown finalize end private def finalize if @actors @actors.reverse_each do |instance| instance.terminate @actors.delete(instance) end end end end end end celluloid-supervision-0.20.5/lib/celluloid/supervision/configuration/0000755000004100000410000000000012613521246026147 5ustar www-datawww-datacelluloid-supervision-0.20.5/lib/celluloid/supervision/configuration/injections.rb0000644000004100000410000000016012613521246030636 0ustar www-datawww-datamodule Celluloid module Supervision class Configuration class Injection end end end end celluloid-supervision-0.20.5/lib/celluloid/supervision/configuration/instance.rb0000644000004100000410000000643112613521246030304 0ustar www-datawww-datamodule Celluloid module Supervision class Configuration class Instance attr_accessor :configuration def initialize(configuration={}) @state = :initializing # :ready resync_accessors @configuration = configuration define(configuration) if configuration.any? end def export @configuration.select { |k, v| !REMOVE_AT_EXPORT.include? k } end def ready?(fail=false) unless @state == :ready @state = :ready if Configuration.valid? @configuration, fail end @state == :ready end def define(instance, fail=false) fail Configuration::Error::AlreadyDefined if ready? fail invoke_injection(:before_configuration) @configuration = Configuration.options(instance) ready? end def injection!(key, proc) @configuration[:injections] ||= {} @configuration[:injections][key] = proc end def injections!(_procs) @configuration[:injections] = proces end def resync_accessors # methods for setting and getting the usual defaults Configuration.parameters(:mandatory, :optional, :plugins, :meta).each do |key| self.class.instance_eval do remove_method :"#{key}!" rescue nil # avoid warnings in tests define_method(:"#{key}!") { |value| @configuration[key] = value } end self.class.instance_eval do remove_method :"#{key}=" rescue nil # avoid warnings in tests define_method(:"#{key}=") { |value| @configuration[key] = value } end self.class.instance_eval do remove_method :"#{key}?" rescue nil # avoid warnings in tests define_method(:"#{key}?") { !@configuration[key].nil? } end self.class.instance_eval do remove_method :"#{key}" rescue nil # avoid warnings in tests define_method(:"#{key}") { @configuration[key] } end end Configuration.aliases.each do |_alias, _original| ["!", :"=", :"?", :""]. each do |m| self.class.instance_eval do remove_method :"#{_alias}#{m}" rescue nil # avoid warnings in tests alias_method :"#{_alias}#{m}", :"#{_original}#{m}" end end end true end def merge!(values) @configuration = @configuration.merge(values) end def merge(values) if values.is_a? Configuration @configuration.merge(values.configuration) elsif values.is_a? Hash @configuration.merge(values) else fail Error::Invalid end end def key?(k) @configuration.key?(k) end def set(key, value) @configuration[key] = value end alias_method :[]=, :set def get(key) @configuration[key] end alias_method :[], :get def delete(k) @configuration.delete(k) end private def invoke_injection(_point) # de puts "injection? #{point}" end end end end end celluloid-supervision-0.20.5/lib/celluloid/supervision/deprecate.rb0000644000004100000410000000045312613521246025563 0ustar www-datawww-data# TODO: Remove at 0.19.0 module Celluloid SupervisionGroup = Supervision::Container Supervision::Group = Supervision::Container Supervision::Member = Supervision::Container::Instance end require "celluloid/supervision/deprecate/supervise" require "celluloid/supervision/deprecate/validation" celluloid-supervision-0.20.5/lib/celluloid/supervision/version.rb0000644000004100000410000000010712613521246025310 0ustar www-datawww-datamodule Celluloid module Supervision VERSION = "0.20.5" end end celluloid-supervision-0.20.5/lib/celluloid/supervision/deprecate/0000755000004100000410000000000012613521246025234 5ustar www-datawww-datacelluloid-supervision-0.20.5/lib/celluloid/supervision/deprecate/validation.rb0000644000004100000410000000424412613521246027717 0ustar www-datawww-datamodule Celluloid module Supervision class Configuration class << self # argument scenarios: # * only class ( becomes :type ) # * class ( becomes :type ), hash* # * hash ( *with :type, and perhaps :as, :size, :args, :block, :registry ) # ( any keys expected are pulled out: may want to check on arity? ) # ( the pulling out of keys is where danger mentioned above comes ) undef parse rescue nil def parse(args) return args if args.is_a? Configuration::Instance options = {args: []} return {type: args} if args.is_a? Class if args.is_a? Hash return args elsif args.is_a? Array if args.length == 1 return args[0] if args.first.is_a? Configuration::Instance return {type: args.first} if args.first.is_a? Class if args.first.is_a?(Hash) && args = args.pop return args end options[:args] = args if args.any? elsif args.length > 1 # TODO: don't use each options.merge! args.pop if args.last.is_a? Hash options[:type] = args.shift if args.first.is_a? Class options[:args] += args if args.any? end end options end # This is dangerous. It is temporary, until `Supervision::Configuration` is entrenched. # Since :type, :as, etc are used by the supervision group/member to initialize, # those will not appear in the resulting actor's initialize call. undef options rescue nil def options(args, options={}) return args.merge!(options) if args.is_a? Configuration::Instance # Not a Supervision:Configuration? # Try to guess its structure and build one: options = parse(args).merge(options) options[:configuration] = Container::Behavior.configure(options) options[:args].compact! if options[:args].is_a? Array options.select! { |k, v| !v.nil? } Configuration.valid? options, true options end end end end end celluloid-supervision-0.20.5/lib/celluloid/supervision/deprecate/supervise.rb0000644000004100000410000000536412613521246027616 0ustar www-datawww-data# TODO: Remove at 0.19.0 module Celluloid class << self undef supervise rescue nil def supervise(*args, &block) supervisor = Supervision.router(*args) supervisor.supervise(*args, &block) end undef supervise_as rescue nil def supervise_as(name, *args, &block) supervisor = Supervision.router(*args) supervisor.supervise_as(name, *args, &block) end end module ClassMethods undef supervise rescue nil def supervise(*args, &block) args.unshift(self) Celluloid.supervise(*args, &block) end undef supervise_as rescue nil def supervise_as(name, *args, &block) args.unshift(self) Celluloid.supervise_as(name, *args, &block) end end # Supervisors are actors that watch over other actors and restart them if # they crash class Supervisor class << self # Define the root of the supervision tree attr_accessor :root undef supervise rescue nil def supervise(klass, *args, &block) args.unshift(klass) Celluloid.supervise(*args, &block) end undef supervise_as rescue nil def supervise_as(name, klass, *args, &block) args.unshift(klass) Celluloid.supervise_as(name, *args, &block) end end end module Supervision class << self undef router rescue nil def router(*_args) # TODO: Actually route, based on :branch, if present; or else: Celluloid.services end end class Container class << self undef run! rescue nil def run!(*args) container = new(*args) do |g| blocks.each do |block| block.call(g) end end container end undef run rescue nil def run(*args) loop do supervisor = run!(*args) # Take five, toplevel supervisor sleep 5 while supervisor.alive? # Why 5? Internals::Logger.error "!!! Celluloid::Supervision::Container #{self} crashed. Restarting..." end end undef supervise rescue nil def supervise(*args, &block) blocks << lambda do |container| container.supervise(*args, &block) end end undef supervise_as rescue nil def supervise_as(name, *args, &block) blocks << lambda do |container| container.supervise_as(name, *args, &block) end end end undef supervise rescue nil def supervise(*args, &block) add(Configuration.options(args, block: block)) end undef supervise_as rescue nil def supervise_as(name, *args, &block) add(Configuration.options(args, block: block, as: name)) end end end end celluloid-supervision-0.20.5/lib/celluloid/supervision/constants.rb0000644000004100000410000000567012613521246025651 0ustar www-datawww-datamodule Celluloid module Supervision # TODO: Do not hard-code. Allow configurable values. INSTANCE_RETRY_WAIT = 3 INSTANCE_RETRY_LIMIT = 5 module Error class NoPublicService < Celluloid::Error; end end class Configuration module Error class AlreadyDefined < Celluloid::Error; end class InvalidSupervisor < Celluloid::Error; end class InvalidValues < Celluloid::Error; end class Incomplete < Celluloid::Error; end class Invalid < Celluloid::Error; end end # Using class variable so that parameters can be added by plugins. @@parameters = { mandatory: [:type], optional: [ :as, :args, :block, ], # TODO: Move these into Behaviors. plugins: [ # de :size, # Supervision::Pool # de :routers, # Supervision::Coordinator # de :supervises # Supervision::Tree ], meta: [ :registry, :branch, :method, ], } @@arity = { type: :args, } @@aliases = { name: :as, kind: :type, # de :pool => :size, # TODO: Move into Behaviors. # de :supervise => :supervises } @@defaults = {} class << self def save_defaults @@defaults = { parameters: @@parameters.inject({}) { |p, (k, v)| p[k] = v.dup; p }, aliases: @@aliases.dup, arity: @@arity.dup, } end def resync_parameters @@parameters = @@defaults[:parameters].inject({}) { |p, (k, v)| p[k] = v.dup; p } @@aliases = @@defaults[:aliases].dup @@arity = @@defaults[:arity].dup end def parameters(*args) args.inject([]) { |parameters, p| parameters += @@parameters[p]; parameters } end def parameter!(key, value) @@parameters[key] << value unless @@parameters[key].include? value end def arity @@arity end def arity!(key, value) @@arity[key] = value end def aliases @@aliases end def alias!(aliased, original) @@aliases[aliased] = original end end save_defaults resync_parameters # This was originally added for `#pool` and `PoolManager # `:before_initialize` was added to allow detecting `:size => N` # and turning that into a pool. Other uses could be for `coordinator` # appointing a `router` by detecting `:routers => N`, and many other uses. ################ These are applied inside Supervision::Member ################ REMOVE_AT_EXPORT = [ :configuration, :behavior, ] INJECTIONS = [ :configuration, :before_initialization, :after_initialization, :before_start, :before_restart, ] end end end celluloid-supervision-0.20.5/lib/celluloid/supervision/service.rb0000644000004100000410000000117712613521246025273 0ustar www-datawww-datamodule Celluloid module Supervision module Service class Root < Container class << self def define super({ supervise: Celluloid.actor_system.root_configuration, as: :root_supervisor, accessors: [:root], branch: :root, type: self, }) end def deploy(instances) super(supervise: instances, branch: :root, as: :root, type: self) end end def provider Celluloid.root_services end end class Public < Container; end end end end celluloid-supervision-0.20.5/lib/celluloid/supervision/container/0000755000004100000410000000000012613521246025262 5ustar www-datawww-datacelluloid-supervision-0.20.5/lib/celluloid/supervision/container/behavior/0000755000004100000410000000000012613521246027061 5ustar www-datawww-datacelluloid-supervision-0.20.5/lib/celluloid/supervision/container/behavior/tree.rb0000644000004100000410000000167412613521246030355 0ustar www-datawww-datamodule Celluloid module Supervision class Container # class << self # def tree(actors=[], *args, &block) # blocks << lambda do |container| # container.tree(Configuration.options(args, :supervise => actors, :block => block )) # end # end # end class Tree include Behavior identifier! :supervises, :supervise configuration do if @configuration[:supervise].is_a? Array @supervisor = @configuration.dup @branch = @configuration.fetch(:branch, @configuration[:as]) @configuration.delete(Behavior.parameter(:supervise, @configuration)) else puts "#{@configuration[:supervise].class.name} ... #{@configuration[:supervise]}" fail ArgumentError.new("No actors given to Tree to supervise.") end end end end end end celluloid-supervision-0.20.5/lib/celluloid/supervision/container/tree.rb0000644000004100000410000000000012613521246026534 0ustar www-datawww-datacelluloid-supervision-0.20.5/lib/celluloid/supervision/container/injections.rb0000644000004100000410000000015412613521246027754 0ustar www-datawww-datamodule Celluloid module Supervision class Container class Injection end end end end celluloid-supervision-0.20.5/lib/celluloid/supervision/container/instance.rb0000644000004100000410000001041512613521246027414 0ustar www-datawww-datamodule Celluloid # Supervise collections of actors as a group module Supervision class Container class Instance attr_reader :name, :actor # @option options [#call, Object] :args ([]) arguments array for the # actor's constructor (lazy evaluation if it responds to #call) def initialize(configuration = {}) @type = configuration.delete(:type) @registry = configuration.delete(:registry) @branch = configuration.delete(:branch) || :services @configuration = configuration # allows injections inside initialize, start, and restart @injections = configuration.delete(:injections) || {} invoke_injection(:before_initialize) # Stringify keys :/ # de @configuration = configuration.each_with_object({}) { |(k,v), h| h[k.to_s] = v } @name = @configuration[:as] @block = @configuration[:block] @args = prepare_args(@configuration[:args]) @method = @configuration[:method] || "new_link" add_accessors invoke_injection(:after_initialize) start end def start invoke_injection(:before_start) @actor = @type.send(@method, *@args, &@block) @registry.add(@name, @actor, @branch) if @name invoke_injection(:after_start) rescue Celluloid::TaskTimeout => ex Internals::Logger.error("TaskTimeout at start of supervised instance of #{@type}") raise ex # TODO: Implement timeout/retry. # unless ( @retry += 1 ) <= INSTANCE_RETRY_LIMIT # raise ex # end # Internals::Logger.warn("TaskTimeout at start of supervised actor. Retrying in #{INSTANCE_RETRY_WAIT} seconds. ( Attempt #{@retry} of #{INSTANCE_RETRY_LIMIT} )") # sleep INSTANCE_RETRY_WAIT # retry rescue => ex Internals::Logger.error("Error ( #{ex.class} ) at start of supervised instance of #{@type}") raise ex end def restart # no need to reset @actor, as this is called in an `exclusive {}` block # @actor = nil # cleanup invoke_injection(:before_restart) start invoke_injection(:after_restart) end def terminate @actor.terminate if @actor cleanup rescue DeadActorError end def cleanup @registry.delete(@name) if @name end private def add_accessors remove_accessors if @configuration[:accessors].is_a? Array # TODO: Decide which level to keep, and only keep that. # Do we provide access by Celluloid.accessor # Do we provide access by Celluloid.actor_system.accessor @configuration[:accessors].each do |name| Celluloid.instance_exec(@configuration[:as], name) do |actor, where| define_method(name) do Celluloid.actor_system[actor] end end Celluloid::Actor::System.instance_exec(@configuration[:as], name) do |actor, where| define_method(name) do Celluloid.actor_system[actor] end end end end end def remove_accessors if @configuration[:accessors].is_a? Array @configuration[:accessors].each do |name| Celluloid.instance_eval do remove_method(name) rescue nil # avoid warnings in tests end Celluloid::Actor::System.instance_eval do remove_method(name) rescue nil # avoid warnings in tests end end end end def invoke_injection(name) return unless @injections block = @injections[name] instance_eval(&block) if block.is_a? Proc end # Executes args if it has the method #call, and converts the return # value to an Array. Otherwise, it just converts it to an Array. def prepare_args(args) args = args.call if args.respond_to?(:call) Array(args) end end end end end celluloid-supervision-0.20.5/lib/celluloid/supervision/container/behavior.rb0000644000004100000410000000552412613521246027414 0ustar www-datawww-datamodule Celluloid module Supervision class Container module Behavior @@injections = {} # Hash of Class => Hash of Injections @@behaviors = {} # Hash of identifying symbol parameter => Class module Error class Mutant < Celluloid::Error; end end class << self def included(klass) klass.send :extend, ClassMethods end def injections @@injections end def [](identifier) @@behaviors[identifier] end def []=(identifier, behavior) @@behaviors[identifier] = behavior end def parameter(identifier, options) found = nil p = Configuration.aliases.inject([identifier]) { |invoke, (a, i)| invoke << a if i == identifier; invoke } case p.count { |parameter| found = parameter; options.key?(parameter) } when 1 found when 0 else fail Error::Mutant.new("More than one kind of identifiable behavior parameter.") end end # Beware of order. There may be multiple behavior injections, but their order is not determined ( yet ) # Right now, something like a pool-coordinator-tree supervisor mutant are absolutely expected to crash. # Therefore, sorry Professor X -- we kill every Mutant. On sight, no questions asked. Zero mutant love. def configure(options) behavior = nil injection = nil @@behaviors.map do |identifier, injector| if identifier = parameter(identifier, options) if behavior fail Error::Mutant.new("More than one type of behavior expected.") else if @@injections[injector].include?(:configuration) injection = @@injections[behavior = injector][:configuration] options[:behavior] ||= behavior end end end end options[:type] ||= behavior injection || proc { @configuration } end module ClassMethods def identifier!(identifier, *aliases) Behavior[identifier] = self Configuration.parameter! :plugins, identifier aliases.each do |aliased| Configuration.alias! aliased, identifier end Configuration.save_defaults end def behavior_injections Behavior.injections[self] ||= {} end Configuration::INJECTIONS.each do |point| define_method(point) do |&injector| behavior_injections[point] = injector end end end end end end end end celluloid-supervision-0.20.5/lib/celluloid/supervision/supervise.rb0000644000004100000410000000153312613521246025654 0ustar www-datawww-data# collect together all instances of the `supervise` method module Celluloid class << self def supervise(config={}, &block) supervisor = Supervision.router(config) supervisor.supervise(config, &block) end end module ClassMethods def supervise(config={}, &block) Celluloid.supervise(config.merge(type: self), &block) end end module Supervision class << self def router(_config={}) # TODO: Actually route. Celluloid.services # for now, hardcode .services end end class Container class << self def supervise(config, &block) blocks << lambda do |container| container.add(config, &block) end end end def supervise(config, &block) add(Configuration.options(config, block: block)) end end end end celluloid-supervision-0.20.5/lib/celluloid/supervision.rb0000644000004100000410000000121512613521246023624 0ustar www-datawww-datarequire "celluloid" unless defined? Celluloid require "celluloid/supervision/constants" require "celluloid/supervision/supervise" require "celluloid/supervision/container" require "celluloid/supervision/container/instance" require "celluloid/supervision/container/behavior" require "celluloid/supervision/container/injections" require "celluloid/supervision/container/behavior/tree" require "celluloid/supervision/validation" require "celluloid/supervision/configuration" require "celluloid/supervision/configuration/instance" require "celluloid/supervision/service" require "celluloid/supervision/deprecate" unless $CELLULOID_BACKPORTED == false celluloid-supervision-0.20.5/.rubocop.yml0000644000004100000410000000005512613521246020442 0ustar www-datawww-datainherit_from: - culture/rubocop/rubocop.ymlcelluloid-supervision-0.20.5/metadata.yml0000644000004100000410000002066612613521246020505 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: celluloid-supervision version: !ruby/object:Gem::Version version: 0.20.5 platform: ruby authors: - Donovan Keme - Tony Arcieri - Tim Carey-Smith autorequire: bindir: bin cert_chain: [] date: 2015-09-30 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: bundler version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: nenv version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: dotenv version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: benchmark_suite version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rubocop version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: transpec version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: pry version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rake version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rspec version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: guard-rspec version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rspec-retry version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: coveralls version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: celluloid version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 0.17.2 type: :development prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 0.17.2 - !ruby/object:Gem::Dependency name: celluloid-essentials version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: celluloid-pool version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: celluloid-fsm version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: celluloid-extras version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: timers version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 4.1.1 type: :runtime prerelease: false requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: 4.1.1 description: Supervisors, Supervision Groups, and Supervision Trees for Celluloid. email: - code@extremist.digital - tony.arcieri@gmail.com executables: [] extensions: [] extra_rdoc_files: [] files: - ".coveralls.yml" - ".env-ci" - ".env-dev" - ".gitignore" - ".gitmodules" - ".rspec" - ".rubocop.yml" - ".travis.yml" - CHANGES.md - Gemfile - LICENSE - README.md - Rakefile - celluloid-supervision.gemspec - lib/celluloid/supervision.rb - lib/celluloid/supervision/configuration.rb - lib/celluloid/supervision/configuration/injections.rb - lib/celluloid/supervision/configuration/instance.rb - lib/celluloid/supervision/constants.rb - lib/celluloid/supervision/container.rb - lib/celluloid/supervision/container/behavior.rb - lib/celluloid/supervision/container/behavior/tree.rb - lib/celluloid/supervision/container/injections.rb - lib/celluloid/supervision/container/instance.rb - lib/celluloid/supervision/container/tree.rb - lib/celluloid/supervision/deprecate.rb - lib/celluloid/supervision/deprecate/supervise.rb - lib/celluloid/supervision/deprecate/validation.rb - lib/celluloid/supervision/service.rb - lib/celluloid/supervision/supervise.rb - lib/celluloid/supervision/validation.rb - lib/celluloid/supervision/version.rb - tasks/benchmarks.rake - tasks/rspec.rake - tasks/rubocop.rake homepage: https://github.com/celluloid/ licenses: - MIT metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.4.8 signing_key: specification_version: 4 summary: Celluloid Supervision test_files: [] celluloid-supervision-0.20.5/.gitignore0000644000004100000410000000010012613521246020147 0ustar www-datawww-datacoverage/ rdoc/ doc/ pkg/ tmp/ .yardoc .bundle Gemfile.lock log celluloid-supervision-0.20.5/celluloid-supervision.gemspec0000644000004100000410000000143612613521246024101 0ustar www-datawww-data# -*- encoding: utf-8 -*- require File.expand_path("../culture/sync", __FILE__) Gem::Specification.new do |gem| gem.name = "celluloid-supervision" gem.version = Celluloid::Supervision::VERSION gem.platform = Gem::Platform::RUBY gem.summary = "Celluloid Supervision" gem.description = "Supervisors, Supervision Groups, and Supervision Trees for Celluloid." gem.licenses = ["MIT"] gem.authors = ["Donovan Keme", "Tony Arcieri", "Tim Carey-Smith"] gem.email = ["code@extremist.digital", "tony.arcieri@gmail.com"] gem.homepage = "https://github.com/celluloid/" gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|examples|spec|features)/}) } gem.require_path = "lib" Celluloid::Sync::Gemspec[gem] end celluloid-supervision-0.20.5/tasks/0000755000004100000410000000000012613521246017315 5ustar www-datawww-datacelluloid-supervision-0.20.5/tasks/rubocop.rake0000644000004100000410000000011312613521246021625 0ustar www-datawww-dataunless ENV["CI"] require "rubocop/rake_task" RuboCop::RakeTask.new end celluloid-supervision-0.20.5/tasks/benchmarks.rake0000644000004100000410000000071212613521246022276 0ustar www-datawww-datarequire "timeout" desc "Run Celluloid benchmarks" task :benchmark do begin Timeout.timeout(120) do glob = File.expand_path("../../benchmarks/*.rb", __FILE__) Dir[glob].each { |benchmark| load benchmark } end rescue Exception, Timeout::Error => ex puts "ERROR: Couldn't complete benchmark: #{ex.class}: #{ex}" puts " #{ex.backtrace.join("\n ")}" exit 1 unless ENV["CI"] # Hax for running benchmarks on Travis end end celluloid-supervision-0.20.5/tasks/rspec.rake0000644000004100000410000000017512613521246021300 0ustar www-datawww-datarequire "rspec/core/rake_task" RSpec::Core::RakeTask.new RSpec::Core::RakeTask.new(:rcov) do |task| task.rcov = true end celluloid-supervision-0.20.5/LICENSE0000644000004100000410000000206512613521246017200 0ustar www-datawww-dataThe MIT License (MIT) Copyright (c) 2015 Celluloid Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. celluloid-supervision-0.20.5/CHANGES.md0000644000004100000410000000102012613521246017553 0ustar www-datawww-data0.20.5 (2015-09-30) ----- * Revamped test suite, using shared RSpec configuration layer provided by Celluloid itself. * Updated gem dependencies provided by Celluloid::Sync... extraneous gems removed, or marked as development dependencies. 0.20.1 (2015-08-06) ----- * Fixed arity checking * Added usage examples to README * Change reference to `Actor::System` ( was `ActorSystem` ) 0.20.0 (2015-07-04) ----- * Extracted from Celluloid * Re-added Supervision Trees * Added Configuration object * Added injections and behaviors celluloid-supervision-0.20.5/.env-dev0000644000004100000410000000020412613521246017531 0ustar www-datawww-dataCELLULOID_SPECS_LOG_STRATEGY=single CELLULOID_SPECS_LOG_FILE=log/test.log CELLULOID_SPECS_LOG_LEVEL=0 CELLULOID_SPECS_LOG_SYNC=true celluloid-supervision-0.20.5/README.md0000644000004100000410000000522012613521246017446 0ustar www-datawww-data![Celluloid Supervision](https://raw.github.com/celluloid/celluloid-logos/master/celluloid-supervision/celluloid-supervision.png) [![Gem Version](https://badge.fury.io/rb/celluloid-supervision.svg)](http://rubygems.org/gems/celluloid-supervision) [![Build Status](https://secure.travis-ci.org/celluloid/celluloid-supervision.svg?branch=master)](http://travis-ci.org/celluloid/celluloid-supervision) [![Code Climate](https://codeclimate.com/github/celluloid/celluloid-supervision.svg)](https://codeclimate.com/github/celluloid/celluloid-supervision) [![Coverage Status](https://coveralls.io/repos/celluloid/celluloid-supervision/badge.svg?branch=master)](https://coveralls.io/r/celluloid/celluloid-supervision) Supervisors; with Supervision Containers (Groups), Configurations, and Trees for [Celluloid](https://github.com/celluloid/celluloid). To supervise actors, you have many options: # Using supervisors. ### Directly ```ruby MyActor.supervise as: :my_actor # Without arguments. MyActor.supervise as: :my_actor, args: [:one_arg, :two_args] ``` ### Indirectly ```ruby Celluloid.supervise as: :my_actor, type: MyActor # Without arguments. Celluloid.supervise as: :my_actor, type: MyActor, args: [:one_arg, :two_args] ``` # Using containers. ```ruby container = Celluloid::Supervision::Container.new { supervise type: MyActor, as: :my_actor supervise type: MyActor, as: :my_actor_with_args, args: [:one_arg, :two_args] } container.run! ``` # Using configuration objects: ```ruby config = Celluloid::Supervision::Configuration.define([ { type: MyActor, as: :my_actor }, { type: MyActor, as: :my_actor_with_args, args: [ :one_arg, :two_args ] }, ]) # Whenever you would like to deploy the actors: config.deploy # Whenver you would like to shut them down: config.shutdown # Reuse the same configuration if you like! config.deploy ``` ### By on-going configuration object: ```ruby config = Celluloid::Supervision::Configuration.new config.define type: MyActor, as: :my_actor config.define type: MyActor, as: :my_actor_with_args, args: [:one_arg, :two_args] config deploy # Now add actors to the already running configuration. config.add type: MyActor, as: :my_actor_deployed_immediately config.shutdown ``` # Documentation coming: * Supervision Trees * Supervised Pools * Supervised Supervisors ## Contributing * Fork this repository on github. * Make your changes and send us a pull request. * If we like them we'll merge them. * If we've accepted a patch, feel free to ask for commit access. ## License Copyright (c) 2011-2015 Tony Arcieri, Donovan Keme. Distributed under the MIT License. See LICENSE.txt for further details.celluloid-supervision-0.20.5/.gitmodules0000644000004100000410000000012512613521246020343 0ustar www-datawww-data[submodule "culture"] path = culture url = http://github.com/celluloid/culture.git