Class List Method List File List

# Class: Vertx::Counter

Inherits:
  Object
  - Object
  - Vertx::Counter
  show all
Defined in:
  /Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/counter.rb

## Overview

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

## Constant Summary

@@j_api_type =

      Object.new

## Class Method Summary (collapse)

- + (Boolean) accept?(obj)
- + (Object) j_api_type
- + (Object) j_class
- + (Object) unwrap(obj)
- + (Object) wrap(obj)

## Instance Method Summary (collapse)

- - (void) add_and_get(value = nil) { ... }
  Add the value to the counter atomically and return the new count.
- - (void) compare_and_set(expected = nil, value = nil) { ... }
  Set the counter to the specified value only if the current value is the expectec value.
- - (void) decrement_and_get { ... }
  Decrement the counter atomically and return the new count.
- - (void) get { ... }
  Get the current value of the counter.
- - (void) get_and_add(value = nil) { ... }
  Add the value to the counter atomically and return the value before the add.
- - (void) get_and_increment { ... }
  Increment the counter atomically and return the value before the increment.
- - (void) increment_and_get { ... }
  Increment the counter atomically and return the new count.

## Class Method Details

### + (`Boolean`) accept?(obj)

Returns:

- (`Boolean`)

    18
    19
    20
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/counter.rb', line 18

    def @@j_api_type.accept?(obj)
      obj.class == Counter
    end

### + (`Object`) j_api_type

    27
    28
    29
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/counter.rb', line 27

    def self.j_api_type
      @@j_api_type
    end

### + (`Object`) j_class

    30
    31
    32
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/counter.rb', line 30

    def self.j_class
      Java::IoVertxCoreShareddata::Counter.java_class
    end

### + (`Object`) unwrap(obj)

    24
    25
    26
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/counter.rb', line 24

    def @@j_api_type.unwrap(obj)
      obj.j_del
    end

### + (`Object`) wrap(obj)

    21
    22
    23
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/counter.rb', line 21

    def @@j_api_type.wrap(obj)
      Counter.new(obj)
    end

## 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`)

    73
    74
    75
    76
    77
    78
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/counter.rb', line 73

    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`)

    95
    96
    97
    98
    99
    100
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/counter.rb', line 95

    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`)

    63
    64
    65
    66
    67
    68
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/counter.rb', line 63

    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`)

    36
    37
    38
    39
    40
    41
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/counter.rb', line 36

    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`)

    83
    84
    85
    86
    87
    88
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/counter.rb', line 83

    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`)

    54
    55
    56
    57
    58
    59
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/counter.rb', line 54

    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`)

    45
    46
    47
    48
    49
    50
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/counter.rb', line 45

    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