Class: Droonga::Client

Inherits:
Object
  • Object
show all
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/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: Error, RateLimiter

Constant Summary collapse

VERSION =
"0.1.9"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Creates a new Droonga Engine client.

Parameters:

  • options (Hash) (defaults to: {})

    Options to connect Droonga Engine.

Options Hash (options):

  • :tag (String) — default: "droonga"

    The tag of the request message.

  • :host (String) — default: "127.0.0.1"

    The host name or IP address of the Droonga Engine to be connected.

  • :port (Integer) — default: 24224

    The port number of the Droonga Engine to be connected.

  • :receiver_host (String) — default: Socket.gethostname

    The host name or IP address to receive response from the Droonga Engine.

  • :receiver_port (Integer) — default: 0

    The port number to receive response from the Droonga Engine.

  • :timeout (Integer) — default: 5

    The timeout value for connecting to, writing to and reading from Droonga Engine.



62
63
64
# File 'lib/droonga/client.rb', line 62

def initialize(options={})
  @connection = create_connection(options)
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.

Parameters:

  • options (Hash) (defaults to: {})

    Options to connect Droonga Engine.

Yields:

  • (client)

    Gives the opened client. It is alive while yielding.

Yield Parameters:

  • client (Client)

    The opened client.

Returns:

  • The return value from the given block.



37
38
39
40
41
42
43
44
# File 'lib/droonga/client.rb', line 37

def open(options={})
  client = new(options)
  begin
    yield(client)
  ensure
    client.close
  end
end

Instance Method Details

#closevoid

This method returns an undefined value.

Close the connection used by the client. You can't send any request anymore.



93
94
95
# File 'lib/droonga/client.rb', line 93

def close
  @connection.close
end

#request(message, options = {}, &block) ⇒ Object



75
76
77
78
79
80
# File 'lib/droonga/client.rb', line 75

def request(message, options={}, &block)
  if message["id"].nil?
    message = message.merge("id" => generate_id)
  end
  @connection.request(message, options, &block)
end

#send(message, options = {}, &block) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/droonga/client.rb', line 66

def send(message, options={}, &block)
  if message["id"].nil? or message["date"].nil?
    id = message["id"] || generate_id
    date = message["date"] || Time.now
    message = message.merge("id" => id, "date" => date)
  end
  @connection.send(message, options, &block)
end

#subscribe(message, options = {}, &block) ⇒ Object



82
83
84
85
86
87
# File 'lib/droonga/client.rb', line 82

def subscribe(message, options={}, &block)
  if message["id"].nil?
    message = message.merge("id" => generate_id)
  end
  @connection.subscribe(message, options, &block)
end