Class: Archipelago::Client::Base
- Inherits:
-
Object
- Object
- Archipelago::Client::Base
- Includes:
- Disco::Camel
- Defined in:
- lib/archipelago/client.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#debug_callable ⇒ Object
Returns the value of attribute debug_callable.
-
#jockey ⇒ Object
readonly
Returns the value of attribute jockey.
-
#service_descriptions ⇒ Object
readonly
Returns the value of attribute service_descriptions.
-
#services ⇒ Object
readonly
Returns the value of attribute services.
Instance Method Summary collapse
-
#around_update_services(&block) ⇒ Object
Override this if you want to do something special before or after calling update_services!.
-
#method_missing(meth, *args) ⇒ Object
Finding our services dynamically.
-
#setup_client(options = {}) ⇒ Object
Initialize a Client using Archipelago::Disco::MC or :jockey if given, or a new Archipelago::Disco::Jockey if none, that looks for new services :initial_service_update_interval or INITIAL_SERVICE_UPDATE_INTERVAL, when it starts and never slower than every :maximum_service_update_interval or MAXIMUM_SERVICE_UPDATE_INTERVAL.
-
#stop! ⇒ Object
Stops the service update thread for this Pirate and also unpublishes and/or stops the Jockey.
-
#update_services!(options = {}) ⇒ Object
Make our @jockey lookup all our services.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
Finding our services dynamically.
74 75 76 77 78 79 80 |
# File 'lib/archipelago/client.rb', line 74 def method_missing(meth, *args) if @services.include?(meth) return @services[meth] else super end end |
Instance Attribute Details
#debug_callable ⇒ Object
Returns the value of attribute debug_callable.
44 45 46 |
# File 'lib/archipelago/client.rb', line 44 def debug_callable @debug_callable end |
#jockey ⇒ Object (readonly)
Returns the value of attribute jockey.
43 44 45 |
# File 'lib/archipelago/client.rb', line 43 def jockey @jockey end |
#service_descriptions ⇒ Object (readonly)
Returns the value of attribute service_descriptions.
43 44 45 |
# File 'lib/archipelago/client.rb', line 43 def service_descriptions @service_descriptions end |
#services ⇒ Object (readonly)
Returns the value of attribute services.
43 44 45 |
# File 'lib/archipelago/client.rb', line 43 def services @services end |
Instance Method Details
#around_update_services(&block) ⇒ Object
Override this if you want to do something special before or after calling update_services!
98 99 100 |
# File 'lib/archipelago/client.rb', line 98 def around_update_services(&block) yield end |
#setup_client(options = {}) ⇒ Object
Initialize a Client using Archipelago::Disco::MC or :jockey if given, or a new Archipelago::Disco::Jockey if none, that looks for new services :initial_service_update_interval or INITIAL_SERVICE_UPDATE_INTERVAL, when it starts and never slower than every :maximum_service_update_interval or MAXIMUM_SERVICE_UPDATE_INTERVAL.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/archipelago/client.rb', line 53 def setup_client( = {}) setup_jockey() @initial_service_update_interval = [:initial_service_update_interval] || INITIAL_SERVICE_UPDATE_INTERVAL @maximum_service_update_interval = [:maximum_service_update_interval] || MAXIMUM_SERVICE_UPDATE_INTERVAL @service_descriptions = [:service_descriptions] @initial_lookup_timeout = [:initial_lookup_timeout] || INITIAL_LOOKUP_TIMEOUT @debug_callable = [:debug_callable] @services = {} @service_descriptions.each do |name, description| @services[name] = Archipelago::Disco::ServiceLocker.new @services[name].convert_to_tree! end start_service_updater start_subscriptions end |
#stop! ⇒ Object
Stops the service update thread for this Pirate and also unpublishes and/or stops the Jockey.
86 87 88 89 90 91 92 |
# File 'lib/archipelago/client.rb', line 86 def stop! @service_update_thread.kill if @service_update_thread stop_subscriptions unless defined?(Archipelago::Disco::MC) && @jockey && @jockey == Archipelago::Disco::MC @jockey.stop! end end |
#update_services!(options = {}) ⇒ Object
Make our @jockey lookup all our services.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/archipelago/client.rb', line 105 def update_services!( = {}) timeout = [:timeout] || 0 silent = [:silent] || false validate = [:validate] || false around_update_services do @service_descriptions.each do |name, description| # # This sure sounds inefficient, but hey, listen up: # # * RBTrees are nice and fast when it comes to looking up ordered stuff. # * They are horribly slow in all other ways. # * As an example: It takes (as of this writing) 10x the time to insert 10k elements in an RBTree # as it takes to sort 10k elements in an Array. # # This means that using them in Archipelago::Disco::ServiceLocker will be inefficient as hell, since they # are merging and creating new maps all the time. But in here, I expect us to not renew our service lists # more than on average once every MAXIMUM_SERVICE_UPDATE_INTERVAL, so that MAY make it worthwhile to do # the RBTree song and dance in here. Hopefully. # new_services = @jockey.lookup(Archipelago::Disco::Query.new(description), :timeout => timeout, :silent => silent) new_services.convert_to_tree! new_services.validate! if validate @services[name] = new_services @debug_callable.call("#{self}.service[#{name.inspect}]: #{PP.pp(@services[name].keys, "")}") if @debug_callable end end end |