class Rinda::TupleEntry
A TupleEntry is a Tuple (i.e. a possible entry in some Tuplespace) together with expiry and cancellation data.
Attributes
Public Class Methods
Source
# File bundled-src/rinda-0.2.0/lib/rinda/tuplespace.rb, line 26 def initialize(ary, sec=nil) @cancel = false @expires = nil @tuple = make_tuple(ary) @renewer = nil renew(sec) end
Creates a TupleEntry based on ary with an optional renewer or expiry time sec.
A renewer must implement the renew method which returns a Numeric, nil, or true to indicate when the tuple has expired.
Public Instance Methods
Source
# File bundled-src/rinda-0.2.0/lib/rinda/tuplespace.rb, line 110 def [](key) @tuple[key] end
Retrieves key from the tuple.
Source
# File bundled-src/rinda-0.2.0/lib/rinda/tuplespace.rb, line 44 def alive? !canceled? && !expired? end
A TupleEntry is dead when it is canceled or expired.
Source
# File bundled-src/rinda-0.2.0/lib/rinda/tuplespace.rb, line 37 def cancel @cancel = true end
Marks this TupleEntry as canceled.
Source
# File bundled-src/rinda-0.2.0/lib/rinda/tuplespace.rb, line 57 def canceled?; @cancel; end
Returns the canceled status.
Source
# File bundled-src/rinda-0.2.0/lib/rinda/tuplespace.rb, line 65 def expired? return true unless @expires return false if @expires > Time.now return true if @renewer.nil? renew(@renewer) return true unless @expires return @expires < Time.now end
Has this tuple expired? (true/false).
A tuple has expired when its expiry timer based on the sec argument to initialize runs out.
Source
# File bundled-src/rinda-0.2.0/lib/rinda/tuplespace.rb, line 117 def fetch(key) @tuple.fetch(key) end
Fetches key from the tuple.
Source
# File bundled-src/rinda-0.2.0/lib/rinda/tuplespace.rb, line 96 def make_expires(sec=nil) case sec when Numeric Time.now + sec when true Time.at(1) when nil Time.at(2**31-1) end end
Source
# File bundled-src/rinda-0.2.0/lib/rinda/tuplespace.rb, line 131 def make_tuple(ary) Rinda::Tuple.new(ary) end
Creates a Rinda::Tuple for ary.
Source
# File bundled-src/rinda-0.2.0/lib/rinda/tuplespace.rb, line 84 def renew(sec_or_renewer) sec, @renewer = get_renewer(sec_or_renewer) @expires = make_expires(sec) end
Reset the expiry time according to sec_or_renewer.
nil-
it is set to expire in the far future.
true-
it has expired.
Numeric-
it will expire in that many seconds.
Otherwise the argument refers to some kind of renewer object which will reset its expiry time.
Source
# File bundled-src/rinda-0.2.0/lib/rinda/tuplespace.rb, line 124 def size @tuple.size end
The size of the tuple.
Private Instance Methods
Source
# File bundled-src/rinda-0.2.0/lib/rinda/tuplespace.rb, line 144 def get_renewer(it) case it when Numeric, true, nil return it, nil else begin return it.renew, it rescue Exception return it, nil end end end
Returns a valid argument to make_expires and the renewer or nil.
Given true, nil, or Numeric, returns that value and nil (no actual renewer). Otherwise it returns an expiry value from calling it.renew and the renewer.