Class: Orientdb4r::LBStrategy
- Inherits:
-
Object
- Object
- Orientdb4r::LBStrategy
- Defined in:
- lib/orientdb4r/load_balancing.rb
Overview
Base class for implementation of load balancing strategy.
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_RECOVER_TIME =
After what time [s] can be a failed node reused in load balancing.
30
Instance Attribute Summary collapse
-
#bad_nodes ⇒ Object
readonly
Returns the value of attribute bad_nodes.
-
#nodes_count ⇒ Object
readonly
Returns the value of attribute nodes_count.
-
#recover_time ⇒ Object
Returns the value of attribute recover_time.
Instance Method Summary collapse
-
#bad_one(idx) ⇒ Object
Marks an index as bad that means it will be not used until: * there is other ‘good’ node * timeout.
-
#good_one(idx) ⇒ Object
Marks an index as good that means it can be used for next server calls.
-
#initialize(nodes_count) ⇒ LBStrategy
constructor
Constructor.
-
#node_index ⇒ Object
Gets index of node to be used for next request or ‘nil’ if there is no one next.
Constructor Details
#initialize(nodes_count) ⇒ LBStrategy
Constructor.
15 16 17 18 19 |
# File 'lib/orientdb4r/load_balancing.rb', line 15 def initialize nodes_count @nodes_count = nodes_count @bad_nodes = {} @recover_time = DEFAULT_RECOVER_TIME end |
Instance Attribute Details
#bad_nodes ⇒ Object (readonly)
Returns the value of attribute bad_nodes.
10 11 12 |
# File 'lib/orientdb4r/load_balancing.rb', line 10 def bad_nodes @bad_nodes end |
#nodes_count ⇒ Object (readonly)
Returns the value of attribute nodes_count.
10 11 12 |
# File 'lib/orientdb4r/load_balancing.rb', line 10 def nodes_count @nodes_count end |
#recover_time ⇒ Object
Returns the value of attribute recover_time.
11 12 13 |
# File 'lib/orientdb4r/load_balancing.rb', line 11 def recover_time @recover_time end |
Instance Method Details
#bad_one(idx) ⇒ Object
Marks an index as bad that means it will be not used until:
-
there is other ‘good’ node
-
timeout
38 39 40 |
# File 'lib/orientdb4r/load_balancing.rb', line 38 def bad_one(idx) @bad_nodes[idx] = Time.now end |
#good_one(idx) ⇒ Object
Marks an index as good that means it can be used for next server calls.
30 31 32 |
# File 'lib/orientdb4r/load_balancing.rb', line 30 def good_one(idx) @bad_nodes.delete idx end |
#node_index ⇒ Object
Gets index of node to be used for next request or ‘nil’ if there is no one next.
24 25 26 |
# File 'lib/orientdb4r/load_balancing.rb', line 24 def node_index raise NotImplementedError, 'this should be overridden in subclass' end |