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

connections[R]

Public Class Methods

new(*urls) { |self| ... } click to toggle source

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

_add_plugin(*plg)
Alias for: add_plugin
add_plugin(*plg) click to toggle source
# 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
Also aliased as: _add_plugin
close!() click to toggle source

Close all connections

# File lib/xrbp/websocket/multi/multi_connection.rb, line 47
def close!
  connections.each { |c| c.close! }
end
connect() click to toggle source
# File lib/xrbp/websocket/multi/multi_connection.rb, line 83
def connect
  @connections.each { |c|
    c.connect
  }
end
force_quit!() click to toggle source

Force terminate all connections

# File lib/xrbp/websocket/multi/multi_connection.rb, line 42
def force_quit!
  connections.each { |c| c.force_quit! }
end
next_connection(prev=nil) click to toggle source

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
plugin_namespace() click to toggle source
# File lib/xrbp/websocket/multi/multi_connection.rb, line 18
def plugin_namespace
  WebSocket
end
wait_for_close() click to toggle source

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
wait_for_completed() click to toggle source

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
wait_for_open() click to toggle source

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