Class: Voltdb::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
ClientUtils
Defined in:
lib/voltdb/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClientUtils

#host_and_port_from_address, #params_to_java_objects

Constructor Details

#initialize(java_client) ⇒ Client

Returns a new instance of Client.



22
23
24
# File 'lib/voltdb/client.rb', line 22

def initialize(java_client)
  @java_client = java_client
end

Instance Attribute Details

#java_clientObject (readonly)

Returns the value of attribute java_client.



12
13
14
# File 'lib/voltdb/client.rb', line 12

def java_client
  @java_client
end

Class Method Details

.create_client(config) ⇒ Object

Factory of Voltdb::Client

Parameters:

  • config

    Voltdb::ClientConfig

Returns:

  • Voltdb::Client



18
19
20
# File 'lib/voltdb/client.rb', line 18

def self.create_client(config)
  new(ClientFactory.create_client(config))
end

Instance Method Details

#call_all_partition_procedure(proc_name, *params) {|response| ... } ⇒ ClientResponseWithPartitionKey, ...

The method uses system procedure @GetPartitionKeys to get a set of partition values and then execute the stored procedure one partition at a time, and return an aggregated response. If a block is passed to the method an asyncronous call will be made

Parameters:

  • proc_name (String)

    proc_name the stored procedure name

  • *param (Array<Object>)

    a list of params

Yields:

  • (response)

    async response that will be invoked with procedure results

Returns:

  • (ClientResponseWithPartitionKey, true, false)

    VoltDB client response with partition key if the procedure was called synchronously, else will return true if the procedure was properly queued or false if it was not

Raises:

  • (ProcCallException, NoConnectionsException, IOException)

    ProcCallException will be returned if called synchronously



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/voltdb/client.rb', line 41

def call_all_partition_procedure(proc_name, *params, &block)
  if block_given?
    java_client.call_all_partition_procedure(
      AllPartitionProcCallback.new(&block),
      proc_name,
      *params_to_java_objects(*params)
    )
  else
    java_client.call_all_partition_procedure(
      proc_name,
      *params_to_java_objects(*params)
    ).map do |partition|
      partition.response.extend(ClientResponseUtils)
      partition
    end
  end
end

#call_procedure(proc_name, *params) {|response| ... } ⇒ Java::OrgVoltdbClient::ClientResponse, ...

Invokes a voltdb stored procedure based on its procedure name, a list of params and a block only if an asynchronous call is required

Parameters:

  • proc_name (String)

    the stored procedure name

  • *params (Array<Object>)

    a list of params

Yields:

  • (response)

    async response that will be invoked with procedure results

Returns:

  • (Java::OrgVoltdbClient::ClientResponse, true, false)

    VoltDB client response if the procedure was called synchronously, else will return true if the procedure was properly queued or false if it was not

Raises:

  • (ProcCallException, NoConnectionsException, IOException)

    ProcCallException will be returned if called synchronously



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/voltdb/client.rb', line 71

def call_procedure(proc_name, *params, &block)
  if block_given?
    java_client.call_procedure(
      ProcCallback.new(&block),
      proc_name,
      *params_to_java_objects(*params)
    )
  else
    java_client.call_procedure(proc_name, *params_to_java_objects(*params)).tap do |resp|
      resp.extend(ClientResponseUtils)
    end
  end
end

#call_procedure_with_timeout(query_timeout, proc_name, *params) {|response| ... } ⇒ Java::OrgVoltdbClient::ClientResponse, ...

Invokes a voltdb stored procedure with an specific timeout a procedure name, a list of params and a block only if an asynchronous call is required

Parameters:

  • query_timeout (Fixnum)

    the stored procedure timeout

  • proc_name (String)

    the stored procedure name

  • *params (Array<Object>)

    a list of params

Yields:

  • (response)

    async response that will be invoked with procedure results

Returns:

  • (Java::OrgVoltdbClient::ClientResponse, true, false)

    Voltdb client response if the procedure was called synchronously, else will return true if the procedure was properly queued or false if it was not

Raises:

  • (ProcCallException, NoConnectionsException, IOException)

    ProcCallException will be returned if called synchronously



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/voltdb/client.rb', line 99

def call_procedure_with_timeout(query_timeout, proc_name, *params, &block)
  if block_given?
    java_client.call_procedure_with_timeout(
      ProcCallback.new(&block),
      query_timeout,
      proc_name,
      *params_to_java_objects(*params)
    )
  else
    java_client.call_procedure_with_timeout(
      query_timeout,
      proc_name,
      *params_to_java_objects(*params)
    ).tap do |resp|
      resp.extend(ClientResponseUtils)
    end
  end
end

#get_connected_host_listArray<InetSocketAddress>

Get the list of VoltDB server hosts that this client has open TCP connections to

Returns:

  • (Array<InetSocketAddress>)

    An list of InetSocketAddress representing the connected hosts



123
124
125
# File 'lib/voltdb/client.rb', line 123

def get_connected_host_list
  java_client.get_connected_host_list.to_ary
end

#get_instance_idArray<Fixnum>

Get an identifier for the cluster that this client is currently connected to. This will be null if the client has not been connected. Currently these values have logical meaning, but they should just be interpreted as a unique per-cluster value

Returns:

  • (Array<Fixnum>)

    An array of Fixnum containing the millisecond timestamp when the cluster was started and the leader IP address



134
135
136
# File 'lib/voltdb/client.rb', line 134

def get_instance_id
  java_client.get_instance_id.to_ary
end

#get_new_bulk_loader(table_name, max_batch_size, upsert, failure, success = nil) {|failure, success| ... } ⇒ VoltBulkLoader

Creates a new instance of a VoltBulkLoader that is bound to this Client. Multiple instances of a VoltBulkLoader created by a single Client will share some resources, particularly if they are inserting into the same table

Parameters:

  • table_name (String)

    that bulk inserts are to be applied to

  • max_batch_size (Fixnum)

    to collect for the table before pushing a bulk insert

  • upsert (Boolean)

    true if want upsert instead of insert

Yield Parameters:

  • failure (row, list, response)

    BulkLoaderFailureCallback

  • success (row, response)

    BulkLoaderSuccessCallback

Returns:

  • (VoltBulkLoader)

    instance of VoltBulkLoader

Raises:

  • (Exception)

    if tableName can’t be found in the catalog



151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/voltdb/client.rb', line 151

def get_new_bulk_loader(table_name, max_batch_size, upsert, failure, success = nil)
  fcb = BulkLoaderFailureCallback.new(&failure)
  scb = BulkLoaderSuccessCallback.new(&success) if success

  if success
    java_client.get_new_bulk_loader(table_name, max_batch_size, upsert, fcb, scb)
  elsif upsert
    java_client.get_new_bulk_loader(table_name, max_batch_size, upsert, fcb)
  else
    java_client.get_new_bulk_loader(table_name, max_batch_size, fcb)
  end
end

#get_throughput_and_outstanding_txn_limitsArray<Fixnum>

Get the instantaneous values of the rate limiting values for this client

Returns:

  • (Array<Fixnum>)

    Array of Fixnum representing max throughput/sec and max outstanding txns



168
169
170
# File 'lib/voltdb/client.rb', line 168

def get_throughput_and_outstanding_txn_limits
  java_client.get_throughput_and_outstanding_txn_limits.to_ary
end

#update_classes(jar_path, classes_to_delete) {|response| ... } ⇒ Java::OrgVoltdbClient::ClientResponse, ...

This method is a convenience method that is equivalent to reading a jarfile containing to be added/updated into a byte array in Java code, then calling call_procedure with “@UpdateClasses” as the procedure name, followed by the bytes of the jarfile and a string containing a comma-separates list of classes to delete from the catalog.If a block is passed to the method an asyncronous call will be made

Parameters:

  • jar_path (String)

    path to the jar file with new/update clases

  • classes_to_delete (String, String)

    comma-separated list of classes to delete

Yields:

  • (response)

    async response that will be invoked with procedure results

Returns:

  • (Java::OrgVoltdbClient::ClientResponse, true, false)

    Voltdb client response if the procedure was called synchronously, else will return true if the procedure was properly queued or false if it was not

Raises:

  • (ProcCallException, NoConnectionsException, IOException)

    ProcCallException will be returned if called synchronously



189
190
191
192
193
194
195
196
197
# File 'lib/voltdb/client.rb', line 189

def update_classes(jar_path, classes_to_delete, &block)
  if block_given?
    java_client.update_classes(ProcCallback.new(&block), jar_path, classes_to_delete)
  else
    java_client.update_classes(jar_path, classes_to_delete).tap do |resp|
      resp.extend(ClientResponseUtils)
    end
  end
end