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

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

Direct Known Subclasses

Thread

Defined Under Namespace

Classes: HTTPClient

Constant Summary collapse

DEBUG =
(ENV["GROONGA_CLIENT_HTTP_DEBUG"] == "yes")

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Synchronous.



53
54
55
56
# File 'lib/groonga/client/protocol/http/synchronous.rb', line 53

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



115
116
117
118
119
120
121
122
123
# File 'lib/groonga/client/protocol/http/synchronous.rb', line 115

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.



94
95
96
# File 'lib/groonga/client/protocol/http/synchronous.rb', line 94

def connected?
  false
end

#send(command) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/groonga/client/protocol/http/synchronous.rb', line 59

def send(command)
  begin
    http = HTTPClient.new(@url.host, @url.port)
    http.set_debug_output($stderr) if DEBUG
    start_options.each do |key, value|
      http.__send__("#{key}=", value)
    end
    http.start do
      http.read_timeout = read_timeout
      response = send_request(http, command)
      body = response.body
      case response
      when Net::HTTPSuccess,
           Net::HTTPBadRequest, # for invalid request
           Net::HTTPRequestTimeOut # for canceled request
        yield(body)
      else
        # "[[" is for command_version=1
        # "{" is for command_version=3
        if body.start_with?("[[") or body.start_with?("{")
          yield(body)
        else
          message = "#{response.code} #{response.message}: #{body}"
          raise Error.new(message)
        end
      end
    end
  rescue SystemCallError, Timeout::Error
    raise WrappedError.new($!)
  end
  EmptyRequest.new
end