Class: Orientdb4r::LBStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/orientdb4r/load_balancing.rb

Overview

Base class for implementation of load balancing strategy.

Direct Known Subclasses

RoundRobin, Sequence

Constant Summary collapse

DEFAULT_RECOVER_TIME =

After what time [s] can be a failed node reused in load balancing.

30

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nodesObject (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_countObject (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_timeObject

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_indexObject

Gets index of node to be used for next request or ‘nil’ if there is no one next.

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/orientdb4r/load_balancing.rb', line 24

def node_index
  raise NotImplementedError, 'this should be overridden in subclass'
end