Class: WSDirector::Result
- Inherits:
-
Object
- Object
- WSDirector::Result
- Defined in:
- lib/wsdirector/result.rb
Overview
Handle results from all clients from the group
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
Instance Method Summary collapse
-
#failed(error_message) ⇒ Object
Called when client failed.
- #failures_count ⇒ Object
-
#initialize(group) ⇒ Result
constructor
A new instance of Result.
-
#succeed ⇒ Object
Called when client successfully finished it’s work.
- #success? ⇒ Boolean
- #total_count ⇒ Object
- #track_sample(id, max) ⇒ Object
Constructor Details
#initialize(group) ⇒ Result
Returns a new instance of Result.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/wsdirector/result.rb', line 8 def initialize(group) @group = group @errors = Concurrent::Array.new @all = Concurrent::AtomicFixnum.new(0) @failures = Concurrent::AtomicFixnum.new(0) @sampling_mutex = Mutex.new @sampling_counter = Hash.new { |h, k| h[k] = 0 } end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/wsdirector/result.rb', line 6 def errors @errors end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
6 7 8 |
# File 'lib/wsdirector/result.rb', line 6 def group @group end |
Instance Method Details
#failed(error_message) ⇒ Object
Called when client failed
25 26 27 28 29 |
# File 'lib/wsdirector/result.rb', line 25 def failed() errors << all.increment failures.increment end |
#failures_count ⇒ Object
39 40 41 |
# File 'lib/wsdirector/result.rb', line 39 def failures_count failures.value end |
#succeed ⇒ Object
Called when client successfully finished it’s work
20 21 22 |
# File 'lib/wsdirector/result.rb', line 20 def succeed all.increment end |
#success? ⇒ Boolean
31 32 33 |
# File 'lib/wsdirector/result.rb', line 31 def success? failures.value.zero? end |
#total_count ⇒ Object
35 36 37 |
# File 'lib/wsdirector/result.rb', line 35 def total_count all.value end |
#track_sample(id, max) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/wsdirector/result.rb', line 43 def track_sample(id, max) sampling_mutex.synchronize do return false if sampling_counter[id] >= max sampling_counter[id] += 1 true end end |