Class: XRBP::WebSocket::RoundRobin

Inherits:
MultiConnection show all
Defined in:
lib/xrbp/websocket/multi/round_robin.rb

Overview

MultiConnection strategy where connections selected in a circular-round robin manner, where the next connection is always used for the next request even if the current one succeeds.

Instance Attribute Summary

Attributes inherited from MultiConnection

#connections

Instance Method Summary collapse

Methods inherited from MultiConnection

#_add_plugin, #add_plugin, #close!, #connect, #force_quit!, #plugin_namespace, #wait_for_close, #wait_for_completed, #wait_for_open

Constructor Details

#initialize(*urls) ⇒ RoundRobin

Returns a new instance of RoundRobin.



8
9
10
11
# File 'lib/xrbp/websocket/multi/round_robin.rb', line 8

def initialize(*urls)
  super(*urls)
  @current = 0
end

Instance Method Details

#next_connection(prev = nil) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/xrbp/websocket/multi/round_robin.rb', line 13

def next_connection(prev=nil)
  return nil unless prev.nil?

  c = connections[@current]
  @current += 1
  @current  = 0 if @current >= connections.size
  c
end