| Class | Rinda::TupleEntry |
| In: |
lib/rinda/tuplespace.rb
|
| Parent: | Object |
A TupleEntry is a Tuple (i.e. a possible entry in some Tuplespace) together with expiry and cancellation data.
| expires | [RW] |
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.
# File lib/rinda/tuplespace.rb, line 25
25: def initialize(ary, sec=nil)
26: @cancel = false
27: @expires = nil
28: @tuple = make_tuple(ary)
29: @renewer = nil
30: renew(sec)
31: end
Retrieves key from the tuple.
# File lib/rinda/tuplespace.rb, line 109
109: def [](key)
110: @tuple[key]
111: end
A TupleEntry is dead when it is canceled or expired.
# File lib/rinda/tuplespace.rb, line 43
43: def alive?
44: !canceled? && !expired?
45: end
Marks this TupleEntry as canceled.
# File lib/rinda/tuplespace.rb, line 36
36: def cancel
37: @cancel = true
38: end
Returns the canceled status.
# File lib/rinda/tuplespace.rb, line 56
56: def canceled?; @cancel; end
Has this tuple expired? (true/false).
A tuple has expired when its expiry timer based on the sec argument to initialize runs out.
# File lib/rinda/tuplespace.rb, line 64
64: def expired?
65: return true unless @expires
66: return false if @expires > Time.now
67: return true if @renewer.nil?
68: renew(@renewer)
69: return true unless @expires
70: return @expires < Time.now
71: end
Fetches key from the tuple.
# File lib/rinda/tuplespace.rb, line 116
116: def fetch(key)
117: @tuple.fetch(key)
118: end
Returns an expiry Time based on sec which can be one of:
| Numeric: | sec seconds into the future |
| true: | the expiry time is the start of 1970 (i.e. expired) |
| nil: | it is Tue Jan 19 03:14:07 GMT Standard Time 2038 (i.e. when UNIX clocks will die) |
# File lib/rinda/tuplespace.rb, line 95
95: def make_expires(sec=nil)
96: case sec
97: when Numeric
98: Time.now + sec
99: when true
100: Time.at(1)
101: when nil
102: Time.at(2**31-1)
103: end
104: end
Creates a Rinda::Tuple for ary.
# File lib/rinda/tuplespace.rb, line 130
130: def make_tuple(ary)
131: Rinda::Tuple.new(ary)
132: end
Reset the expiry time according to sec_or_renewer.
| nil: | it is set to expire in the far future. |
| false: | 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.
# File lib/rinda/tuplespace.rb, line 83
83: def renew(sec_or_renewer)
84: sec, @renewer = get_renewer(sec_or_renewer)
85: @expires = make_expires(sec)
86: 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.
# File lib/rinda/tuplespace.rb, line 143
143: def get_renewer(it)
144: case it
145: when Numeric, true, nil
146: return it, nil
147: else
148: begin
149: return it.renew, it
150: rescue Exception
151: return it, nil
152: end
153: end
154: end