Class: Groonga::Client::Protocol::GQTP

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga/client/protocol/gqtp.rb

Defined Under Namespace

Classes: RawResponse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ GQTP

Returns a new instance of GQTP.



30
31
32
33
34
35
36
37
# File 'lib/groonga/client/protocol/gqtp.rb', line 30

def initialize(url, options={})
  begin
    @client = ::GQTP::Client.new(:host => url.host,
                                 :port => url.port)
  rescue ::GQTP::ConnectionError
    raise WrappedError.new($!)
  end
end

Instance Method Details

#closeBoolean #close({}) { ... } ⇒ #wait

Closes the opened connection if the current connection is still opened. You can't send a new command after you call this method.

Overloads:

  • #closeBoolean

    Closes synchronously.

    Returns:

    • (Boolean)

      true when the opened connection is closed. false when there is no connection.

  • #close({}) { ... } ⇒ #wait

    Closes asynchronously.

    Yields:

    • [] Calls the block when the opened connection is closed.

    Returns:

    • (#wait)

      The request object. If you want to wait until the request is processed. You can send #wait message to the request.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/groonga/client/protocol/gqtp.rb', line 73

def close(&block)
  sync = !block_given?
  if connected?
    return_value = @client.close(&block)
    @client = nil
    return_value
  else
    if sync
      false
    else
      EmptyRequest.new
    end
  end
end

#connected?Boolean

Returns true if the current connection is opened, false otherwise.

Returns:

  • (Boolean)

    true if the current connection is opened, false otherwise.



52
53
54
# File 'lib/groonga/client/protocol/gqtp.rb', line 52

def connected?
  not @client.nil?
end

#send(command) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/groonga/client/protocol/gqtp.rb', line 39

def send(command)
  formatted_command = command.to_command_format
  raw_response = RawResponse.new(command)
  @client.send(formatted_command) do |header, body|
    raw_response.header = header
    raw_response.body = body
    response = raw_response.to_groonga_command_compatible_response
    yield(response)
  end
end