lib/rubyonacid/factories/rinda.rb in rubyonacid-0.3.1 vs lib/rubyonacid/factories/rinda.rb in rubyonacid-0.4.0
- old
+ new
@@ -7,20 +7,20 @@
class RindaFactory < Factory
#Time in seconds to wait for a value before giving up and returning a default value for the given key.
#Default is 0, which will return immediately.
attr_accessor :timeout
- #A factory to pull requests from if retrieval of values via Rinda times out.
- attr_accessor :default_factory
#The URI to connect to. Default is "druby://127.0.0.1:7632" (7632 == RNDA).
attr_accessor :uri
- def initialize(uri = "druby://127.0.0.1:7632", timeout = 0)
+ #Takes a hash with all keys supported by Factory, plus these keys and defaults:
+ # :uri => "druby://127.0.0.1:7632"
+ # :timeout => 0
+ def initialize(options = {})
super
- @uri = uri
- @timeout = timeout
- @default_factory = nil
+ @uri = options[:uri] || "druby://127.0.0.1:7632"
+ @timeout = options[:timeout] || 0
@prior_values = {}
end
#Create the Rinda TupleSpace for clients to write to.
def start_service
@@ -33,13 +33,13 @@
@prior_values[key] ||= 0.0
begin
key, value = @space.take([key, Float], @timeout)
@prior_values[key] = value
rescue Rinda::RequestExpiredError => exception
- if @default_factory
- value = @default_factory.get_unit(key)
- else
+ if source_factories.empty?
value = @prior_values[key]
+ else
+ value = super
end
end
value
end