Class List Method List File List

# Class: VertxCircuitBreaker::CircuitBreaker

Inherits:
  Object
  - Object
  - VertxCircuitBreaker::CircuitBreaker
  show all
Defined in:
  /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb

## Overview

An implementation of the circuit breaker pattern for Vert.x

## Constant Summary

@@j_api_type =

      Object.new

## Class Method Summary (collapse)

- + (Boolean) accept?(obj)
- + (::VertxCircuitBreaker::CircuitBreaker) create(name = nil, vertx = nil, options = nil)
  Creates a new instance of CircuitBreaker.
- + (Object) j_api_type
- + (Object) j_class
- + (Object) unwrap(obj)
- + (Object) wrap(obj)

## Instance Method Summary (collapse)

- - (self) close
  Closes the circuit breaker.
- - (self) close_handler { ... }
  Sets a invoked when the circuit breaker state switches to close.
- - (::Vertx::Future) execute { ... }
  Same as #execute_with_fallback but using the circuit breaker default fallback.
- - (self) execute_and_report(resultPromise = nil) { ... }
  Same as #execute_and_report_with_fallback but using the circuit breaker default fallback.
- - (self) execute_and_report_with_fallback(resultPromise = nil, command = nil, fallback = nil) { ... }
  Executes the given operation with the circuit breaker control.
- - (void) execute_command(command = nil) { ... }
  Same as #execute_with_fallback but using the circuit breaker default fallback.
- - (void) execute_command_with_fallback(command = nil, fallback = nil) { ... }
  Same as #execute_with_fallback but using a callback.
- - (::Vertx::Future) execute_with_fallback(command = nil, fallback = nil) { ... }
  Executes the given operation with the circuit breaker control.
- - (Fixnum) failure_count
  The current number of failures.
- - (self) fallback(handler = nil) { ... }
  Sets a default invoked when the bridge is open to handle the "request", or on failure if Hash#is_fallback_on_failure is enabled.
- - (self) half_open_handler { ... }
  Sets a invoked when the circuit breaker state switches to half-open.
- - (String) name
  The name of the circuit breaker.
- - (self) open
  Explicitly opens the circuit.
- - (self) open_handler { ... }
  Sets a invoked when the circuit breaker state switches to open.
- - (self) reset
  Resets the circuit breaker state (number of failure set to 0 and state set to closed).
- - (self) retry_policy(retryPolicy = nil) { ... }
- - (:OPEN, ...) state
  The current state.

## Class Method Details

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

Returns:

- (`Boolean`)

    20
    21
    22
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 20

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

### + (`::VertxCircuitBreaker::CircuitBreaker`) create(name = nil, vertx = nil, options = nil)

Creates a new instance of VertxCircuitBreaker::CircuitBreaker.

Parameters:

- name (`String`) (defaults to: `nil`) —
  the name
- vertx (`::Vertx::Vertx`) (defaults to: `nil`) —
  the Vert.x instance
- options (`Hash`) (defaults to: `nil`) —
  the configuration option

Returns:

- (`::VertxCircuitBreaker::CircuitBreaker`) —
  the created instance

Raises:

- (`ArgumentError`)

    40
    41
    42
    43
    44
    45
    46
    47
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 40

    def self.create(name=nil,vertx=nil,options=nil)
      if name.class == String && vertx.class.method_defined?(:j_del) && !block_given? && options == nil
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxCircuitbreaker::CircuitBreaker.java_method(:create, [Java::java.lang.String.java_class,Java::IoVertxCore::Vertx.java_class]).call(name,vertx.j_del),::VertxCircuitBreaker::CircuitBreaker)
      elsif name.class == String && vertx.class.method_defined?(:j_del) && options.class == Hash && !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxCircuitbreaker::CircuitBreaker.java_method(:create, [Java::java.lang.String.java_class,Java::IoVertxCore::Vertx.java_class,Java::IoVertxCircuitbreaker::CircuitBreakerOptions.java_class]).call(name,vertx.j_del,Java::IoVertxCircuitbreaker::CircuitBreakerOptions.new(::Vertx::Util::Utils.to_json_object(options))),::VertxCircuitBreaker::CircuitBreaker)
      end
      raise ArgumentError, "Invalid arguments when calling create(#{name},#{vertx},#{options})"
    end

### + (`Object`) j_api_type

    29
    30
    31
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 29

    def self.j_api_type
      @@j_api_type
    end

### + (`Object`) j_class

    32
    33
    34
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 32

    def self.j_class
      Java::IoVertxCircuitbreaker::CircuitBreaker.java_class
    end

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

    26
    27
    28
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 26

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

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

    23
    24
    25
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 23

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

## Instance Method Details

### - (`self`) close

Closes the circuit breaker. It stops sending events on its state on the event bus. This method is not related to the `close` state of the circuit breaker. To set the circuit breaker in the `close` state, use #reset.

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    52
    53
    54
    55
    56
    57
    58
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 52

    def close
      if !block_given?
        @j_del.java_method(:close, []).call()
        return self
      end
      raise ArgumentError, "Invalid arguments when calling close()"
    end

### - (`self`) close_handler { ... }

Sets a invoked when the circuit breaker state switches to close.

Yields:

- the handler, must not be `null`

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    82
    83
    84
    85
    86
    87
    88
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 82

    def close_handler
      if block_given?
        @j_del.java_method(:closeHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield })
        return self
      end
      raise ArgumentError, "Invalid arguments when calling close_handler()"
    end

### - (`::Vertx::Future`) execute { ... }

Same as #execute_with_fallback but using the circuit breaker default fallback.

Yields:

- the operation

Returns:

- (`::Vertx::Future`) —
  a future object completed when the operation or its fallback completes

Raises:

- (`ArgumentError`)

    124
    125
    126
    127
    128
    129
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 124

    def execute
      if block_given?
        return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:execute, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::Promise, nil)) })),::Vertx::Future, nil)
      end
      raise ArgumentError, "Invalid arguments when calling execute()"
    end

### - (`self`) execute_and_report(resultPromise = nil) { ... }

Same as #execute_and_report_with_fallback but using the circuit breaker default fallback.

Parameters:

- resultPromise (`::Vertx::Promise`) (defaults to: `nil`) —
  the promise on which the operation result is reported

Yields:

- the operation

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    145
    146
    147
    148
    149
    150
    151
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 145

    def execute_and_report(resultPromise=nil)
      if resultPromise.class.method_defined?(:j_del) && block_given?
        @j_del.java_method(:executeAndReport, [Java::IoVertxCore::Promise.java_class,Java::IoVertxCore::Handler.java_class]).call(resultPromise.j_del,(Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::Promise, nil)) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling execute_and_report(#{resultPromise})"
    end

### - (`self`) execute_and_report_with_fallback(resultPromise = nil, command = nil, fallback = nil) { ... }

Executes the given operation with the circuit breaker control. The operation is generally calling an external system. The operation receives a object as parameter and must call when the operation has terminated successfully. The operation must also call in case of failure.

The operation is not invoked if the circuit breaker is open, and the given fallback is called immediately. The circuit breaker also monitor the completion of the operation before a configure timeout. The operation is considered as failed if it does not terminate in time.

Unlike #execute_with_fallback, this method does return a object, but let the caller pass a object on which the result is reported. If the fallback is called, the promise is successfully completed with the value returned by the fallback function. If the fallback throws an exception, the promise is marked as failed.

Parameters:

- resultPromise (`::Vertx::Promise`) (defaults to: `nil`) —
  the promise on which the operation result is reported
- command (`Proc`) (defaults to: `nil`) —
  the operation

Yields:

- the fallback function. It gets an exception as parameter and returns the fallback result

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    169
    170
    171
    172
    173
    174
    175
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 169

    def execute_and_report_with_fallback(resultPromise=nil,command=nil,fallback=nil)
      if resultPromise.class.method_defined?(:j_del) && command.class == Proc && block_given? && fallback == nil
        @j_del.java_method(:executeAndReportWithFallback, [Java::IoVertxCore::Promise.java_class,Java::IoVertxCore::Handler.java_class,Java::JavaUtilFunction::Function.java_class]).call(resultPromise.j_del,(Proc.new { |event| command.call(::Vertx::Util::Utils.safe_create(event,::Vertx::Promise, nil)) }),(Proc.new { |event| ::Vertx::Util::Utils.to_object(yield(::Vertx::Util::Utils.from_throwable(event))) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling execute_and_report_with_fallback(#{resultPromise},#{command},#{fallback})"
    end

### - (`void`) execute_command(command = nil) { ... }

This method returns an undefined value.

Same as #execute_with_fallback but using the circuit breaker default fallback.

Parameters:

- command (`Proc`) (defaults to: `nil`) —
  the operation

Yields:

- the completion handler receiving either the operation result or the fallback result. The parameter is an because if the fallback is not called, the error is passed to the handler.

Raises:

- (`ArgumentError`)

    134
    135
    136
    137
    138
    139
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 134

    def execute_command(command=nil)
      if command.class == Proc && block_given?
        return @j_del.java_method(:executeCommand, [Java::IoVertxCore::Handler.java_class,Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| command.call(::Vertx::Util::Utils.safe_create(event,::Vertx::Promise, nil)) }),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.from_object(ar.result) : nil) }))
      end
      raise ArgumentError, "Invalid arguments when calling execute_command(#{command})"
    end

### - (`void`) execute_command_with_fallback(command = nil, fallback = nil) { ... }

This method returns an undefined value.

Same as #execute_with_fallback but using a callback.

Parameters:

- command (`Proc`) (defaults to: `nil`) —
  the operation
- fallback (`Proc`) (defaults to: `nil`) —
  the fallback

Yields:

- the completion handler receiving either the operation result or the fallback result. The parameter is an because if the fallback is not called, the error is passed to the handler.

Raises:

- (`ArgumentError`)

    115
    116
    117
    118
    119
    120
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 115

    def execute_command_with_fallback(command=nil,fallback=nil)
      if command.class == Proc && fallback.class == Proc && block_given?
        return @j_del.java_method(:executeCommandWithFallback, [Java::IoVertxCore::Handler.java_class,Java::JavaUtilFunction::Function.java_class,Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| command.call(::Vertx::Util::Utils.safe_create(event,::Vertx::Promise, nil)) }),(Proc.new { |event| ::Vertx::Util::Utils.to_object(fallback.call(::Vertx::Util::Utils.from_throwable(event))) }),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.from_object(ar.result) : nil) }))
      end
      raise ArgumentError, "Invalid arguments when calling execute_command_with_fallback(#{command},#{fallback})"
    end

### - (`::Vertx::Future`) execute_with_fallback(command = nil, fallback = nil) { ... }

Executes the given operation with the circuit breaker control. The operation is generally calling an external system. The operation receives a object as parameter and must call when the operation has terminated successfully. The operation must also call in case of failure.

The operation is not invoked if the circuit breaker is open, and the given fallback is called immediately. The circuit breaker also monitor the completion of the operation before a configure timeout. The operation is considered as failed if it does not terminate in time.

This method returns a object to retrieve the status and result of the operation, with the status being a success or a failure. If the fallback is called, the returned future is successfully completed with the value returned from the fallback. If the fallback throws an exception, the returned future is marked as failed.

Parameters:

- command (`Proc`) (defaults to: `nil`) —
  the operation

Yields:

- the fallback function. It gets an exception as parameter and returns the fallback result

Returns:

- (`::Vertx::Future`) —
  a future object completed when the operation or its fallback completes

Raises:

- (`ArgumentError`)

    104
    105
    106
    107
    108
    109
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 104

    def execute_with_fallback(command=nil,fallback=nil)
      if command.class == Proc && block_given? && fallback == nil
        return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:executeWithFallback, [Java::IoVertxCore::Handler.java_class,Java::JavaUtilFunction::Function.java_class]).call((Proc.new { |event| command.call(::Vertx::Util::Utils.safe_create(event,::Vertx::Promise, nil)) }),(Proc.new { |event| ::Vertx::Util::Utils.to_object(yield(::Vertx::Util::Utils.from_throwable(event))) })),::Vertx::Future, nil)
      end
      raise ArgumentError, "Invalid arguments when calling execute_with_fallback(#{command},#{fallback})"
    end

### - (`Fixnum`) failure_count

Returns the current number of failures.

Returns:

- (`Fixnum`) —
  the current number of failures.

Raises:

- (`ArgumentError`)

    215
    216
    217
    218
    219
    220
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 215

    def failure_count
      if !block_given?
        return @j_del.java_method(:failureCount, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling failure_count()"
    end

### - (`self`) fallback(handler = nil) { ... }

Sets a default invoked when the bridge is open to handle the "request", or on failure if Hash#is_fallback_on_failure is enabled.

The function gets the exception as parameter and returns the fallback result.

Yields:

- the handler

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    182
    183
    184
    185
    186
    187
    188
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 182

    def fallback(handler=nil)
      if block_given? && handler == nil
        @j_del.java_method(:fallback, [Java::JavaUtilFunction::Function.java_class]).call((Proc.new { |event| ::Vertx::Util::Utils.to_object(yield(::Vertx::Util::Utils.from_throwable(event))) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling fallback(#{handler})"
    end

### - (`self`) half_open_handler { ... }

Sets a invoked when the circuit breaker state switches to half-open.

Yields:

- the handler, must not be `null`

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    72
    73
    74
    75
    76
    77
    78
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 72

    def half_open_handler
      if block_given?
        @j_del.java_method(:halfOpenHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield })
        return self
      end
      raise ArgumentError, "Invalid arguments when calling half_open_handler()"
    end

### - (`String`) name

Returns the name of the circuit breaker.

Returns:

- (`String`) —
  the name of the circuit breaker.

Raises:

- (`ArgumentError`)

    222
    223
    224
    225
    226
    227
    228
    229
    230
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 222

    def name
      if !block_given?
        if @cached_name != nil
          return @cached_name
        end
        return @cached_name = @j_del.java_method(:name, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling name()"
    end

### - (`self`) open

Explicitly opens the circuit.

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    200
    201
    202
    203
    204
    205
    206
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 200

    def open
      if !block_given?
        @j_del.java_method(:open, []).call()
        return self
      end
      raise ArgumentError, "Invalid arguments when calling open()"
    end

### - (`self`) open_handler { ... }

Sets a invoked when the circuit breaker state switches to open.

Yields:

- the handler, must not be `null`

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    62
    63
    64
    65
    66
    67
    68
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 62

    def open_handler
      if block_given?
        @j_del.java_method(:openHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield })
        return self
      end
      raise ArgumentError, "Invalid arguments when calling open_handler()"
    end

### - (`self`) reset

Resets the circuit breaker state (number of failure set to 0 and state set to closed).

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    191
    192
    193
    194
    195
    196
    197
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 191

    def reset
      if !block_given?
        @j_del.java_method(:reset, []).call()
        return self
      end
      raise ArgumentError, "Invalid arguments when calling reset()"
    end

### - (`self`) retry_policy(retryPolicy = nil) { ... }

Yields:

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    233
    234
    235
    236
    237
    238
    239
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 233

    def retry_policy(retryPolicy=nil)
      if block_given? && retryPolicy == nil
        @j_del.java_method(:retryPolicy, [Java::JavaUtilFunction::Function.java_class]).call((Proc.new { |event| yield(event) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling retry_policy(#{retryPolicy})"
    end

### - (`:OPEN`, ...) state

Returns the current state.

Returns:

- (`:OPEN`, `:CLOSED`, `:HALF_OPEN`) —
  the current state.

Raises:

- (`ArgumentError`)

    208
    209
    210
    211
    212
    213
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 208

    def state
      if !block_given?
        return @j_del.java_method(:state, []).call().name.intern
      end
      raise ArgumentError, "Invalid arguments when calling state()"
    end