Class: ZooKeeper::Transaction

Inherits:
Object
  • Object
show all
Includes:
Operations
Defined in:
lib/zkruby/client.rb

Overview

Collects zookeeper operations to execute as a single transaction

The builder methods #create #delete #check #set all take an optional callback block that will be executed if the #commit succeeds.

If the transaction fails none of these callbacks will be executed.

Constant Summary

Constants included from Operations

Operations::CREATE_OPTS

Instance Method Summary collapse

Constructor Details

#initialize(client, session) ⇒ Transaction

:nodoc



544
545
546
547
548
# File 'lib/zkruby/client.rb', line 544

def initialize(client,session)
    @client = client
    @session = session
    @ops = []
end

Instance Method Details

#check(path, version, &callback) ⇒ Object

Check Version



579
580
581
# File 'lib/zkruby/client.rb', line 579

def check(path,version,&callback)
    op_check(path,version,&callback)
end

#commitObject #commit { ... } ⇒ AsyncOp

Commit the transaction

Overloads:

  • #commitObject

    Synchronously commit the transaction

    Raises:

    • (Error)

      if the transaction failed

  • #commit { ... } ⇒ AsyncOp

    Returns captures the result of the asynchronous operation.

    Yields:

    • callback invoked if transaction is successful

    Returns:

    • (AsyncOp)

      captures the result of the asynchronous operation



590
591
592
# File 'lib/zkruby/client.rb', line 590

def commit(&callback)
    op = client.multi(ops,&callback)
end

#create(path, data, acl, *modeopts, &callback) ⇒ Object

Create a node

@param [String] path the base name of the path to create
@param [String] data the content to store at path
@param [Data::ACL] acl the access control list to apply to the new node
@param [Symbol,...] modeopts combination of :sequential, :emphemeral
@yieldparam [String] path the created path


557
558
559
# File 'lib/zkruby/client.rb', line 557

def create(path,data,acl,*modeopts,&callback)
    op_create(path,data,acl,*modeopts,&callback)
end

#delete(path, version, &callback) ⇒ Object

Delete path

@param [String] path
@param [FixNum] version the expected version to be deleted (-1 to match any version)
@yield  [] callback invoked if delete is successful


565
566
567
# File 'lib/zkruby/client.rb', line 565

def delete(path,version,&callback)
    op_delete(path,version,&callback)
end

#set(path, data, version, &callback) ⇒ Object

Set Data

@param [String] path
@param [String] data content to set at path
@param [Fixnum] version expected current version at path or -1 for any version
@yieldparam [Data::Stat] stat new stat of path


574
575
576
# File 'lib/zkruby/client.rb', line 574

def set(path,data,version,&callback)
    op_set(path,data,version,&callback)
end