Class: Officer::Client
- Inherits:
-
Object
- Object
- Officer::Client
- Defined in:
- lib/officer/client.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #lock(name, options = {}) ⇒ Object
- #reconnect ⇒ Object
- #reset ⇒ Object
- #unlock(name) ⇒ Object
- #with_lock(name, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
17 18 19 20 21 22 23 24 |
# File 'lib/officer/client.rb', line 17 def initialize ={} .reverse_merge! :host => 'localhost', :port => 11500 @host = [:host] @port = [:port] connect end |
Instance Method Details
#lock(name, options = {}) ⇒ Object
31 32 33 |
# File 'lib/officer/client.rb', line 31 def lock name, ={} execute({:command => 'lock', :name => name, :timeout => [:timeout]}.to_json) end |
#reconnect ⇒ Object
26 27 28 29 |
# File 'lib/officer/client.rb', line 26 def reconnect disconnect connect end |
#reset ⇒ Object
57 58 59 |
# File 'lib/officer/client.rb', line 57 def reset execute({:command => 'reset'}.to_json) end |
#unlock(name) ⇒ Object
35 36 37 |
# File 'lib/officer/client.rb', line 35 def unlock name execute({:command => 'unlock', :name => name}.to_json) end |
#with_lock(name, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/officer/client.rb', line 39 def with_lock name, ={} response = lock name, result = response['result'] raise LockTimeoutError if result == 'timed_out' raise LockError unless %w(acquired already_acquired).include?(result) begin yield ensure # Deal with nested with_lock calls. Only the outer most call should tell the server to unlock. if result == 'acquired' response = unlock name raise UnlockError unless response['result'] == 'released' end end end |