Class: EM::HyperDex::Client
- Inherits:
-
Object
- Object
- EM::HyperDex::Client
- Defined in:
- lib/em-hyperdex-client.rb
Defined Under Namespace
Modules: Watcher Classes: DeferrableEnumerable
Constant Summary collapse
- ASYNC_METHODS =
HyperDex::Client::Client. instance_methods. map(&:to_s). grep(/^async_/). map { |m| m.gsub(/^async_/, '') }
- ITERATOR_METHODS =
%w{search sorted_search}
Instance Method Summary collapse
- #close ⇒ Object
- #handle_response ⇒ Object
-
#initialize(host, port) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(host, port) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/em-hyperdex-client.rb', line 8 def initialize(host, port) @client = HyperDex::Client::Client.new(host, port) @failed = false @outstanding = {} if ::EM.reactor_running? @em_conn = ::EM.watch(@client.poll_fd, Watcher, self) @em_conn.notify_readable = true end end |
Instance Method Details
#close ⇒ Object
104 105 106 107 108 |
# File 'lib/em-hyperdex-client.rb', line 104 def close @outstanding.each { |o| o.wait } @em_conn.detach @client = nil end |
#handle_response ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/em-hyperdex-client.rb', line 73 def handle_response begin df = @outstanding.delete(op = @client.loop(0)) rescue HyperDex::Client::HyperDexClientException # Something has gone wrong, and we're just going to take our bat # and ball and go home. @outstanding.values.each { |op| op.fail(ex) } @failed = true return end # It's possible for the client's poll_fd to see activity when there # isn't any new completed operation; according to rescrv, this can # happen "because of background activity". In that case, `#loop` # called with a timeout will return `nil`, and we should just # return quietly. if op.nil? return end begin if df.respond_to?(:item_available) df.item_available else df.succeed(op.wait) end rescue HyperDex::Client::HyperDexClientException => ex df.fail(ex) end end |