Class: RubyOnAcid::RindaFactory
- Defined in:
- lib/rubyonacid/factories/rinda.rb
Overview
Allows values to be sent over the network. For more information, see the Ruby standard library documentation for Rinda.
Instance Attribute Summary collapse
-
#default_factory ⇒ Object
A factory to pull requests from if retrieval of values via Rinda times out.
-
#timeout ⇒ Object
Time in seconds to wait for a value before giving up and returning a default value for the given key.
-
#uri ⇒ Object
The URI to connect to.
Instance Method Summary collapse
-
#get_unit(key) ⇒ Object
Get key from Rinda server.
-
#initialize(uri = "druby://127.0.0.1:7632", timeout = 0) ⇒ RindaFactory
constructor
A new instance of RindaFactory.
-
#start_service ⇒ Object
Create the Rinda TupleSpace for clients to write to.
Methods inherited from Factory
#boolean, #choose, #get, #within
Constructor Details
#initialize(uri = "druby://127.0.0.1:7632", timeout = 0) ⇒ RindaFactory
Returns a new instance of RindaFactory.
17 18 19 20 21 22 23 |
# File 'lib/rubyonacid/factories/rinda.rb', line 17 def initialize(uri = "druby://127.0.0.1:7632", timeout = 0) super @uri = uri @timeout = timeout @default_factory = nil @prior_values = {} end |
Instance Attribute Details
#default_factory ⇒ Object
A factory to pull requests from if retrieval of values via Rinda times out.
13 14 15 |
# File 'lib/rubyonacid/factories/rinda.rb', line 13 def default_factory @default_factory end |
#timeout ⇒ Object
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.
11 12 13 |
# File 'lib/rubyonacid/factories/rinda.rb', line 11 def timeout @timeout end |
#uri ⇒ Object
The URI to connect to. Default is “druby://127.0.0.1:7632” (7632 == RNDA).
15 16 17 |
# File 'lib/rubyonacid/factories/rinda.rb', line 15 def uri @uri end |
Instance Method Details
#get_unit(key) ⇒ Object
Get key from Rinda server.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rubyonacid/factories/rinda.rb', line 32 def get_unit(key) @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 value = @prior_values[key] end end value end |
#start_service ⇒ Object
Create the Rinda TupleSpace for clients to write to.
26 27 28 29 |
# File 'lib/rubyonacid/factories/rinda.rb', line 26 def start_service DRb.start_service @space = Rinda::TupleSpaceProxy.new(DRbObject.new(nil, @uri)) end |