Class: Groonga::Client::Protocol::HTTP::Synchronous

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

Direct Known Subclasses

Thread

Instance Method Summary collapse

Constructor Details

#initialize(host, port, options) ⇒ Synchronous

Returns a new instance of Synchronous.



29
30
31
32
33
# File 'lib/groonga/client/protocol/http/synchronous.rb', line 29

def initialize(host, port, options)
  @host = host
  @port = port
  @options = options
end

Instance Method Details

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

Does nothing because the current implementation doesn't support keep-alive. If the implementation supports keep-alive, it close the opend connection.

Overloads:

  • #closefalse

    Closes synchronously.

    Returns:

    • (false)

      It always returns false because there is always 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.



82
83
84
85
86
87
88
89
90
# File 'lib/groonga/client/protocol/http/synchronous.rb', line 82

def close(&block)
  sync = !block_given?
  if sync
    false
  else
    yield
    EmptyRequest.new
  end
end

#connected?false

Returns Always returns false because the current implementation doesn't support keep-alive.

Returns:

  • (false)

    Always returns false because the current implementation doesn't support keep-alive.



61
62
63
# File 'lib/groonga/client/protocol/http/synchronous.rb', line 61

def connected?
  false
end

#send(command) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/groonga/client/protocol/http/synchronous.rb', line 35

def send(command)
  begin
    Net::HTTP.start(@host, @port) do |http|
      http.read_timeout = read_timeout
      response = send_request(http, command)
      case response
      when Net::HTTPSuccess, Net::HTTPBadRequest
        yield(response.body)
      else
        if response.body.start_with?("[[")
          yield(response.body)
        else
          message =
            "#{response.code} #{response.message}: #{response.body}"
          raise Error.new(message)
        end
      end
    end
  rescue SystemCallError, Timeout::Error
    raise WrappedError.new($!)
  end
  EmptyRequest.new
end