Class: Rinda::TupleEntry
- Inherits:
-
Object
- Object
- Rinda::TupleEntry
- Includes:
- DRbUndumped
- Defined in:
- lib/rinda/tuplespace.rb
Overview
A TupleEntry is a Tuple (i.e. a possible entry in some Tuplespace) together with expiry and cancellation data.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#expires ⇒ Object
Returns the value of attribute expires.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Retrieves
key
from the tuple. -
#alive? ⇒ Boolean
A TupleEntry is dead when it is canceled or expired.
-
#cancel ⇒ Object
Marks this TupleEntry as canceled.
-
#canceled? ⇒ Boolean
Returns the canceled status.
-
#expired? ⇒ Boolean
Has this tuple expired? (true/false).
-
#fetch(key) ⇒ Object
Fetches
key
from the tuple. -
#initialize(ary, sec = nil) ⇒ TupleEntry
constructor
Creates a TupleEntry based on
ary
with an optional renewer or expiry timesec
. -
#make_expires(sec = nil) ⇒ Object
- Returns an expiry Time based on
sec
which can be one of: Numeric sec
seconds into the futuretrue
- 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).
- the expiry time is the start of 1970 (i.e. expired)
- Returns an expiry Time based on
-
#make_tuple(ary) ⇒ Object
Creates a Rinda::Tuple for
ary
. -
#renew(sec_or_renewer) ⇒ Object
Reset the expiry time according to
sec_or_renewer
. -
#size ⇒ Object
The size of the tuple.
-
#value ⇒ Object
Return the object which makes up the tuple itself: the Array or Hash.
Constructor Details
#initialize(ary, sec = nil) ⇒ TupleEntry
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.
27 28 29 30 31 32 33 |
# File 'lib/rinda/tuplespace.rb', line 27 def initialize(ary, sec=nil) @cancel = false @expires = nil @tuple = make_tuple(ary) @renewer = nil renew(sec) end |
Instance Attribute Details
#expires ⇒ Object
Returns the value of attribute expires
18 19 20 |
# File 'lib/rinda/tuplespace.rb', line 18 def expires @expires end |
Instance Method Details
#[](key) ⇒ Object
Retrieves key
from the tuple.
111 112 113 |
# File 'lib/rinda/tuplespace.rb', line 111 def [](key) @tuple[key] end |
#alive? ⇒ Boolean
A TupleEntry is dead when it is canceled or expired.
45 46 47 |
# File 'lib/rinda/tuplespace.rb', line 45 def alive? !canceled? && !expired? end |
#cancel ⇒ Object
Marks this TupleEntry as canceled.
38 39 40 |
# File 'lib/rinda/tuplespace.rb', line 38 def cancel @cancel = true end |
#canceled? ⇒ Boolean
Returns the canceled status.
58 |
# File 'lib/rinda/tuplespace.rb', line 58 def canceled?; @cancel; end |
#expired? ⇒ Boolean
Has this tuple expired? (true/false).
A tuple has expired when its expiry timer based on the sec
argument to #initialize runs out.
66 67 68 69 70 71 72 73 |
# File 'lib/rinda/tuplespace.rb', line 66 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 |
#fetch(key) ⇒ Object
Fetches key
from the tuple.
118 119 120 |
# File 'lib/rinda/tuplespace.rb', line 118 def fetch(key) @tuple.fetch(key) end |
#make_expires(sec = nil) ⇒ Object
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)
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/rinda/tuplespace.rb', line 97 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 |
#make_tuple(ary) ⇒ Object
Creates a Rinda::Tuple for ary
.
132 133 134 |
# File 'lib/rinda/tuplespace.rb', line 132 def make_tuple(ary) Rinda::Tuple.new(ary) end |
#renew(sec_or_renewer) ⇒ Object
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.
85 86 87 88 |
# File 'lib/rinda/tuplespace.rb', line 85 def renew(sec_or_renewer) sec, @renewer = get_renewer(sec_or_renewer) @expires = make_expires(sec) end |
#size ⇒ Object
The size of the tuple.
125 126 127 |
# File 'lib/rinda/tuplespace.rb', line 125 def size @tuple.size end |
#value ⇒ Object
Return the object which makes up the tuple itself: the Array or Hash.
53 |
# File 'lib/rinda/tuplespace.rb', line 53 def value; @tuple.value; end |