Class: VertxCircuitBreaker::CircuitBreaker
- Inherits:
-
Object
- Object
- VertxCircuitBreaker::CircuitBreaker
- Defined in:
- /Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-circuit-breaker/circuit_breaker.rb
Overview
Class Method Summary (collapse)
-
+ (::VertxCircuitBreaker::CircuitBreaker) create(name = nil, vertx = nil, options = nil)
Creates a new instance of CircuitBreaker.
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(resultFuture = nil) { ... }
Same as #execute_and_report_with_fallback but using the circuit breaker default fallback.
-
- (self) execute_and_report_with_fallback(resultFuture = nil, operation = nil, fallback = nil) { ... }
Executes the given operation with the circuit breaker control.
-
- (::Vertx::Future) execute_with_fallback(operation = nil, fallback = nil) { ... }
Executes the given operation with the circuit breaker control.
-
- (Fixnum) failure_count
@return 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
@return 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).
-
- (:OPEN, ...) state
@return the current state.
Class Method Details
+ (::VertxCircuitBreaker::CircuitBreaker) create(name = nil, vertx = nil, options = nil)
23 24 25 26 27 28 29 30 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-circuit-breaker/circuit_breaker.rb', line 23 def self.create(name=nil,vertx=nil,=nil) if name.class == String && vertx.class.method_defined?(:j_del) && !block_given? && == 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) && .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())),::VertxCircuitBreaker::CircuitBreaker) end raise ArgumentError, "Invalid arguments when calling create(name,vertx,options)" end |
Instance Method Details
- (self) close
close
state of the circuit breaker. To set the circuit breaker in the
close
state, use #reset.
35 36 37 38 39 40 41 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-circuit-breaker/circuit_breaker.rb', line 35 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 { ... }
65 66 67 68 69 70 71 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-circuit-breaker/circuit_breaker.rb', line 65 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 { ... }
96 97 98 99 100 101 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-circuit-breaker/circuit_breaker.rb', line 96 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::Future)) })),::Vertx::Future) end raise ArgumentError, "Invalid arguments when calling execute()" end |
- (self) execute_and_report(resultFuture = nil) { ... }
107 108 109 110 111 112 113 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-circuit-breaker/circuit_breaker.rb', line 107 def execute_and_report(resultFuture=nil) if resultFuture.class.method_defined?(:j_del) && block_given? @j_del.java_method(:executeAndReport, [Java::IoVertxCore::Future.java_class,Java::IoVertxCore::Handler.java_class]).call(resultFuture.j_del,(Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::Future)) })) return self end raise ArgumentError, "Invalid arguments when calling execute_and_report(resultFuture)" end |
- (self) execute_and_report_with_fallback(resultFuture = nil, operation = nil, fallback = nil) { ... }
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.
131 132 133 134 135 136 137 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-circuit-breaker/circuit_breaker.rb', line 131 def execute_and_report_with_fallback(resultFuture=nil,operation=nil,fallback=nil) if resultFuture.class.method_defined?(:j_del) && operation.class == Proc && block_given? && fallback == nil @j_del.java_method(:executeAndReportWithFallback, [Java::IoVertxCore::Future.java_class,Java::IoVertxCore::Handler.java_class,Java::JavaUtilFunction::Function.java_class]).call(resultFuture.j_del,(Proc.new { |event| operation.call(::Vertx::Util::Utils.safe_create(event,::Vertx::Future)) }),(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(resultFuture,operation,fallback)" end |
- (::Vertx::Future) execute_with_fallback(operation = nil, fallback = nil) { ... }
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.
87 88 89 90 91 92 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-circuit-breaker/circuit_breaker.rb', line 87 def execute_with_fallback(operation=nil,fallback=nil) if operation.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| operation.call(::Vertx::Util::Utils.safe_create(event,::Vertx::Future)) }),(Proc.new { |event| ::Vertx::Util::Utils.to_object(yield(::Vertx::Util::Utils.from_throwable(event))) })),::Vertx::Future) end raise ArgumentError, "Invalid arguments when calling execute_with_fallback(operation,fallback)" end |
- (Fixnum) failure_count
179 180 181 182 183 184 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-circuit-breaker/circuit_breaker.rb', line 179 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) { ... }
The function gets the exception as parameter and returns the fallback result.
144 145 146 147 148 149 150 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-circuit-breaker/circuit_breaker.rb', line 144 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 { ... }
55 56 57 58 59 60 61 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-circuit-breaker/circuit_breaker.rb', line 55 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
187 188 189 190 191 192 193 194 195 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-circuit-breaker/circuit_breaker.rb', line 187 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
162 163 164 165 166 167 168 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-circuit-breaker/circuit_breaker.rb', line 162 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 { ... }
45 46 47 48 49 50 51 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-circuit-breaker/circuit_breaker.rb', line 45 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
153 154 155 156 157 158 159 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-circuit-breaker/circuit_breaker.rb', line 153 def reset if !block_given? @j_del.java_method(:reset, []).call() return self end raise ArgumentError, "Invalid arguments when calling reset()" end |
- (:OPEN, ...) state
171 172 173 174 175 176 |
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-circuit-breaker/circuit_breaker.rb', line 171 def state if !block_given? return @j_del.java_method(:state, []).call().name.intern end raise ArgumentError, "Invalid arguments when calling state()" end |