Class: Droonga::Client
- Inherits:
-
Object
- Object
- Droonga::Client
- Defined in:
- lib/droonga/client.rb,
lib/droonga/client/error.rb,
lib/droonga/client/version.rb,
lib/droonga/client/rate-limiter.rb,
lib/droonga/client/connection/http.rb,
lib/droonga/client/connection/error.rb,
lib/droonga/client/message_completer.rb,
lib/droonga/client/message_validator.rb,
lib/droonga/client/connection/empty-request.rb,
lib/droonga/client/connection/droonga-protocol.rb,
lib/droonga/client/connection/droonga-protocol/coolio.rb,
lib/droonga/client/connection/droonga-protocol/thread.rb
Defined Under Namespace
Modules: Connection Classes: ConnectionError, Error, MessageCompleter, MessageValidator, RateLimiter
Constant Summary collapse
- DEFAULT_PROTOCOL =
:droonga
- DEFAULT_HOST =
Socket.gethostname
- DEFAULT_PORT =
10031
- DEFAULT_TAG =
"droonga"
- DEFAULT_DATASET =
"Default"
- DEFAULT_TARGET_ROLE =
"any"
- DEFAULT_TIMEOUT_SECONDS =
3
- VERSION =
"0.2.2"
Instance Attribute Summary collapse
-
#on_error ⇒ Object
writeonly
Sets the attribute on_error.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
Class Method Summary collapse
-
.open(options = {}) {|client| ... } ⇒ Object
Opens a new connection and yields a Client object to use the connection.
Instance Method Summary collapse
-
#close ⇒ void
Close the connection used by the client.
- #complete(message) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
Creates a new Droonga Engine client.
- #request(message, options = {}, &block) ⇒ Object
- #send(message, options = {}, &block) ⇒ Object
- #subscribe(message, options = {}, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Creates a new Droonga Engine client.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/droonga/client.rb', line 87 def initialize(={}) @protocol = [:protocol] || DEFAULT_PROTOCOL @connection = create_connection() @connection.on_error = lambda do |error| on_error(ConnectionError.new(error)) end @completion = [:completion] != false @validation = [:validation] != false @completer = MessageCompleter.new(:default_dataset => [:default_dataset], :default_timeout => [:default_timeout], :default_target_role => [:default_target_role]) @validator = MessageValidator.new end |
Instance Attribute Details
#on_error=(value) ⇒ Object
Sets the attribute on_error
37 38 39 |
# File 'lib/droonga/client.rb', line 37 def on_error=(value) @on_error = value end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
38 39 40 |
# File 'lib/droonga/client.rb', line 38 def protocol @protocol end |
Class Method Details
.open(options = {}) {|client| ... } ⇒ Object
Opens a new connection and yields a Droonga::Client object to use the connection. The client is closed after the given block is finished.
58 59 60 61 62 63 64 65 |
# File 'lib/droonga/client.rb', line 58 def open(={}) client = new() begin yield(client) ensure client.close end end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
Close the connection used by the client. You can't send any request anymore.
125 126 127 |
# File 'lib/droonga/client.rb', line 125 def close @connection.close end |
#complete(message) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/droonga/client.rb', line 129 def complete() case @protocol when :http http_request = @connection.build_request() http_headers = {} http_request.canonical_each do |name, value| http_headers[name] = value end { "method" => http_request.method, "path" => http_request.path, "headers" => http_headers, "body" => http_request.body, } when :droonga do_completion(, :completion => true) else nil end end |
#request(message, options = {}, &block) ⇒ Object
109 110 111 112 113 |
# File 'lib/droonga/client.rb', line 109 def request(, ={}, &block) = do_completion(, ) do_validation(, ) @connection.request(, , &block) end |
#send(message, options = {}, &block) ⇒ Object
103 104 105 106 107 |
# File 'lib/droonga/client.rb', line 103 def send(, ={}, &block) = do_completion(, ) do_validation(, ) @connection.send(, , &block) end |
#subscribe(message, options = {}, &block) ⇒ Object
115 116 117 118 119 |
# File 'lib/droonga/client.rb', line 115 def subscribe(, ={}, &block) = do_completion(, ) do_validation(, ) @connection.subscribe(, , &block) end |