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.

Methods

[]   alive?   cancel   canceled?   expired?   fetch   get_renewer   make_expires   make_tuple   new   renew   size   value  

Included Modules

DRbUndumped

Attributes

expires  [RW] 

Public Class methods

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.

[Source]

    # File lib/rinda/tuplespace.rb, line 27
27:     def initialize(ary, sec=nil)
28:       @cancel = false
29:       @expires = nil
30:       @tuple = make_tuple(ary)
31:       @renewer = nil
32:       renew(sec)
33:     end

Public Instance methods

Retrieves key from the tuple.

[Source]

     # File lib/rinda/tuplespace.rb, line 111
111:     def [](key)
112:       @tuple[key]
113:     end

A TupleEntry is dead when it is canceled or expired.

[Source]

    # File lib/rinda/tuplespace.rb, line 45
45:     def alive?
46:       !canceled? && !expired?
47:     end

Marks this TupleEntry as canceled.

[Source]

    # File lib/rinda/tuplespace.rb, line 38
38:     def cancel
39:       @cancel = true
40:     end

Returns the canceled status.

[Source]

    # File lib/rinda/tuplespace.rb, line 58
58:     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.

[Source]

    # File lib/rinda/tuplespace.rb, line 66
66:     def expired?
67:       return true unless @expires
68:       return false if @expires > Time.now
69:       return true if @renewer.nil?
70:       renew(@renewer)
71:       return true unless @expires
72:       return @expires < Time.now
73:     end

Fetches key from the tuple.

[Source]

     # File lib/rinda/tuplespace.rb, line 118
118:     def fetch(key)
119:       @tuple.fetch(key)
120:     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)

[Source]

     # File lib/rinda/tuplespace.rb, line 97
 97:     def make_expires(sec=nil)
 98:       case sec
 99:       when Numeric
100:         Time.now + sec
101:       when true
102:         Time.at(1)
103:       when nil
104:         Time.at(2**31-1)
105:       end
106:     end

Creates a Rinda::Tuple for ary.

[Source]

     # File lib/rinda/tuplespace.rb, line 132
132:     def make_tuple(ary)
133:       Rinda::Tuple.new(ary)
134:     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.

[Source]

    # File lib/rinda/tuplespace.rb, line 85
85:     def renew(sec_or_renewer)
86:       sec, @renewer = get_renewer(sec_or_renewer)
87:       @expires = make_expires(sec)
88:     end

The size of the tuple.

[Source]

     # File lib/rinda/tuplespace.rb, line 125
125:     def size
126:       @tuple.size
127:     end

Return the object which makes up the tuple itself: the Array or Hash.

[Source]

    # File lib/rinda/tuplespace.rb, line 53
53:     def value; @tuple.value; end

Private Instance methods

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.

[Source]

     # File lib/rinda/tuplespace.rb, line 145
145:     def get_renewer(it)
146:       case it
147:       when Numeric, true, nil
148:         return it, nil
149:       else
150:         begin
151:           return it.renew, it
152:         rescue Exception
153:           return it, nil
154:         end
155:       end
156:     end

[Validate]