Class: Quark::MdkDiscovery::CircuitBreaker
- Inherits:
-
DatawireQuarkCore::QuarkObject
- Object
- DatawireQuarkCore::QuarkObject
- Quark::MdkDiscovery::CircuitBreaker
- Extended by:
- DatawireQuarkCore::Static
- Defined in:
- lib/mdk_discovery.rb
Overview
Default circuit breaker policy.
Constant Summary
Constants included from DatawireQuarkCore::Static
DatawireQuarkCore::Static::Unassigned
Instance Attribute Summary collapse
-
#_delay ⇒ Object
Returns the value of attribute _delay.
-
#_failed ⇒ Object
Returns the value of attribute _failed.
-
#_failures ⇒ Object
Returns the value of attribute _failures.
-
#_lastFailure ⇒ Object
Returns the value of attribute _lastFailure.
-
#_log ⇒ Object
Returns the value of attribute _log.
-
#_mutex ⇒ Object
Returns the value of attribute _mutex.
-
#_threshold ⇒ Object
Returns the value of attribute _threshold.
-
#_time ⇒ Object
Returns the value of attribute _time.
Instance Method Summary collapse
- #__init_fields__ ⇒ Object
- #_getClass ⇒ Object
- #_getField(name) ⇒ Object
- #_setField(name, value) ⇒ Object
- #available ⇒ Object
- #failure ⇒ Object
-
#initialize(time, threshold, retestDelay) ⇒ CircuitBreaker
constructor
A new instance of CircuitBreaker.
- #success ⇒ Object
Methods included from DatawireQuarkCore::Static
_lazy_statics, static, unlazy_statics
Methods inherited from DatawireQuarkCore::QuarkObject
Constructor Details
#initialize(time, threshold, retestDelay) ⇒ CircuitBreaker
Returns a new instance of CircuitBreaker.
760 761 762 763 764 765 766 767 768 |
# File 'lib/mdk_discovery.rb', line 760 def initialize(time, threshold, retestDelay) self.__init_fields__ @_threshold = threshold @_delay = retestDelay @_time = time nil end |
Instance Attribute Details
#_delay ⇒ Object
Returns the value of attribute _delay.
753 754 755 |
# File 'lib/mdk_discovery.rb', line 753 def _delay @_delay end |
#_failed ⇒ Object
Returns the value of attribute _failed.
753 754 755 |
# File 'lib/mdk_discovery.rb', line 753 def _failed @_failed end |
#_failures ⇒ Object
Returns the value of attribute _failures.
753 754 755 |
# File 'lib/mdk_discovery.rb', line 753 def _failures @_failures end |
#_lastFailure ⇒ Object
Returns the value of attribute _lastFailure.
753 754 755 |
# File 'lib/mdk_discovery.rb', line 753 def _lastFailure @_lastFailure end |
#_log ⇒ Object
Returns the value of attribute _log.
753 754 755 |
# File 'lib/mdk_discovery.rb', line 753 def _log @_log end |
#_mutex ⇒ Object
Returns the value of attribute _mutex.
753 754 755 |
# File 'lib/mdk_discovery.rb', line 753 def _mutex @_mutex end |
#_threshold ⇒ Object
Returns the value of attribute _threshold.
753 754 755 |
# File 'lib/mdk_discovery.rb', line 753 def _threshold @_threshold end |
#_time ⇒ Object
Returns the value of attribute _time.
753 754 755 |
# File 'lib/mdk_discovery.rb', line 753 def _time @_time end |
Instance Method Details
#__init_fields__ ⇒ Object
883 884 885 886 887 888 889 890 891 892 893 894 895 |
# File 'lib/mdk_discovery.rb', line 883 def __init_fields__() self._log = ::Quark.quark._getLogger("mdk.breaker") self._threshold = nil self._delay = nil self._time = nil self._mutex = ::DatawireQuarkCore::Lock.new() self._failed = false self._failures = 0 self._lastFailure = 0.0 nil end |
#_getClass ⇒ Object
815 816 817 818 819 820 |
# File 'lib/mdk_discovery.rb', line 815 def _getClass() return "mdk_discovery.CircuitBreaker" nil end |
#_getField(name) ⇒ Object
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 |
# File 'lib/mdk_discovery.rb', line 822 def _getField(name) if ((name) == ("_log")) return (self)._log end if ((name) == ("_threshold")) return (self)._threshold end if ((name) == ("_delay")) return (self)._delay end if ((name) == ("_time")) return (self)._time end if ((name) == ("_mutex")) return (self)._mutex end if ((name) == ("_failed")) return (self)._failed end if ((name) == ("_failures")) return (self)._failures end if ((name) == ("_lastFailure")) return (self)._lastFailure end return nil nil end |
#_setField(name, value) ⇒ Object
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 |
# File 'lib/mdk_discovery.rb', line 853 def _setField(name, value) if ((name) == ("_log")) (self)._log = value end if ((name) == ("_threshold")) (self)._threshold = ::DatawireQuarkCore.cast(value) { ::Integer } end if ((name) == ("_delay")) (self)._delay = ::DatawireQuarkCore.cast(value) { ::Float } end if ((name) == ("_time")) (self)._time = ::DatawireQuarkCore.cast(value) { ::Quark.mdk_runtime.Time } end if ((name) == ("_mutex")) (self)._mutex = ::DatawireQuarkCore.cast(value) { ::DatawireQuarkCore::Lock } end if ((name) == ("_failed")) (self)._failed = ::DatawireQuarkCore.cast(value) { ::Object } end if ((name) == ("_failures")) (self)._failures = ::DatawireQuarkCore.cast(value) { ::Integer } end if ((name) == ("_lastFailure")) (self)._lastFailure = ::DatawireQuarkCore.cast(value) { ::Float } end nil end |
#available ⇒ Object
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 |
# File 'lib/mdk_discovery.rb', line 798 def available() if (@_failed) @_mutex.acquire() result = ((@_time.time()) - (@_lastFailure)) > (@_delay) @_mutex.release() if (result) @_log.info("BREAKER RETEST.") end return result else return true end nil end |
#failure ⇒ Object
784 785 786 787 788 789 790 791 792 793 794 795 796 |
# File 'lib/mdk_discovery.rb', line 784 def failure() @_mutex.acquire() @_failures = (@_failures) + (1) @_lastFailure = @_time.time() if (((@_threshold) != (0)) && ((@_failures) >= (@_threshold))) @_log.info("BREAKER TRIPPED.") @_failed = true end @_mutex.release() nil end |
#success ⇒ Object
773 774 775 776 777 778 779 780 781 782 |
# File 'lib/mdk_discovery.rb', line 773 def success() @_mutex.acquire() @_failed = false @_failures = 0 @_lastFailure = 0.0 @_mutex.release() nil end |