Module: PrivateMethodsCariocaServicesRegistry
- Included in:
- Carioca::Services::Registry
- Defined in:
- lib/carioca/private.rb
Overview
private methods to mixin Carioca::Services::Registry
Instance Method Summary collapse
-
#get_ring ⇒ Object
run a ring servier instance or get existing.
-
#initialize(_options) ⇒ Object
private initializer.
-
#instanciate_service(_opts) ⇒ Object
instanciate Object from class defintion of a service defined in the service definition in _opts.
- #kill_distributed_service(options) ⇒ Object
-
#kill_service(options) ⇒ Object
call the garbage method of a service if exist and Delete from the loaded services list.
-
#require_service(_options) ⇒ Object
require file for a service from a service definition in _options.
-
#scan_instance_suffix(options) ⇒ Object
scan for <service>_<instance> and rewrite options with :name and :shortname, :instance.
-
#shutdown_ring_if_empty ⇒ Object
shutdown ring server if empty.
-
#verify_requires_dependancies(_options) ⇒ Object
verify dependancies in services structure in @list from a service defition in _options and start it if needed.
Instance Method Details
#get_ring ⇒ Object
run a ring servier instance or get existing
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/carioca/private.rb', line 105 def get_ring @dorsal_controller = start_service :name => 'dorsal' @ring_server = @dorsal_controller.bind_to_ring if @ring_server.nil? then @dorsal_controller.start_ring_server @ring_server = @dorsal_controller.bind_to_ring @log.debug('Carioca') { "Starting new Ring Server" } if @log else @log.debug('Carioca') { "Getting already started Ring Server" } if @log end end |
#initialize(_options) ⇒ Object
private initializer
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/carioca/private.rb', line 14 def initialize() @logger_not_in_reg = false @debug = [:debug] @registry_filename = [:file] @name = [:name] @list = Hash::new load if File::exist?(@registry_filename) unless @list.include?('logger') then self.register_service({:name => 'logger', :service => 'Carioca::Services::InternalLogger', :resource => 'logger', :description => "The standard ruby Logger internal wrapper Service", :type => :builtin, :init_options => { :target => "/tmp/log.file"}}) @logger_not_in_reg = true end @loaded_services = Hash::new # preload logger service @log = self.start_service :name => 'logger' @log.level =(@debug)? Logger::DEBUG : Logger::INFO @log.debug('Carioca') { "Registry started, service logger preloaded" } @log.debug('Carioca') { "Logger registered, not in configured registry" } if @logger_not_in_reg end |
#instanciate_service(_opts) ⇒ Object
instanciate Object from class defintion of a service defined in the service definition in _opts
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/carioca/private.rb', line 119 def instanciate_service(_opts) _name = _opts[:shortname] dist = (@list[_name][:distributed].nil?)? false : @list[_name][:distributed] get_ring if dist @list[_name][:init_options].merge! _opts[:params] unless _opts[:params].nil? @obj = Object::new if @list[_name][:init_options].nil? then eval("@obj = #{@list[_name][:service]}::new") else eval("@obj = #{@list[_name][:service]}::new(@list[_name][:init_options])") end if dist then @ring_server.start_service({ :name => _opts[:name], :object => @obj, :description => @list[_name][:description], :owner => @name }) @loaded_services[_opts[:name]] = @ring_server.bind_to_service :name => _opts[:name] else @loaded_services[_opts[:name]] = @obj end return @loaded_services[_opts[:name]] end |
#kill_distributed_service(options) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/carioca/private.rb', line 148 def kill_distributed_service() preserve = ([:preserve].nil?)? false : [:preserve] get_ring if @ring_server.nil? if @ring_server.list_services.include?([:name]) then if [:preserve] and @ring_server.list_services[[:name]][:owner] != @name then @log.debug('Carioca') { "Unlinking distributed Service #{options[:name]} owned by #{@name}." } if @log else @ring_server.destroy_service :name => [:name] @log.debug('Carioca') { "Killing distributed Service #{options[:name]}." } if @log end @loaded_services.delete([:name]) shutdown_ring_if_empty return true else @log.debug('Carioca') { "Distributed service #{options[:name]} not in ring" } if @log return false end end |
#kill_service(options) ⇒ Object
call the garbage method of a service if exist and Delete from the loaded services list
141 142 143 144 145 146 |
# File 'lib/carioca/private.rb', line 141 def kill_service() @log.debug('Carioca') { "Service #{options[:name]} stopped" } if @log @loaded_services[[:name]].garbage if @loaded_services[[:name]].respond_to? :garbage @loaded_services.delete([:name]) return true end |
#require_service(_options) ⇒ Object
require file for a service from a service definition in _options
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/carioca/private.rb', line 56 def require_service() _name = [:shortname] sym = ":#{@list[_name][:service].split('::').last}" case @list[_name][:type] when :file then require @list[_name][:resource] when :builtin then _file = Carioca::Services::search_builtins _name if _file then require _file else raise RegistryError::new("Config failed") end when :gem then require @list[_name][:resource] when :gem_file then (_name,_file) = @list[_name][:resource].split(':') _dfile = Carioca::Services::search_file_in_gem _name,_file if _dfile then require _dfile else raise RegistryError::new("Config failed") end else raise RegistryError::new("Config failed") end end |
#scan_instance_suffix(options) ⇒ Object
scan for <service>_<instance> and rewrite options with :name and :shortname, :instance
86 87 88 89 90 91 92 93 |
# File 'lib/carioca/private.rb', line 86 def scan_instance_suffix() if [:name] =~ /.*_.*/ then ([:shortname],[:instance]) = [:name].split(/_/) else [:shortname] = [:name] end return end |
#shutdown_ring_if_empty ⇒ Object
shutdown ring server if empty
96 97 98 99 100 101 102 |
# File 'lib/carioca/private.rb', line 96 def shutdown_ring_if_empty get_ring if @ring_server.nil? if @ring_server.list_services.empty? then @log.debug('Carioca') { "Stopping Ultragreen Ring server if no distributed services found" } @dorsal_controller.stop_ring_server end end |
#verify_requires_dependancies(_options) ⇒ Object
verify dependancies in services structure in @list from a service defition in _options and start it if needed
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/carioca/private.rb', line 41 def verify_requires_dependancies() _name = [:shortname] if @list[_name].include?(:requires) then @list[_name][:requires].each do |service| raise RegistryError::new 'Missing Required depedancy #{service}' unless @list.keys.include? service unless @loaded_services.include?(service) then @log.debug('Carioca') { "Registry dependancy found and not loaded : #{service}" } restart_service :name => service end end end end |