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(keeping = 600) ⇒ TimerHolder2

Returns a new instance of TimerHolder2.



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

def initialize(keeping=600)
  super()
  @sentinel = Object.new
  @gc = {}
  @renew = {}
  @keeping = keeping
  @expires = nil
end

Instance Method Details

#add(obj) ⇒ Object



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

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

#fetch(key) ⇒ Object



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

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