Class: Rinda::TupleEntry

Class | Rinda::TupleEntry
In: | 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 make_expires make_tuple new renew size value

### Included Modules

DRbUndumped

### Attributes

expires | [RW] |

### Public Class methods

new(ary, sec=nil)

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 rinda/tuplespace.rb, line 25
        def initialize(ary, sec=nil)
          @cancel = false
          @expires = nil
          @tuple = make_tuple(ary)
          @renewer = nil
          renew(sec)
        end

### Public Instance methods

[](key)

Retrieves `key` from the tuple.

[Source]

    # File rinda/tuplespace.rb, line 109
        def [](key)
          @tuple[key]
        end

alive?()

A TupleEntry is dead when it is canceled or expired.

[Source]

    # File rinda/tuplespace.rb, line 43
        def alive?
          !canceled? && !expired?
        end

cancel()

Marks this TupleEntry as canceled.

[Source]

    # File rinda/tuplespace.rb, line 36
        def cancel
          @cancel = true
        end

canceled?()

Returns the canceled status.

[Source]

    # File rinda/tuplespace.rb, line 56
        def canceled?; @cancel; end

expired?()

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 rinda/tuplespace.rb, line 64
        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)

Fetches `key` from the tuple.

[Source]

    # File rinda/tuplespace.rb, line 116
        def fetch(key)
          @tuple.fetch(key)
        end

make_expires(sec=nil)

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 rinda/tuplespace.rb, line 95
        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)

Creates a Rinda::Tuple for `ary`.

[Source]

    # File rinda/tuplespace.rb, line 130
        def make_tuple(ary)
          Rinda::Tuple.new(ary)
        end

renew(sec_or_renewer)

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 rinda/tuplespace.rb, line 83
        def renew(sec_or_renewer)
          sec, @renewer = get_renewer(sec_or_renewer)
          @expires = make_expires(sec)
        end

size()

The size of the tuple.

[Source]

    # File rinda/tuplespace.rb, line 123
        def size
          @tuple.size
        end

value()

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

[Source]

    # File rinda/tuplespace.rb, line 51
        def value; @tuple.value; end

[Validate]