carioca 1.3 → 1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/ChangeLog +4 -1
- data/Rakefile +13 -6
- data/carioca.gemspec +20 -21
- data/lib/carioca.rb +53 -53
- data/lib/carioca/exceptions.rb +1 -1
- data/lib/carioca/helpers.rb +3 -3
- data/lib/carioca/private.rb +24 -26
- data/lib/carioca/services.rb +10 -10
- data/lib/carioca/services/configuration.rb +31 -29
- data/lib/carioca/services/debug.rb +8 -10
- data/lib/carioca/services/logger.rb +13 -13
- data/lib/carioca/tasks/rake.rb +3 -3
- data/lib/carioca/tasks/registry_init.rake +2 -1
- data/spec/carioca_spec.rb +72 -78
- data/spec/config/.config +14 -0
- data/spec/init_spec.rb +1 -0
- data/spec/samples/dummy.rb +1 -0
- data/spec/samples/otherdummy.rb +1 -0
- data/spec/samples/requireddummy.rb +1 -0
- data/spec/spec_helper.rb +1 -1
- metadata +49 -72
- data/Gemfile.lock +0 -54
- data/test.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9be0e1efee67cbc15309f5eb56a72208681b14d84c3c1f3666474c28798c1c51
|
4
|
+
data.tar.gz: 66033e08a911cd0b537eb7ca1114a8aca2d445f8cae79e9d04e62190e27d0a0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85c41d310a6ad5f7704b2f244a1616160569dd389939c4ed389b08d81520f15f1c304e5ece750e29205043544bcca886ad39a6925be24c941044acaf5a3c8cbd
|
7
|
+
data.tar.gz: 95cdb63add808821f358742e1fbd6ef611ebc49f062901405ec37cc972dcf7c8695a88583f16685b020df3f08485c8bc1dec83d2868c44641a67fd53c5c0ecef
|
data/ChangeLog
CHANGED
data/Rakefile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
|
2
|
+
require "bundler/gem_tasks"
|
3
3
|
require 'rspec'
|
4
4
|
require 'rake'
|
5
5
|
require "rake/clean"
|
@@ -11,8 +11,9 @@ require 'yard/rake/yardoc_task.rb'
|
|
11
11
|
require "rake/tasklib"
|
12
12
|
require "roodi"
|
13
13
|
require "roodi_task"
|
14
|
-
|
15
|
-
|
14
|
+
require 'code_statistics'
|
15
|
+
|
16
|
+
|
16
17
|
RoodiTask.new() do | t |
|
17
18
|
t.patterns = %w(lib/**/*.rb)
|
18
19
|
t.config = "ultragreen_roodi_coding_convention.yml"
|
@@ -31,12 +32,12 @@ RSpec::Core::RakeTask.new('spec')
|
|
31
32
|
|
32
33
|
|
33
34
|
YARD::Rake::YardocTask.new do |t|
|
34
|
-
t.files = [ 'lib/**/*.rb', '-', 'doc/**/*','spec/**/*_spec.rb']
|
35
|
+
t.files = [ 'lib/**/*.rb', '-', 'doc/**/*','spec/**/*_spec.rb']
|
35
36
|
t.options += ['--title', "Gem Documentation"]
|
36
37
|
t.options += ['-o', "yardoc"]
|
37
38
|
t.options += ['-r', "doc/manual.rdoc"]
|
38
39
|
end
|
39
|
-
YARD::Config.load_plugin('yard-rspec')
|
40
|
+
YARD::Config.load_plugin('yard-rspec')
|
40
41
|
|
41
42
|
namespace :yardoc do
|
42
43
|
task :clobber do
|
@@ -59,4 +60,10 @@ Rake::RDocTask.new('rdoc') do |d|
|
|
59
60
|
d.options << '--line-numbers' << '--diagram' << '-SHN'
|
60
61
|
end
|
61
62
|
|
62
|
-
task :default => [:gem]
|
63
|
+
task :default => [:gem]
|
64
|
+
|
65
|
+
task :stage do
|
66
|
+
Rake::Task["clean"].invoke
|
67
|
+
Rake::Task["clobber"].invoke
|
68
|
+
Rake::Task["install"].invoke
|
69
|
+
end
|
data/carioca.gemspec
CHANGED
@@ -1,33 +1,32 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{carioca}
|
3
3
|
s.author = "Romain GEORGES"
|
4
|
-
s.version = "1.
|
5
|
-
s.license = "BSD-2"
|
6
|
-
s.date = %q{2013-02-18}
|
4
|
+
s.version = "1.4"
|
5
|
+
s.license = "BSD-2-Clause"
|
7
6
|
s.summary = %q{Carioca : Configuration Agent and Registry with Inversion Of Control for your Applications}
|
8
7
|
s.email = %q{romain@ultragreen.net}
|
9
|
-
s.homepage = %q{
|
8
|
+
s.homepage = %q{https://github.com/Ultragreen/carioca}
|
10
9
|
s.description = %q{Carioca : provide a full IoC light Container for designing your applications}
|
11
|
-
s.
|
12
|
-
|
13
|
-
|
14
|
-
s.add_development_dependency "
|
15
|
-
s.add_development_dependency
|
16
|
-
s.add_development_dependency '
|
17
|
-
s.add_development_dependency '
|
18
|
-
s.add_development_dependency '
|
19
|
-
s.add_development_dependency '
|
20
|
-
s.add_development_dependency 'code_statistics', '~> 0.2', '>= 0.2.13'
|
10
|
+
s.files = `git ls-files`.split($/)
|
11
|
+
|
12
|
+
|
13
|
+
s.add_development_dependency "rake", "~> 13.0.1"
|
14
|
+
s.add_development_dependency 'rspec', '~> 3.9.0'
|
15
|
+
s.add_development_dependency 'yard', '~> 0.9.24'
|
16
|
+
s.add_development_dependency 'rdoc', '~> 6.2.1'
|
17
|
+
s.add_development_dependency 'roodi', '~> 5.0.0'
|
18
|
+
s.add_development_dependency 'code_statistics', '~> 0.2.13'
|
21
19
|
s.add_development_dependency 'yard-rspec', '~> 0.1'
|
22
20
|
|
23
|
-
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
s.add_dependency 'xml-simple', "~> 1.1", '>= 1.1.5'
|
22
|
+
s.add_development_dependency 'uuid', '~> 2.3.9'
|
23
|
+
|
28
24
|
|
25
|
+
|
26
|
+
s.add_dependency 'dorsal', "~> 1.0"
|
27
|
+
s.add_dependency 'methodic', "~> 1.3", '>= 1.3'
|
28
|
+
s.add_dependency 'xml-simple', "~> 1.1", '>= 1.1.5'
|
29
|
+
s.add_dependency 'activesupport', "~> 6.0.2.2"
|
29
30
|
s.required_ruby_version = '>= 1.8.1'
|
30
|
-
|
31
|
-
# << '--diagram'
|
32
|
-
s.rubyforge_project = "nowarning"
|
31
|
+
|
33
32
|
end
|
data/lib/carioca.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
#!/usr/bin/env ruby
|
3
|
-
#
|
3
|
+
# coding: utf-8
|
4
4
|
#---
|
5
5
|
# Author : Romain GEORGES
|
6
6
|
# type : gem component library
|
@@ -23,27 +23,27 @@ require 'carioca/private'
|
|
23
23
|
module Carioca
|
24
24
|
|
25
25
|
|
26
|
-
|
26
|
+
|
27
27
|
# module Services
|
28
|
-
# @note this module is a namespace Carioca::Services
|
28
|
+
# @note this module is a namespace Carioca::Services
|
29
29
|
module Services
|
30
|
-
|
31
|
-
|
30
|
+
|
31
|
+
|
32
32
|
# class Registry
|
33
33
|
# This class provide the Registry manager for Carioca
|
34
34
|
# @note this class is a Singleton Class to instanciate do not use new (initializer), but :
|
35
|
-
# Carioca::Services::Registry.init options
|
36
|
-
# @example Complete usage
|
35
|
+
# Carioca::Services::Registry.init options
|
36
|
+
# @example Complete usage
|
37
37
|
# require 'rubygems'
|
38
|
-
# require 'carioca'
|
39
|
-
# registry = Carioca::Services::Registry.init
|
38
|
+
# require 'carioca'
|
39
|
+
# registry = Carioca::Services::Registry.init
|
40
40
|
# registry = Carioca::Services::Registry.init :file => 'myservices.registry'
|
41
41
|
# registry = Carioca::Services::Registry.init :file => 'myservices.registry', :debug => true
|
42
42
|
class Registry
|
43
43
|
|
44
44
|
include PrivateMethodsCariocaServicesRegistry
|
45
|
-
|
46
|
-
# for singleton
|
45
|
+
|
46
|
+
# for singleton
|
47
47
|
private_class_method :new
|
48
48
|
private :verify_requires_dependancies
|
49
49
|
private :require_service
|
@@ -52,17 +52,17 @@ module Carioca
|
|
52
52
|
private :scan_instance_suffix
|
53
53
|
private :kill_distributed_service
|
54
54
|
private :shutdown_ring_if_empty
|
55
|
-
|
56
|
-
|
55
|
+
|
56
|
+
|
57
57
|
@@inst = nil
|
58
|
-
|
58
|
+
|
59
59
|
# Singleton constructor for Registry
|
60
60
|
# @param [Hash] _options the options, keys are symbols
|
61
61
|
# @option _options [String] :file The path of your registry YAML definition (see YAML registry format)
|
62
|
-
# @option _options [TrueClass,FalseClass] :debug Boolean activation/deactiviation of the carioca debug mode (log traces)
|
62
|
+
# @option _options [TrueClass,FalseClass] :debug Boolean activation/deactiviation of the carioca debug mode (log traces)
|
63
63
|
# @return [Carioca::Services::Registry] Singleton class instance of Registry
|
64
64
|
# @example usage
|
65
|
-
# registry = Carioca::Services::Registry.init # or
|
65
|
+
# registry = Carioca::Services::Registry.init # or
|
66
66
|
# registry = Carioca::Services::Registry.init :file => 'myservices.registry' # or
|
67
67
|
# registry = Carioca::Services::Registry.init :file => 'myservices.registry', :debug => true
|
68
68
|
def Registry.init(_options = {})
|
@@ -72,52 +72,52 @@ module Carioca
|
|
72
72
|
@@inst = new(options) if @@inst.nil?
|
73
73
|
return @@inst
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
# @example read
|
77
77
|
# registry = Carioca::Services::Registry.init
|
78
78
|
# p registry.registry_filename
|
79
79
|
# @example write
|
80
80
|
# registry = Carioca::Services::Registry.init
|
81
81
|
# p registry.registry_filename = '/tmp/test.file'
|
82
|
-
# @attr_reader [Hash] list a hash table of all structured registred services definition
|
82
|
+
# @attr_reader [Hash] list a hash table of all structured registred services definition
|
83
83
|
# (come from file and explicitly registered services)
|
84
84
|
attr_accessor :registry_filename
|
85
|
-
|
86
|
-
# @example
|
85
|
+
|
86
|
+
# @example
|
87
87
|
# registry = Carioca::Services::Registry.init
|
88
88
|
# p registry.list
|
89
|
-
# @attr_reader [Hash] list a hash table of all structured registred services definition
|
89
|
+
# @attr_reader [Hash] list a hash table of all structured registred services definition
|
90
90
|
# (come from file and explicitly registered services)
|
91
91
|
attr_reader :list
|
92
92
|
|
93
|
-
# @example
|
93
|
+
# @example
|
94
94
|
# registry = Carioca::Services::Registry.init
|
95
95
|
# p registry.loaded_services # you should see the logger service Hash definition
|
96
|
-
# @attr_reader [Hash] loaded_services a hash table of all structured loaded services
|
96
|
+
# @attr_reader [Hash] loaded_services a hash table of all structured loaded services
|
97
97
|
attr_reader :loaded_services
|
98
98
|
|
99
|
-
# @example
|
99
|
+
# @example
|
100
100
|
# registry = Carioca::Services::Registry.init
|
101
101
|
# p registry.debug
|
102
102
|
# @attr_reader [TrueClass,FalseClass] debug a boolean of the current debug status
|
103
103
|
attr_reader :debug
|
104
104
|
|
105
|
-
# @example
|
105
|
+
# @example
|
106
106
|
# registry = Carioca::Services::Registry.init
|
107
107
|
# p registry.name
|
108
108
|
# registry.name = 'Agent'
|
109
109
|
# @attr_reader [String] the name of the Registry, used for distributed services
|
110
110
|
# @note default value is 'Carioca'
|
111
111
|
attr_accessor :name
|
112
|
-
|
112
|
+
|
113
113
|
# writer accessor for debug (interaction with log service)
|
114
|
-
# @example
|
114
|
+
# @example
|
115
115
|
# registry = Carioca::Services::Registry.init
|
116
116
|
# p registry.debug = true
|
117
|
-
# @param [TrueClass,FalseClass] _value true or false to activate/deactivate debug mode
|
117
|
+
# @param [TrueClass,FalseClass] _value true or false to activate/deactivate debug mode
|
118
118
|
# @note interaction with preloaded service logger
|
119
119
|
def debug=(_value)
|
120
|
-
@log.level =(_value)? Logger::DEBUG : Logger::INFO
|
120
|
+
@log.level =(_value)? Logger::DEBUG : Logger::INFO
|
121
121
|
end
|
122
122
|
|
123
123
|
|
@@ -126,7 +126,7 @@ module Carioca
|
|
126
126
|
# @option _options [String] :name The name of the service to stop
|
127
127
|
# @return [TruaClass,FalseClass] true if service effectivly stopped, false if not, or :name == 'logger'
|
128
128
|
# @example usage
|
129
|
-
# registry = Carioca::Services::Registry.init
|
129
|
+
# registry = Carioca::Services::Registry.init
|
130
130
|
# registry.start_service :name => 'configuration'
|
131
131
|
# registry.stop_service :name => 'configuration'
|
132
132
|
# #=> return true
|
@@ -142,23 +142,23 @@ module Carioca
|
|
142
142
|
options.validate!
|
143
143
|
@log.debug('Carioca') { "Service logger can't be unloaded" } if @log and options[:name] == 'logger'
|
144
144
|
return false if options[:name] == 'logger'
|
145
|
-
if @loaded_services.include?(options[:name]) then
|
145
|
+
if @loaded_services.include?(options[:name]) then
|
146
146
|
options = scan_instance_suffix(options)
|
147
147
|
return kill_distributed_service options if @list[options[:shortname]][:distributed]
|
148
148
|
return kill_service options
|
149
149
|
else
|
150
150
|
@log.debug('Carioca') { "Service #{options[:name]} not loaded" } if @log
|
151
|
-
return false
|
151
|
+
return false
|
152
152
|
end
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
|
156
156
|
# register a new service in registry added to @list
|
157
157
|
# @param [Hash] _options the options hash, key are :symbols
|
158
158
|
# @option _options [String] :name the name of the service (required)
|
159
159
|
# @option _options [String] :resource the resource, must be a gem name, a fullpath filename, a builtin service (required)
|
160
160
|
# @option _options [Symbol] :type the resource type of the service, must be :gem, :builtin or :file (required)
|
161
|
-
# @option _options [String] :service the realname of the service class with namespace (eg. ExternalServices::Dummy )
|
161
|
+
# @option _options [String] :service the realname of the service class with namespace (eg. ExternalServices::Dummy )
|
162
162
|
# @option _options [String] :description the description of the service (required)
|
163
163
|
# @option _options [Hash] :init_options the params of the service, keys are symbols
|
164
164
|
# @option _options [Array] :requires the list of [String] services name required to load this service
|
@@ -167,7 +167,7 @@ module Carioca
|
|
167
167
|
# @raise ArgumentError when :type is not in [:gem,:file,:builtin]
|
168
168
|
def register_service(_options)
|
169
169
|
options = Methodic.get_options(_options)
|
170
|
-
options.specify_classes_of({:name => String, :resource => String, :description => String, :type => Symbol, :service => String })
|
170
|
+
options.specify_classes_of({:name => String, :resource => String, :description => String, :type => Symbol, :service => String })
|
171
171
|
options.specify_presences_of([:name,:type,:resource,:service])
|
172
172
|
cond = Proc::new{|option| if [:gem,:gem_file,:file,:builtin].include? option then true else false end }
|
173
173
|
options.specify_condition_for :type => cond
|
@@ -193,7 +193,7 @@ module Carioca
|
|
193
193
|
@list.delete(options[:name])
|
194
194
|
return true
|
195
195
|
end
|
196
|
-
|
196
|
+
|
197
197
|
# overload @list (self.list) by adding/reloading the builtins services definition scanned from Carioca gem
|
198
198
|
# alterate @list
|
199
199
|
# @example usage
|
@@ -203,11 +203,11 @@ module Carioca
|
|
203
203
|
def discover_builtins
|
204
204
|
@list.merge! Carioca::Services::discover_builtins
|
205
205
|
end
|
206
|
-
|
206
|
+
|
207
207
|
# save the registry file in self.registry_filename
|
208
208
|
# @return [TruaClass,FalseClass] true if the file is saved
|
209
209
|
# @example usage
|
210
|
-
# registry = Carioca::Services::Registry.init :file => './empty.file'
|
210
|
+
# registry = Carioca::Services::Registry.init :file => './empty.file'
|
211
211
|
# registry.discover_builtins
|
212
212
|
# registry.unregister_service :name => 'configuration'
|
213
213
|
# registry.save!
|
@@ -218,15 +218,15 @@ module Carioca
|
|
218
218
|
end
|
219
219
|
return res
|
220
220
|
end
|
221
|
-
|
221
|
+
|
222
222
|
# start or get e previously started service in @list
|
223
223
|
# @return [Object] the loaded service class instance
|
224
224
|
# @param [Hash] _options the params, key are symbols
|
225
225
|
# @option _options [String] :name the name of the service
|
226
226
|
# @option _options [Hash] :params the params of the service
|
227
227
|
# @raise [RegistryError] Config Failed, for unconsistant service definition in @list
|
228
|
-
# @example usage
|
229
|
-
# registry = Carioca::Services::Registry.init
|
228
|
+
# @example usage
|
229
|
+
# registry = Carioca::Services::Registry.init
|
230
230
|
# config = registry.start_service :name => 'configuration'
|
231
231
|
# proxy = subject.start_service :name => 'debug' , :params => {:service => 'configuration'}
|
232
232
|
def start_service(_options)
|
@@ -235,7 +235,7 @@ module Carioca
|
|
235
235
|
options.specify_presences_of([:name])
|
236
236
|
options.validate!
|
237
237
|
@log.debug('Carioca') { "getting service #{options[:name]}"} if @log
|
238
|
-
self.restart_service(options) unless @loaded_services.include? options[:name]
|
238
|
+
self.restart_service(options) unless @loaded_services.include? options[:name]
|
239
239
|
return @loaded_services[options[:name]]
|
240
240
|
end
|
241
241
|
alias :get_service :start_service
|
@@ -246,8 +246,8 @@ module Carioca
|
|
246
246
|
# @option _options [String] :name the name of the service
|
247
247
|
# @option _options [Hash] :params the params of the service
|
248
248
|
# @raise [RegistryError] Config Failed, for unconsistant service definition in @list
|
249
|
-
# @example usage
|
250
|
-
# registry = Carioca::Services::Registry.init
|
249
|
+
# @example usage
|
250
|
+
# registry = Carioca::Services::Registry.init
|
251
251
|
# config = registry.restart_service :name => 'configuration'
|
252
252
|
# config = registry.restart_service :name => 'configuration' # stop and restart the previous services
|
253
253
|
# proxy = subject.restart_service :name => 'debug' , :params => {:service => 'configuration'}
|
@@ -264,17 +264,17 @@ module Carioca
|
|
264
264
|
kill_distributed_service options
|
265
265
|
elsif @loaded_services.include? options[:name] then
|
266
266
|
@log.debug('Carioca') { "Restarting service #{options[:name]}"} if @log
|
267
|
-
kill_service options
|
268
|
-
end
|
267
|
+
kill_service options
|
268
|
+
end
|
269
269
|
verify_requires_dependancies(options)
|
270
270
|
require_service(options)
|
271
271
|
return instanciate_service(options)
|
272
272
|
end
|
273
|
-
|
273
|
+
|
274
274
|
# close the registry (finalizer)
|
275
|
-
# * stop all the services
|
275
|
+
# * stop all the services
|
276
276
|
# * kill logger
|
277
|
-
# * call private kill_service for each
|
277
|
+
# * call private kill_service for each
|
278
278
|
# @note the garbage method hook is call if defined, for each service
|
279
279
|
# @return [TrueClass,FalseClass] true if registry closed successfully
|
280
280
|
def close
|
@@ -283,7 +283,7 @@ module Carioca
|
|
283
283
|
@loaded_services.keys.each do |service|
|
284
284
|
options[:name] = service
|
285
285
|
options = scan_instance_suffix(options)
|
286
|
-
next if options[:name] == 'logger'
|
286
|
+
next if options[:name] == 'logger'
|
287
287
|
kill_distributed_service :name => options[:name], :preserve => true if @list[options[:shortname]][:distributed]
|
288
288
|
kill_service options unless @list[options[:shortname]][:distributed]
|
289
289
|
end
|
@@ -293,7 +293,7 @@ module Carioca
|
|
293
293
|
end
|
294
294
|
|
295
295
|
# load the registry file from self.registry_filename
|
296
|
-
# @return [Hash] @list the list Structure of the loaded registry
|
296
|
+
# @return [Hash] @list the list Structure of the loaded registry
|
297
297
|
# @example usage
|
298
298
|
# registry = Carioca::Services::Registry.init
|
299
299
|
# registry.registry_filename = "./an_other.file"
|
@@ -303,12 +303,12 @@ module Carioca
|
|
303
303
|
@list = YAML.load_file(@registry_filename)
|
304
304
|
end
|
305
305
|
alias :reload :load
|
306
|
-
|
306
|
+
|
307
307
|
end # end of Carioca::Services::Registry
|
308
308
|
end # end of Carioca:Services
|
309
309
|
end # end of Carioca
|
310
310
|
|
311
|
-
# Exception overload class for Carioca
|
311
|
+
# Exception overload class for Carioca
|
312
312
|
class RegistryError < Exception; end
|
313
313
|
|
314
314
|
|
data/lib/carioca/exceptions.rb
CHANGED
data/lib/carioca/helpers.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# coding: utf-8
|
2
2
|
#---
|
3
3
|
# Author : Romain GEORGES
|
4
4
|
# type : gem component library
|
@@ -15,7 +15,7 @@ class Class
|
|
15
15
|
def use_configuration(_options = {})
|
16
16
|
options = Methodic.get_options(_options)
|
17
17
|
options.specify_classes_of :with_file => String
|
18
|
-
options.
|
18
|
+
options.specify_default_value_for :with_file => 'services/registry.yml'
|
19
19
|
options.merge
|
20
20
|
options.validate!
|
21
21
|
Carioca::Services::Registry.init.start_service :name => 'configuration', :params => { :config_file => options[:with_file]}
|
@@ -27,7 +27,7 @@ Module.class_eval do
|
|
27
27
|
def init_registry _options={}
|
28
28
|
options = Methodic.get_options(_options)
|
29
29
|
options.specify_classes_of :with_file => String
|
30
|
-
options.
|
30
|
+
options.specify_default_value_for :with_file => 'services/registry.yml'
|
31
31
|
options.merge
|
32
32
|
options.validate!
|
33
33
|
Carioca::Services::Registry.init :file => options[:with_file]
|
data/lib/carioca/private.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# coding: utf-8
|
2
2
|
#---
|
3
3
|
# Author : Romain GEORGES
|
4
4
|
# type : gem component library
|
@@ -19,24 +19,24 @@ module PrivateMethodsCariocaServicesRegistry
|
|
19
19
|
@list = Hash::new
|
20
20
|
load if File::exist?(@registry_filename)
|
21
21
|
unless @list.include?('logger') then
|
22
|
-
self.register_service({:name => 'logger',
|
22
|
+
self.register_service({:name => 'logger',
|
23
23
|
:service => 'Carioca::Services::InternalLogger',
|
24
|
-
:resource => 'logger',
|
25
|
-
:description => "The standard ruby Logger internal wrapper Service",
|
26
|
-
:type => :builtin,
|
24
|
+
:resource => 'logger',
|
25
|
+
:description => "The standard ruby Logger internal wrapper Service",
|
26
|
+
:type => :builtin,
|
27
27
|
:init_options => { :target => "/tmp/log.file"}})
|
28
28
|
@logger_not_in_reg = true
|
29
|
-
end
|
29
|
+
end
|
30
30
|
@loaded_services = Hash::new
|
31
31
|
# preload logger service
|
32
|
-
@log = self.start_service :name => 'logger'
|
33
|
-
@log.level =(@debug)? Logger::DEBUG : Logger::INFO
|
32
|
+
@log = self.start_service :name => 'logger'
|
33
|
+
@log.level =(@debug)? Logger::DEBUG : Logger::INFO
|
34
34
|
@log.debug('Carioca') { "Registry started, service logger preloaded" }
|
35
35
|
@log.debug('Carioca') { "Logger registered, not in configured registry" } if @logger_not_in_reg
|
36
36
|
end
|
37
|
-
|
38
|
-
# verify dependancies in services structure
|
39
|
-
# in @list from a service defition
|
37
|
+
|
38
|
+
# verify dependancies in services structure
|
39
|
+
# in @list from a service defition
|
40
40
|
# in _options and start it if needed
|
41
41
|
def verify_requires_dependancies(_options)
|
42
42
|
_name = _options[:shortname]
|
@@ -45,18 +45,18 @@ module PrivateMethodsCariocaServicesRegistry
|
|
45
45
|
raise RegistryError::new 'Missing Required depedancy #{service}' unless @list.keys.include? service
|
46
46
|
unless @loaded_services.include?(service) then
|
47
47
|
@log.debug('Carioca') { "Registry dependancy found and not loaded : #{service}" }
|
48
|
-
restart_service :name => service
|
48
|
+
restart_service :name => service
|
49
49
|
end
|
50
50
|
end
|
51
|
-
end
|
51
|
+
end
|
52
52
|
end
|
53
|
-
|
54
|
-
# require file for a service
|
53
|
+
|
54
|
+
# require file for a service
|
55
55
|
# from a service definition in _options
|
56
56
|
def require_service(_options)
|
57
57
|
_name = _options[:shortname]
|
58
58
|
sym = ":#{@list[_name][:service].split('::').last}"
|
59
|
-
case @list[_name][:type]
|
59
|
+
case @list[_name][:type]
|
60
60
|
when :file then
|
61
61
|
require @list[_name][:resource]
|
62
62
|
when :builtin then
|
@@ -67,7 +67,7 @@ module PrivateMethodsCariocaServicesRegistry
|
|
67
67
|
raise RegistryError::new("Config failed")
|
68
68
|
end
|
69
69
|
when :gem then
|
70
|
-
require @list[_name][:resource]
|
70
|
+
require @list[_name][:resource]
|
71
71
|
when :gem_file then
|
72
72
|
(_name,_file) = @list[_name][:resource].split(':')
|
73
73
|
_dfile = Carioca::Services::search_file_in_gem _name,_file
|
@@ -76,7 +76,7 @@ module PrivateMethodsCariocaServicesRegistry
|
|
76
76
|
else
|
77
77
|
raise RegistryError::new("Config failed")
|
78
78
|
end
|
79
|
-
else
|
79
|
+
else
|
80
80
|
raise RegistryError::new("Config failed")
|
81
81
|
end
|
82
82
|
end
|
@@ -91,7 +91,7 @@ module PrivateMethodsCariocaServicesRegistry
|
|
91
91
|
end
|
92
92
|
return options
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
#shutdown ring server if empty
|
96
96
|
def shutdown_ring_if_empty
|
97
97
|
get_ring if @ring_server.nil?
|
@@ -114,7 +114,7 @@ module PrivateMethodsCariocaServicesRegistry
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
-
# instanciate Object from class defintion of a service defined in
|
117
|
+
# instanciate Object from class defintion of a service defined in
|
118
118
|
# the service definition in _opts
|
119
119
|
def instanciate_service(_opts)
|
120
120
|
_name = _opts[:shortname]
|
@@ -122,7 +122,7 @@ module PrivateMethodsCariocaServicesRegistry
|
|
122
122
|
get_ring if dist
|
123
123
|
@list[_name][:init_options].merge! _opts[:params] unless _opts[:params].nil?
|
124
124
|
@obj = Object::new
|
125
|
-
if @list[_name][:init_options].nil? then
|
125
|
+
if @list[_name][:init_options].nil? then
|
126
126
|
eval("@obj = #{@list[_name][:service]}::new")
|
127
127
|
else
|
128
128
|
eval("@obj = #{@list[_name][:service]}::new(@list[_name][:init_options])")
|
@@ -135,8 +135,8 @@ module PrivateMethodsCariocaServicesRegistry
|
|
135
135
|
end
|
136
136
|
return @loaded_services[_opts[:name]]
|
137
137
|
end
|
138
|
-
|
139
|
-
# call the garbage method of a service if exist and
|
138
|
+
|
139
|
+
# call the garbage method of a service if exist and
|
140
140
|
# Delete from the loaded services list
|
141
141
|
def kill_service(options)
|
142
142
|
@log.debug('Carioca') { "Service #{options[:name]} stopped" } if @log
|
@@ -146,7 +146,7 @@ module PrivateMethodsCariocaServicesRegistry
|
|
146
146
|
end
|
147
147
|
|
148
148
|
def kill_distributed_service(options)
|
149
|
-
preserve = (options[:preserve].nil?)? false : options[:preserve]
|
149
|
+
preserve = (options[:preserve].nil?)? false : options[:preserve]
|
150
150
|
get_ring if @ring_server.nil?
|
151
151
|
if @ring_server.list_services.include?(options[:name]) then
|
152
152
|
if options[:preserve] and @ring_server.list_services[options[:name]][:owner] != @name then
|
@@ -166,5 +166,3 @@ module PrivateMethodsCariocaServicesRegistry
|
|
166
166
|
|
167
167
|
|
168
168
|
end # end of PrivateMethodsCariocaServicesRegistry
|
169
|
-
|
170
|
-
|