Class: Vertx::Counter

Inherits:
Object
  • Object
show all
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/counter.rb

Overview

An asynchronous counter that can be used to across the cluster to maintain a consistent count.

Instance Method Summary (collapse)

Instance Method Details

- (void) add_and_get(value = nil) { ... }

This method returns an undefined value.

Add the value to the counter atomically and return the new count

Parameters:

  • value (Fixnum) (defaults to: nil)
    the value to add

Yields:

  • handler which will be passed the value

Raises:

  • (ArgumentError)


57
58
59
60
61
62
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/counter.rb', line 57

def add_and_get(value=nil)
  if value.class == Fixnum && block_given?
    return @j_del.java_method(:addAndGet, [Java::long.java_class,Java::IoVertxCore::Handler.java_class]).call(value,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling add_and_get(value)"
end

- (void) compare_and_set(expected = nil, value = nil) { ... }

This method returns an undefined value.

Set the counter to the specified value only if the current value is the expectec value. This happens atomically.

Parameters:

  • expected (Fixnum) (defaults to: nil)
    the expected value
  • value (Fixnum) (defaults to: nil)
    the new value

Yields:

  • the handler will be passed true on success

Raises:

  • (ArgumentError)


79
80
81
82
83
84
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/counter.rb', line 79

def compare_and_set(expected=nil,value=nil)
  if expected.class == Fixnum && value.class == Fixnum && block_given?
    return @j_del.java_method(:compareAndSet, [Java::long.java_class,Java::long.java_class,Java::IoVertxCore::Handler.java_class]).call(expected,value,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling compare_and_set(expected,value)"
end

- (void) decrement_and_get { ... }

This method returns an undefined value.

Decrement the counter atomically and return the new count

Yields:

  • handler which will be passed the value

Raises:

  • (ArgumentError)


47
48
49
50
51
52
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/counter.rb', line 47

def decrement_and_get
  if block_given?
    return @j_del.java_method(:decrementAndGet, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling decrement_and_get()"
end

- (void) get { ... }

This method returns an undefined value.

Get the current value of the counter

Yields:

  • handler which will be passed the value

Raises:

  • (ArgumentError)


20
21
22
23
24
25
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/counter.rb', line 20

def get
  if block_given?
    return @j_del.java_method(:get, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling get()"
end

- (void) get_and_add(value = nil) { ... }

This method returns an undefined value.

Add the value to the counter atomically and return the value before the add

Parameters:

  • value (Fixnum) (defaults to: nil)
    the value to add

Yields:

  • handler which will be passed the value

Raises:

  • (ArgumentError)


67
68
69
70
71
72
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/counter.rb', line 67

def get_and_add(value=nil)
  if value.class == Fixnum && block_given?
    return @j_del.java_method(:getAndAdd, [Java::long.java_class,Java::IoVertxCore::Handler.java_class]).call(value,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling get_and_add(value)"
end

- (void) get_and_increment { ... }

This method returns an undefined value.

Increment the counter atomically and return the value before the increment.

Yields:

  • handler which will be passed the value

Raises:

  • (ArgumentError)


38
39
40
41
42
43
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/counter.rb', line 38

def get_and_increment
  if block_given?
    return @j_del.java_method(:getAndIncrement, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling get_and_increment()"
end

- (void) increment_and_get { ... }

This method returns an undefined value.

Increment the counter atomically and return the new count

Yields:

  • handler which will be passed the value

Raises:

  • (ArgumentError)


29
30
31
32
33
34
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/src/main/resources/vertx/counter.rb', line 29

def increment_and_get
  if block_given?
    return @j_del.java_method(:incrementAndGet, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling increment_and_get()"
end