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

Returns a new instance of Registry.



20
21
22
23
# File 'lib/zookeeper/continuation.rb', line 20

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

Instance Attribute Details

#in_flightObject

Returns the value of attribute in_flight

Returns:

  • (Object)

    the current value of in_flight



15
16
17
# File 'lib/zookeeper/continuation.rb', line 15

def in_flight
  @in_flight
end

#pendingObject

Returns the value of attribute pending

Returns:

  • (Object)

    the current value of pending



15
16
17
# File 'lib/zookeeper/continuation.rb', line 15

def pending
  @pending
end

Instance Method Details

#anything_to_do?Boolean

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

Returns:

  • (Boolean)


35
36
37
# File 'lib/zookeeper/continuation.rb', line 35

def anything_to_do?
  !pending.empty?
end

#next_batchObject

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



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

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

#synchronizedObject



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

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