Module: Shuttlecraft::Comms
- Included in:
- Shuttlecraft, Mothership
- Defined in:
- lib/shuttlecraft/comms.rb
Instance Method Summary collapse
-
#each_client ⇒ Object
Loops through each client and yields DRb object for that client.
-
#each_service_uri ⇒ Object
Enumerates through each registered service’s uri.
- #initialize_comms(opts = {}) ⇒ Object
- #registered_services ⇒ Object
-
#update ⇒ Object
Retrieve the last registration data from the TupleSpace.
-
#update! ⇒ Object
Forces retrieval of registrations from the TupleSpace.
-
#update? ⇒ Boolean
Registered services are only updatable if they haven’t been updated in the last @update_every seconds.
Instance Method Details
#each_client ⇒ Object
Loops through each client and yields DRb object for that client
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/shuttlecraft/comms.rb', line 56 def each_client each_service_uri do |uri| begin remote = DRbObject.new_with_uri(uri) yield remote rescue DRb::DRbConnError rescue => e puts "Error sending message to client: #{e.}" if @verbose end end end |
#each_service_uri ⇒ Object
Enumerates through each registered service’s uri
45 46 47 48 49 50 51 |
# File 'lib/shuttlecraft/comms.rb', line 45 def each_service_uri return enum_for __method__ unless block_given? registered_services.each do |_, uri| yield uri end end |
#initialize_comms(opts = {}) ⇒ Object
10 11 12 13 14 |
# File 'lib/shuttlecraft/comms.rb', line 10 def initialize_comms(opts={}) @registered_services_ary = [] @update_every = opts[:update_every] || 2 @last_update = Time.at 0 end |
#registered_services ⇒ Object
16 17 18 19 |
# File 'lib/shuttlecraft/comms.rb', line 16 def registered_services update @registered_services_ary end |
#update ⇒ Object
Retrieve the last registration data from the TupleSpace.
30 31 32 33 34 |
# File 'lib/shuttlecraft/comms.rb', line 30 def update return unless update? @last_update = Time.now @registered_services_ary = read_registered_services end |
#update! ⇒ Object
Forces retrieval of registrations from the TupleSpace.
38 39 40 41 |
# File 'lib/shuttlecraft/comms.rb', line 38 def update! @last_update = Time.at 0 update end |
#update? ⇒ Boolean
Registered services are only updatable if they haven’t been updated in the last @update_every seconds. This prevents DRb message spam.
24 25 26 |
# File 'lib/shuttlecraft/comms.rb', line 24 def update? (@last_update + @update_every) < Time.now end |