Class: Orbjson::System
- Inherits:
-
Object
- Object
- Orbjson::System
- Defined in:
- lib/orbjson.rb
Overview
The System class holds the core broker methods. It is reponsible for registering server-side classes, sending a list of available services to the client, and connecting JSON-RPC requests with registered services
The System object is initialized by calling init
and passing in a mapping of files and classes implementing services.
Constant Summary collapse
- @@registry =
Needle::Registry.new()
Class Method Summary collapse
-
.get_object(klass, *args) ⇒ Object
Returns an object stored in the registry.
-
.init(cfg, flush = true) ⇒ Object
You can configure the Orbjson services list in a few ways, passing detials into the init method.
-
.list_methods ⇒ Object
Returns a list of registerd services.
-
.put_object(klass, instance) ⇒ Object
Adds an object to the registry.
-
.registered_classses ⇒ Object
Returns a list of registered service classes.
Instance Method Summary collapse
-
#listMethods ⇒ Object
Returns a list of registerd services.
Class Method Details
.get_object(klass, *args) ⇒ Object
Returns an object stored in the registry
36 37 38 |
# File 'lib/orbjson.rb', line 36 def self.get_object( klass, *args ) return @@registry[ klass.intern ] end |
.init(cfg, flush = true) ⇒ Object
You can configure the Orbjson services list in a few ways, passing detials into the init method.
Well, three, really:
1. Pass in a path to a local YAML file; the path must begin with
'file://'
For example: cfg = 'file://config.yaml'
System.init( cfg )
2. Pass in some YAML:
cfg = 'services/sample:
- Details'
System.init( cfg )
3. Pass in some an actual Hash object:
cfg = { 'services/sample' => ['Details'] }
System.init( cfg )
The hash (however you express it) consists of 'require' paths mapped
to arrays of classes to instantiate.
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 137 138 139 |
# File 'lib/orbjson.rb', line 109 def self.init( cfg, flush = true ) @@registry = Needle::Registry.new() if flush STDERR.puts( "cfg starts as #{cfg}") case cfg.class.to_s when 'String' if cfg =~ /^file:\/\// cfg.gsub!( /^file:\/\//, '' ) STDERR.puts( "cfg is now #{cfg}") config_hash = YAML::load( File.open( cfg ) ) else STDERR.puts( "cfg is #{cfg}") config_hash = YAML::load( cfg ) end when 'Hash' config_hash = cfg else raise "init was given unusable configuration data [ #{cfg.class}]: #{$!}" end config_hash.each do |src_file, class_list| require src_file class_list.each do |klass| @@registry.register( klass ) { new_from_name( klass ) } end end @@registry.register( :System ) { System.new } @@registry.register( :system ) { System.new } $roy_logger.debug( "@@registry now has \n" + @@registry.keys.inspect ) end |
.list_methods ⇒ Object
Returns a list of registerd services.
The format of each listed service name is className.method
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/orbjson.rb', line 65 def self.list_methods mlist = [] System.registered_classses.each do |cls| name = String.new( cls ) name[0] = name[0].chr.downcase begin $roy_logger.debug( "[#{__LINE__}] System#list_methods has cls #{cls}" ) klass = eval( cls ) ( klass.public_instance_methods - Object.methods ).sort.each { |m| $roy_logger.debug( "[#{__LINE__}] System#list_methods adding #{name}.#{m}" ) mlist << "#{name}.#{m}" } rescue Exception STDERR.puts( "[#{__LINE__}] System#list_methods error #{$!}" ) $roy_logger.error( "[#{__LINE__}] System#list_methods error #{$!}" ) end end $roy_logger.debug( "[#{__LINE__}] System#list_methods returning #{mlist.inspect}" ) mlist end |
.put_object(klass, instance) ⇒ Object
Adds an object to the registry
41 42 43 |
# File 'lib/orbjson.rb', line 41 def self.put_object( klass, instance ) @@registry.register( klass ) { instance } end |
.registered_classses ⇒ Object
Returns a list of registered service classes.
46 47 48 49 50 51 52 53 |
# File 'lib/orbjson.rb', line 46 def self.registered_classses @@registry.keys.map{ |k| $roy_logger.debug( "[#{__LINE__}] self.registered_classses has @@registry[k].to_s #{@@registry[k].to_s}" ) cls = @@registry[k].class.to_s ( cls =~ /Needle::/ || cls =~ /^Hash$/ || cls =~ /^[a-z]/ ) ? nil : @@registry[k].class.to_s }.compact end |
Instance Method Details
#listMethods ⇒ Object
Returns a list of registerd services. Wraps a call to System.list_methods. The format of each listed service name is className.method It was added as a conveience for client code that uses the archaic camelCase method naming convention found in 2oth C. programming languages
59 60 61 |
# File 'lib/orbjson.rb', line 59 def listMethods System.list_methods end |