Class: Riak::Client::BeefcakeProtobuffsBackend::CrdtOperator Private

Inherits:
Object
  • Object
show all
Includes:
Util::Translation
Defined in:
lib/riak/client/beefcake/crdt_operator.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Serializes and writes CRDT operations from Riak::Crdt::Operation members into protobuffs, and writes them to a Riak cluster.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Translation

#i18n_scope, #t

Constructor Details

#initialize(backend) ⇒ CrdtOperator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CrdtOperator



22
23
24
# File 'lib/riak/client/beefcake/crdt_operator.rb', line 22

def initialize(backend)
  @backend = backend
end

Instance Attribute Details

#backendObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
# File 'lib/riak/client/beefcake/crdt_operator.rb', line 20

def backend
  @backend
end

Instance Method Details

#operate(bucket, key, bucket_type, operation, options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Serializes and writes CRDT operations.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/riak/client/beefcake/crdt_operator.rb', line 27

def operate(bucket, key, bucket_type, operation, options = {})
  serialized = serialize(operation)
  args = {
    bucket: bucket,
    key: key,
    type: bucket_type,
    op: serialized,
    return_body: true,
  }.merge options
  request = DtUpdateReq.new args
  begin
    return backend.protocol do |p|
      p.write :DtUpdateReq, request
      p.expect :DtUpdateResp, DtUpdateResp, empty_body_acceptable: true
    end
  rescue ProtobuffsErrorResponse => e
    raise unless e.message =~ /precondition/
    raise CrdtError::PreconditionError.new e.message
  end
end

#serialize(operations) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Serializes CRDT operations without writing them.



49
50
51
52
53
# File 'lib/riak/client/beefcake/crdt_operator.rb', line 49

def serialize(operations)
  return serialize [operations] unless operations.is_a? Enumerable

  serialize_wrap operations
end