class XRBP::WebSocket::MultiConnection
Base class facilitating transparent multiple connection dispatching. This provides mechanism which to instantiate multiple WebSocket::Connection
instances proxying requests to them depending on the next_connection selected.
This class provides all the common logic to manage multiple connections. Subclasses should override and implement next_connection specifying the strategy used to select the connection to use for any given request.
Attributes
Public Class Methods
MultiConnection
initializer taking list of urls which to connect to
@param urls [Array<String>] list of urls which to establish
connections to
# File lib/xrbp/websocket/multi/multi_connection.rb, line 29 def initialize(*urls) @connections = [] urls.each { |url| @connections << Connection.new(url) } connections.each { |c| c.parent = self } yield self if block_given? end
Public Instance Methods
# File lib/xrbp/websocket/multi/multi_connection.rb, line 68 def add_plugin(*plg) connections.each { |c| c.add_plugin *plg } _add_plugin(*plg) end
Close all connections
# File lib/xrbp/websocket/multi/multi_connection.rb, line 47 def close! connections.each { |c| c.close! } end
# File lib/xrbp/websocket/multi/multi_connection.rb, line 83 def connect @connections.each { |c| c.connect } end
Force terminate all connections
# File lib/xrbp/websocket/multi/multi_connection.rb, line 42 def force_quit! connections.each { |c| c.force_quit! } end
Always return first connection by default, override in subclasses
# File lib/xrbp/websocket/multi/multi_connection.rb, line 78 def next_connection(prev=nil) return nil unless prev.nil? @connections.first end
# File lib/xrbp/websocket/multi/multi_connection.rb, line 18 def plugin_namespace WebSocket end
Block until all connections are closed
# File lib/xrbp/websocket/multi/multi_connection.rb, line 57 def wait_for_close connections.each { |c| c.wait_for_close } end
Block until all connections are completed
# File lib/xrbp/websocket/multi/multi_connection.rb, line 62 def wait_for_completed connections.each { |c| c.wait_for_completed } end
Block until all connections are openend
# File lib/xrbp/websocket/multi/multi_connection.rb, line 52 def wait_for_open connections.each { |c| c.wait_for_open } end