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:



262
263
264
265
266
267
268
269
270
271
272
273
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 262

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)


309
310
311
312
313
314
315
316
317
318
319
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 309

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)


148
149
150
151
152
153
154
155
156
157
158
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 148

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

- (::Vertx::Future) execute(command) { ... }

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


184
185
186
187
188
189
190
191
192
193
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 184

def execute
  if true
    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)) unless !block_given? })),::Vertx::Future, nil)
  end
  if defined?(super)
    super
  else
    raise ArgumentError, "Invalid arguments when calling execute()"
  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)


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

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)


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

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) executeCommand(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.


164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 164

def execute_command(*args)
  if args[0].class == Proc && true
    if (block_given?)
      return @j_del.java_method(:executeCommand, [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(:executeCommand, [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_command(#{args[0]})"
  end
end

- (void) executeCommandWithFallback(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.


128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 128

def execute_command_with_fallback(*args)
  if args[0].class == Proc && args[1].class == Proc && true
    if (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| 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(:executeCommandWithFallback, [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_command_with_fallback(#{args[0]},#{args[1]})"
  end
end

- (::Vertx::Future) executeWithFallback(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.

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


66
67
68
69
70
71
72
73
74
75
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 66

def execute_with_fallback(*args)
  if args[0].class == Proc && block_given? && args[1] == 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| args[0].call(::Vertx::Util::Utils.safe_create(event,::Vertx::Promise, nil)) unless args[0] == nil }),(Proc.new { |event| ::Vertx::Util::Utils.to_object(yield(::Vertx::Util::Utils.from_throwable(event))) unless !block_given? })),::Vertx::Future, nil)
  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.


322
323
324
325
326
327
328
329
330
331
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 322

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)


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

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)


242
243
244
245
246
247
248
249
250
251
252
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 242

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.


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

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)


335
336
337
338
339
340
341
342
343
344
345
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 335

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)


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

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)


227
228
229
230
231
232
233
234
235
236
237
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 227

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.


276
277
278
279
280
281
282
283
284
285
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb', line 276

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