Class: VertxCircuitBreaker::CircuitBreaker
- Inherits:
-
Object
- Object
- VertxCircuitBreaker::CircuitBreaker
- Defined in:
- /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-circuit-breaker/circuit_breaker.rb
Overview
Constant Summary
- @@j_api_type =
Object.new
Class Method Summary (collapse)
- + (Boolean) accept?(obj)
-
+ (::VertxCircuitBreaker::CircuitBreaker) create(*args)
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) closeHandler(handler) { ... }
Sets a invoked when the circuit breaker state switches to close.
-
- (::Vertx::Future) execute(command) { ... }
Same as #execute_with_fallback but using the circuit breaker default fallback.
-
- (self) executeAndReport(resultPromise, command) { ... }
Same as #execute_and_report_with_fallback but using the circuit breaker default fallback.
-
- (self) executeAndReportWithFallback(resultPromise, command, fallback) { ... }
Executes the given operation with the circuit breaker control.
-
- (void) executeCommand(command, handler) { ... }
Same as #execute_with_fallback but using the circuit breaker default fallback.
-
- (void) executeCommandWithFallback(command, fallback, handler) { ... }
Same as #execute_with_fallback but using a callback.
-
- (::Vertx::Future) executeWithFallback(command, fallback) { ... }
Executes the given operation with the circuit breaker control.
-
- (Fixnum) failureCount
The current number of failures.
-
- (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.
-
- (self) halfOpenHandler(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) openHandler(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) retryPolicy(retryPolicy) { ... }
-
- (:OPEN, ...) state
The current state.
Class Method Details
+ (Boolean) accept?(obj)
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)
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
close
state of the circuit breaker. To set the circuit breaker in the
close
state, use #reset.
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) { ... }
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) { ... }
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) { ... }
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) { ... }
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.
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.
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.
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) { ... }
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.
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
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) { ... }
The function gets the exception as parameter and returns the fallback result.
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) { ... }
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
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
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) { ... }
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
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) { ... }
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
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 |