Class: VertxCircuitBreaker::CircuitBreaker

Inherits:
Object
  • Object
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)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


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

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

+ (::VertxCircuitBreaker::CircuitBreaker) create(name, vertx) + (::VertxCircuitBreaker::CircuitBreaker) create(name, vertx, options)

Creates a new instance of VertxCircuitBreaker::CircuitBreaker.

Overloads:

Returns:



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

def self.create(*args)
  if args[0].class == String && args[1].class.method_defined?(:j_del) && !block_given? && args[2] == 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(args[0],args[1].j_del),::VertxCircuitBreaker::CircuitBreaker)
  elsif args[0].class == String && args[1].class.method_defined?(:j_del) && args[2].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(args[0],args[1].j_del,Java::IoVertxCircuitbreaker::CircuitBreakerOptions.new(::Vertx::Util::Utils.to_json_object(args[2]))),::VertxCircuitBreaker::CircuitBreaker)
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling create(#{args[0]},#{args[1]},#{args[2]})"
  end
end

+ (Object) j_api_type



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

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



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

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

+ (Object) unwrap(obj)



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

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

+ (Object) wrap(obj)



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

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)


269
270
271
272
273
274
275
276
277
278
279
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 269

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

- (self) closeHandler(handler) { ... }

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

Yields:

  • the handler, must not be null

Returns:

  • (self)


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

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

- (void) execute(command, handler) { ... }

This method returns an undefined value.

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

Parameters:

  • command (Proc)
    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.


138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 138

def execute(*args)
  if args[0].class == Proc && true
    if (block_given?)
      return @j_del.java_method(:execute, [Java::IoVertxCore::Handler.java_class,Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| args[0].call(::Vertx::Util::Utils.safe_create(event,::Vertx::Promise, nil)) unless args[0] == nil }),block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.from_object(ar.result) : nil) } : promise)
    else
      promise = ::Vertx::Util::Utils.promise
      @j_del.java_method(:execute, [Java::IoVertxCore::Handler.java_class,Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| args[0].call(::Vertx::Util::Utils.safe_create(event,::Vertx::Promise, nil)) unless args[0] == nil }),block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.from_object(ar.result) : nil) } : promise)
      return ::Vertx::Util::Utils.safe_create(promise.future(),::Vertx::Future, nil)
    end
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling execute(#{args[0]})"
  end
end

- (self) executeAndReport(resultPromise, command) { ... }

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

Parameters:

  • resultPromise (::Vertx::Promise)
    the promise on which the operation result is reported

Yields:

  • the operation

Returns:

  • (self)


78
79
80
81
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 78

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

- (self) executeAndReportWithFallback(resultPromise, command, fallback) { ... }

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 future is successfully completed with the value returned by the fallback function. If the fallback throws an exception, the future is marked as failed.

Parameters:

  • resultPromise (::Vertx::Promise)
    the promise on which the operation result is reported
  • command (Proc)
    the operation

Yields:

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

Returns:

  • (self)


107
108
109
110
111
112
113
114
115
116
117
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 107

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

- (void) executeWithFallback(command, fallback, handler) { ... }

This method returns an undefined value.

Same as #execute_with_fallback but using a callback.

Parameters:

  • command (Proc)
    the operation
  • fallback (Proc)
    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.


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 56

def execute_with_fallback(*args)
  if args[0].class == Proc && args[1].class == Proc && true
    if (block_given?)
      return @j_del.java_method(:executeWithFallback, [Java::IoVertxCore::Handler.java_class,Java::JavaUtilFunction::Function.java_class,Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| args[0].call(::Vertx::Util::Utils.safe_create(event,::Vertx::Promise, nil)) unless args[0] == nil }),(Proc.new { |event| ::Vertx::Util::Utils.to_object(args[1].call(::Vertx::Util::Utils.from_throwable(event))) unless args[1] == nil }),block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.from_object(ar.result) : nil) } : promise)
    else
      promise = ::Vertx::Util::Utils.promise
      @j_del.java_method(:executeWithFallback, [Java::IoVertxCore::Handler.java_class,Java::JavaUtilFunction::Function.java_class,Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| args[0].call(::Vertx::Util::Utils.safe_create(event,::Vertx::Promise, nil)) unless args[0] == nil }),(Proc.new { |event| ::Vertx::Util::Utils.to_object(args[1].call(::Vertx::Util::Utils.from_throwable(event))) unless args[1] == nil }),block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.from_object(ar.result) : nil) } : promise)
      return ::Vertx::Util::Utils.safe_create(promise.future(),::Vertx::Future, nil)
    end
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling execute_with_fallback(#{args[0]},#{args[1]})"
  end
end

- (Fixnum) failureCount

Returns the current number of failures.

Returns:

  • (Fixnum)
    the current number of failures.


282
283
284
285
286
287
288
289
290
291
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 282

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

- (self) fallback(handler) { ... }

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

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

Yields:

  • the handler

Returns:

  • (self)


253
254
255
256
257
258
259
260
261
262
263
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 253

def fallback(*args)
  if block_given? && args[0] == 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))) unless !block_given? }))
    return self
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling fallback(#{args[0]})"
  end
end

- (self) halfOpenHandler(handler) { ... }

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

Yields:

  • the handler, must not be null

Returns:

  • (self)


202
203
204
205
206
207
208
209
210
211
212
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 202

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

- (String) name

Returns the name of the circuit breaker.

Returns:

  • (String)
    the name of the circuit breaker.


171
172
173
174
175
176
177
178
179
180
181
182
183
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 171

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

- (self) open

Explicitly opens the circuit.

Returns:

  • (self)


295
296
297
298
299
300
301
302
303
304
305
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 295

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

- (self) openHandler(handler) { ... }

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

Yields:

  • the handler, must not be null

Returns:

  • (self)


158
159
160
161
162
163
164
165
166
167
168
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 158

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

- (self) reset

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

Returns:

  • (self)


187
188
189
190
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 187

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

- (self) retryPolicy(retryPolicy) { ... }

Yields:

Returns:

  • (self)


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

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

- (:OPEN, ...) state

Returns the current state.

Returns:

  • (:OPEN, :CLOSED, :HALF_OPEN)
    the current state.


236
237
238
239
240
241
242
243
244
245
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 236

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