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
-
#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.
72 73 74 75 76 77 78 |
# File 'lib/archipelago/client.rb', line 72 def method_missing(meth, *args) if @services.include?(meth) return @services[meth] else super end end |
Instance Attribute Details
#jockey ⇒ Object (readonly)
Returns the value of attribute jockey.
42 43 44 |
# File 'lib/archipelago/client.rb', line 42 def jockey @jockey end |
#service_descriptions ⇒ Object (readonly)
Returns the value of attribute service_descriptions.
42 43 44 |
# File 'lib/archipelago/client.rb', line 42 def service_descriptions @service_descriptions end |
#services ⇒ Object (readonly)
Returns the value of attribute services.
42 43 44 |
# File 'lib/archipelago/client.rb', line 42 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!
96 97 98 |
# File 'lib/archipelago/client.rb', line 96 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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/archipelago/client.rb', line 51 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 @services = {} @service_descriptions.each do |name, description| t = RBTree.new t.extend(Archipelago::Current::ThreadedCollection) @services[name] = t 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.
84 85 86 87 88 89 90 |
# File 'lib/archipelago/client.rb', line 84 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.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/archipelago/client.rb', line 103 def update_services!( = {}) timeout = [:timeout] || 0 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. # @services[name] = @jockey.lookup(Archipelago::Disco::Query.new(description), timeout) @services[name].convert_to_tree! @services[name].validate! if validate end end end |