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.



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

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

Instance Method Details

#add(obj) ⇒ Object



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

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

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



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

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)


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

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

#peek(key) ⇒ Object



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

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