Class: Groonga::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga/client.rb,
lib/groonga/client/error.rb,
lib/groonga/client/command.rb,
lib/groonga/client/default.rb,
lib/groonga/client/version.rb,
lib/groonga/client/empty-request.rb,
lib/groonga/client/protocol/gqtp.rb,
lib/groonga/client/protocol/http.rb,
lib/groonga/client/response/base.rb,
lib/groonga/client/response/dump.rb,
lib/groonga/client/response/load.rb,
lib/groonga/client/response/quit.rb,
lib/groonga/client/protocol/error.rb,
lib/groonga/client/response/check.rb,
lib/groonga/client/response/error.rb,
lib/groonga/client/response/defrag.rb,
lib/groonga/client/response/delete.rb,
lib/groonga/client/response/select.rb,
lib/groonga/client/response/status.rb,
lib/groonga/client/response/log_put.rb,
lib/groonga/client/response/register.rb,
lib/groonga/client/response/clearlock.rb,
lib/groonga/client/response/log_level.rb,
lib/groonga/client/response/log_reopen.rb,
lib/groonga/client/response/table_list.rb,
lib/groonga/client/protocol/http/coolio.rb,
lib/groonga/client/protocol/http/thread.rb,
lib/groonga/client/response/cache_limit.rb,
lib/groonga/client/response/column_list.rb,
lib/groonga/client/response/table_create.rb,
lib/groonga/client/response/column_create.rb,
lib/groonga/client/response/column_remove.rb,
lib/groonga/client/response/column_rename.rb,
lib/groonga/client/protocol/http/synchronous.rb

Defined Under Namespace

Modules: Default, Protocol, Response Classes: Command, EmptyRequest, Error

Constant Summary collapse

VERSION =
"0.1.6"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.

Parameters:

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

    The options.

Options Hash (options):

  • :protocol (:gqtp or :http)

    The protocol that is used by the client.



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/groonga/client.rb', line 65

def initialize(options={})
  options = options.dup
  protocol = options.delete(:protocol) || :gqtp
  options[:read_timeout] ||= Default::READ_TIMEOUT

  @connection = nil
  if protocol == :gqtp
    @connection = Groonga::Client::Protocol::GQTP.new(options)
  else
    @connection = Groonga::Client::Protocol::HTTP.new(options)
  end
end

Class Method Details

.open(options = {}) ⇒ Client .open(options = {}) {|client| ... } ⇒ Object

Overloads:

  • .open(options = {}) ⇒ Client

    Opens a new client connection.

    Parameters:

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

      The options.

    Options Hash (options):

    • :protocol (:gqtp or :http)

      The protocol that is used by the client.

    Returns:

    • (Client)

      The opened client.

  • .open(options = {}) {|client| ... } ⇒ Object

    Opens a new client connection while the block is evaluated. The block is finished the opened client is closed.

    Parameters:

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

      The options.

    Options Hash (options):

    • :protocol (:gqtp or :http)

      The protocol that is used by the client.

    Yields:

    • (client)

      Gives a opened client to the block. The opened client is closed automatically when the block is finished.

    Yield Parameters:

    • client (Client)

      The opened client.

    Yield Returns:

    • (Object)

      Any object.

    Returns:

    • (Object)

      Any object that is returned by the block.



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/groonga/client.rb', line 50

def open(options={}, &block)
  client = new(options)
  if block_given?
    begin
      yield(client)
    ensure
      client.close
    end
  else
    client
  end
end

Instance Method Details

#cache_limit(parameters, &block) ⇒ Object



117
118
119
# File 'lib/groonga/client.rb', line 117

def cache_limit(parameters, &block)
  execute_command("cache_limit", parameters, &block)
end

#check(parameters, &block) ⇒ Object



121
122
123
# File 'lib/groonga/client.rb', line 121

def check(parameters, &block)
  execute_command("check", parameters, &block)
end

#clearlock(parameters = {}, &block) ⇒ Object



125
126
127
# File 'lib/groonga/client.rb', line 125

def clearlock(parameters={}, &block)
  execute_command("clearlock", parameters, &block)
end

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

Closes the opened client 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.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/groonga/client.rb', line 95

def close(&block)
  sync = !block_given?
  if @connection
    close_request = @connection.close do
      yield unless sync
      @connection = nil
    end
    if sync
      close_request.wait
      true
    else
      close_request
    end
  else
    if sync
      false
    else
      EmptyRequest.new
    end
  end
end

#column_create(parameters, &block) ⇒ Object



129
130
131
# File 'lib/groonga/client.rb', line 129

def column_create(parameters, &block)
  execute_command("column_create", parameters, &block)
end

#column_list(parameters, &block) ⇒ Object



133
134
135
# File 'lib/groonga/client.rb', line 133

def column_list(parameters, &block)
  execute_command("column_list", parameters, &block)
end

#column_remove(parameters, &block) ⇒ Object



137
138
139
# File 'lib/groonga/client.rb', line 137

def column_remove(parameters, &block)
  execute_command("column_remove", parameters, &block)
end

#column_rename(parameters, &block) ⇒ Object



141
142
143
# File 'lib/groonga/client.rb', line 141

def column_rename(parameters, &block)
  execute_command("column_rename", parameters, &block)
end

#defrag(parameters = {}, &block) ⇒ Object



145
146
147
# File 'lib/groonga/client.rb', line 145

def defrag(parameters={}, &block)
  execute_command("defrag", parameters, &block)
end

#delete(parameters, &block) ⇒ Object



149
150
151
# File 'lib/groonga/client.rb', line 149

def delete(parameters, &block)
  execute_command("delete", parameters, &block)
end

#dump(parameters = {}, &block) ⇒ Object



153
154
155
# File 'lib/groonga/client.rb', line 153

def dump(parameters={}, &block)
  execute_command("dump", parameters, &block)
end

#execute(command, &block) ⇒ Object



209
210
211
# File 'lib/groonga/client.rb', line 209

def execute(command, &block)
  Client::Command.new(command).execute(@connection, &block)
end

#load(parameters, &block) ⇒ Object



157
158
159
# File 'lib/groonga/client.rb', line 157

def load(parameters, &block)
  execute_command("load", parameters, &block)
end

#log_level(parameters, &block) ⇒ Object



161
162
163
# File 'lib/groonga/client.rb', line 161

def log_level(parameters, &block)
  execute_command("log_level", parameters, &block)
end

#log_put(parameters, &block) ⇒ Object



165
166
167
# File 'lib/groonga/client.rb', line 165

def log_put(parameters, &block)
  execute_command("log_put", parameters, &block)
end

#log_reopen(parameters = {}, &block) ⇒ Object



169
170
171
# File 'lib/groonga/client.rb', line 169

def log_reopen(parameters={}, &block)
  execute_command("log_reopen", parameters, &block)
end

#quit(parameters = {}, &block) ⇒ Object



173
174
175
# File 'lib/groonga/client.rb', line 173

def quit(parameters={}, &block)
  execute_command("quit", parameters, &block)
end

#register(parameters, &block) ⇒ Object



177
178
179
# File 'lib/groonga/client.rb', line 177

def register(parameters, &block)
  execute_command("register", parameters, &block)
end

#select(parameters, &block) ⇒ Object



181
182
183
# File 'lib/groonga/client.rb', line 181

def select(parameters, &block)
  execute_command("select", parameters, &block)
end

#shutdown(parameters = {}, &block) ⇒ Object



185
186
# File 'lib/groonga/client.rb', line 185

def shutdown(parameters={}, &block)
end

#status(parameters = {}, &block) ⇒ Object



188
189
190
# File 'lib/groonga/client.rb', line 188

def status(parameters={}, &block)
  execute_command("status", parameters, &block)
end

#table_create(parameters, &block) ⇒ Object



192
193
194
# File 'lib/groonga/client.rb', line 192

def table_create(parameters, &block)
  execute_command("table_create", parameters, &block)
end

#table_list(parameters = {}, &block) ⇒ Object



196
197
198
# File 'lib/groonga/client.rb', line 196

def table_list(parameters={}, &block)
  execute_command("table_list", parameters, &block)
end

#table_remove(parameters, &block) ⇒ Object



200
201
# File 'lib/groonga/client.rb', line 200

def table_remove(parameters, &block)
end

#table_rename(parameters, &block) ⇒ Object



203
204
# File 'lib/groonga/client.rb', line 203

def table_rename(parameters, &block)
end

#truncate(parameters, &block) ⇒ Object



206
207
# File 'lib/groonga/client.rb', line 206

def truncate(parameters, &block)
end