Class: Dorsal::ImplementationServer
- Inherits:
-
Object
- Object
- Dorsal::ImplementationServer
- Includes:
- DRbUndumped, Privates
- Defined in:
- lib/dorsal/implementation.rb
Overview
should NOT be instantiate
this classe is made to be instantiate as a ring server
the Ring Server DRbObject Implementation
Instance Attribute Summary collapse
- #data ⇒ Object readonly
Instance Method Summary collapse
-
#bind_to_service(_options = {}) ⇒ DRbObject?
bind to a service from the ring server.
-
#destroy_service(_options = {}) ⇒ TrueClass, FalseClass
stop a service in the ring.
-
#initialize(_options = {}) ⇒ ImplementationServer
constructor
the contructor of the Ring Server.
-
#list_services ⇒ Hash
list the services from the ring server.
-
#start_service(_options = {}) ⇒ Fixnum, FalseClass
start a service from the ring server.
Methods included from Privates
#daemonize, #start, #status, #stop
Constructor Details
#initialize(_options = {}) ⇒ ImplementationServer
:description (default) ‘Dorsal::DEFAULT_RINGSERVER_DESCRIPTION’
:debug (default) ‘Dorsal::DEFAULT_DEBUG’
:host (default) ‘Dorsal::DEFAULT_HOST’
:port (default) ‘Dorsal::DEFAULT_PORT’
:dir (default) ‘Dorsal::DEFAULT_DIR’
:name (default) ‘Dorsal::DEFAULT_RINGSERVER_NAME’
:uri rule ‘druby://(:host):(:port)’
:pid_file rule ‘(:dir)/(:name).pid’
DO NOT USE DIRECTLY
the contructor of the Ring Server
46 47 48 49 50 51 52 53 54 |
# File 'lib/dorsal/implementation.rb', line 46 def initialize( = {}) @options = Methodic::() @options.specify_defaults_values :name => 'ringserver', :host => 'localhost', :debug => false, :dir => '/tmp/dorsal' @options.merge @data ={} end |
Instance Attribute Details
#data ⇒ Object (readonly)
for debug only
25 26 27 |
# File 'lib/dorsal/implementation.rb', line 25 def data @data end |
Instance Method Details
#bind_to_service(_options = {}) ⇒ DRbObject?
access by Dorsal::Controller::new.bind_to_ring.bind_to_service
bind to a service from the ring server
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/dorsal/implementation.rb', line 116 def bind_to_service( = {}) = Methodic::() .specify_presences_of :name .validate if list_services.include?([:name]) then DRb.start_service return DRbObject.new nil, @data[[:name]][:uri] else return nil end end |
#destroy_service(_options = {}) ⇒ TrueClass, FalseClass
access by Dorsal::Controller::new.bind_to_ring.destroy_service
stop a service in the ring
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/dorsal/implementation.rb', line 92 def destroy_service( = {}) = Methodic::() .specify_presences_of :name .validate if @data.include? [:name] then [:pid_file] = @data[[:name]][:pid_file] [:description] = @data[[:name]][:description] if stop() then @data.delete([:name]) return true end return false end return false end |
#list_services ⇒ Hash
access by Dorsal::Controller::new.bind_to_ring.list_services
list the services from the ring server
133 134 135 |
# File 'lib/dorsal/implementation.rb', line 133 def list_services return @data end |
#start_service(_options = {}) ⇒ Fixnum, FalseClass
access by Dorsal::Controller::new.bind_to_ring.start_service
start a service from the ring server
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/dorsal/implementation.rb', line 66 def start_service( = {}) = Methodic::() .specify_presences_of :name, :description, :object .validate unless @data.include?([:name]) then [:pid_file] = "#{@options[:dir]}/service-#{[:name]}.pid" [:uri] = "druby://#{@options[:host]}:#{get_free_port(40000,50000)}" @data[[:name]] = { :description => [:description] , :pid_file => [:pid_file], :uri => [:uri] } return start() do require 'drb' [:object].extend DRb::DRbUndumped DRb.start_service([:uri], [:object]) DRb.thread.join end else return false end end |