Class: Zookeeper::Continuation::Registry

Inherits:
Struct
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/zookeeper/continuation.rb

Overview

for keeping track of which continuations are pending, and which ones have been submitted and are awaiting a repsonse

`state_check` are high-priority checks that query the connection about its current state, they always run before other continuations

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry


22
23
24
25
# File 'lib/zookeeper/continuation.rb', line 22

def initialize
  super([], [], {})
  @mutex = Mutex.new
end

Instance Attribute Details

#in_flightObject

Returns the value of attribute in_flight


17
18
19
# File 'lib/zookeeper/continuation.rb', line 17

def in_flight
  @in_flight
end

#pendingObject

Returns the value of attribute pending


17
18
19
# File 'lib/zookeeper/continuation.rb', line 17

def pending
  @pending
end

#state_checkObject

Returns the value of attribute state_check


17
18
19
# File 'lib/zookeeper/continuation.rb', line 17

def state_check
  @state_check
end

Instance Method Details

#anything_to_do?Boolean

does not lock the mutex, returns true if there are pending jobs


37
38
39
# File 'lib/zookeeper/continuation.rb', line 37

def anything_to_do?
  (pending.length + state_check.length) > 0
end

#next_batchObject

returns the pending continuations, resetting the list this method is synchronized


43
44
45
46
47
48
49
50
# File 'lib/zookeeper/continuation.rb', line 43

def next_batch()
  @mutex.lock
  begin
    state_check.slice!(0, state_check.length) + pending.slice!(0,pending.length)
  ensure
    @mutex.unlock rescue nil
  end
end

#synchronizeObject


27
28
29
30
31
32
33
34
# File 'lib/zookeeper/continuation.rb', line 27

def synchronize
  @mutex.lock
  begin
    yield self
  ensure
    @mutex.unlock rescue nil
  end
end