class Discover::Client
Public Class Methods
new(address = nil)
click to toggle source
# File lib/discover.rb, line 8 def initialize(address = nil) uri = parse(address || ENV["DISCOVERD"] || "127.0.0.1:1111") @client = RPCPlus::Client.new(uri.host, uri.port) @registrations = [] end
Public Instance Methods
register(name, port=nil, ip=nil, attributes={})
click to toggle source
# File lib/discover.rb, line 23 def register(name, port=nil, ip=nil, attributes={}) _register(name, port, ip, attributes, false) end
register_and_standby(name, port=nil, ip=nil, attributes={})
click to toggle source
# File lib/discover.rb, line 27 def register_and_standby(name, port=nil, ip=nil, attributes={}) _register(name, port, ip, attributes, true) end
remove_registration(reg)
click to toggle source
# File lib/discover.rb, line 31 def remove_registration(reg) @registrations.delete(reg) end
request(*args, &block)
click to toggle source
# File lib/discover.rb, line 15 def request(*args, &block) @client.request(*args, &block) end
service(name, filters={})
click to toggle source
# File lib/discover.rb, line 19 def service(name, filters={}) Service.new(self, name, filters) end
unregister_all()
click to toggle source
# File lib/discover.rb, line 35 def unregister_all @registrations.each(&:unregister) end
Private Instance Methods
_register(name, port=nil, ip=nil, attributes={}, standby=false)
click to toggle source
# File lib/discover.rb, line 46 def _register(name, port=nil, ip=nil, attributes={}, standby=false) reg = Registration.new(self, name, "#{ip}:#{port}", attributes, standby) @registrations << reg reg.register reg end
parse(address)
click to toggle source
# File lib/discover.rb, line 40 def parse(address) URI.parse(address) rescue URI::InvalidURIError URI.parse("tcp://#{address}") end