Class: DRb::TimerIdConv::TimerHolder2

Inherits:
Object
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/drb/timeridconv.rb

Overview

:nodoc:

Defined Under Namespace

Classes: InvalidIndexError

Instance Method Summary collapse

Constructor Details

#initialize(timeout = 600) ⇒ TimerHolder2

Returns a new instance of TimerHolder2.


20
21
22
23
24
25
26
27
28
# File 'lib/drb/timeridconv.rb', line 20

def initialize(timeout=600)
  super()
  @sentinel = Object.new
  @gc = {}
  @curr = {}
  @renew = {}
  @timeout = timeout
  @keeper = keeper
end

Instance Method Details

#add(obj) ⇒ Object


30
31
32
33
34
35
36
# File 'lib/drb/timeridconv.rb', line 30

def add(obj)
  synchronize do
    key = obj.__id__
    @curr[key] = obj
    return key
  end
end

#fetch(key, dv = @sentinel) ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/drb/timeridconv.rb', line 38

def fetch(key, dv=@sentinel)
  synchronize do
    obj = peek(key)
    if obj == @sentinel
      return dv unless dv == @sentinel
      raise InvalidIndexError
    end
    @renew[key] = obj # KeepIt
    return obj
  end
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)

50
51
52
53
54
55
56
# File 'lib/drb/timeridconv.rb', line 50

def include?(key)
  synchronize do
    obj = peek(key)
    return false if obj == @sentinel
    true
  end
end

#peek(key) ⇒ Object


58
59
60
61
62
# File 'lib/drb/timeridconv.rb', line 58

def peek(key)
  synchronize do
    return @curr.fetch(key, @renew.fetch(key, @gc.fetch(key, @sentinel)))
  end
end