Class: XRBP::WebSocket::MultiConnection
- Inherits:
-
Object
- Object
- XRBP::WebSocket::MultiConnection
- Includes:
- EventEmitter
- Defined in:
- lib/xrbp/websocket/multi/multi_connection.rb
Overview
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.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#connections ⇒ Object
readonly
Returns the value of attribute connections.
Instance Method Summary collapse
- #_add_plugin ⇒ Object
- #add_plugin(*plg) ⇒ Object
-
#close! ⇒ Object
Close all connections.
- #connect ⇒ Object
-
#force_quit! ⇒ Object
Force terminate all connections.
-
#initialize(*urls) {|_self| ... } ⇒ MultiConnection
constructor
MultiConnection initializer taking list of urls which to connect to.
-
#next_connection(prev = nil) ⇒ Object
Always return first connection by default, override in subclasses.
- #plugin_namespace ⇒ Object
-
#wait_for_close ⇒ Object
Block until all connections are closed.
-
#wait_for_completed ⇒ Object
Block until all connections are completed.
-
#wait_for_open ⇒ Object
Block until all connections are openend.
Constructor Details
#initialize(*urls) {|_self| ... } ⇒ MultiConnection
MultiConnection initializer taking list of urls which to connect to
29 30 31 32 33 34 35 36 37 38 39 |
# 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 |
Instance Attribute Details
#connections ⇒ Object (readonly)
Returns the value of attribute connections.
22 23 24 |
# File 'lib/xrbp/websocket/multi/multi_connection.rb', line 22 def connections @connections end |
Instance Method Details
#_add_plugin ⇒ Object
66 |
# File 'lib/xrbp/websocket/multi/multi_connection.rb', line 66 alias :_add_plugin :add_plugin |
#add_plugin(*plg) ⇒ Object
68 69 70 71 72 73 74 |
# 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! ⇒ Object
Close all connections
47 48 49 |
# File 'lib/xrbp/websocket/multi/multi_connection.rb', line 47 def close! connections.each { |c| c.close! } end |
#connect ⇒ Object
83 84 85 86 87 |
# File 'lib/xrbp/websocket/multi/multi_connection.rb', line 83 def connect @connections.each { |c| c.connect } end |
#force_quit! ⇒ Object
Force terminate all connections
42 43 44 |
# File 'lib/xrbp/websocket/multi/multi_connection.rb', line 42 def force_quit! connections.each { |c| c.force_quit! } end |
#next_connection(prev = nil) ⇒ Object
Always return first connection by default, override in subclasses
78 79 80 81 |
# 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 ⇒ Object
18 19 20 |
# File 'lib/xrbp/websocket/multi/multi_connection.rb', line 18 def plugin_namespace WebSocket end |
#wait_for_close ⇒ Object
Block until all connections are closed
57 58 59 |
# 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 ⇒ Object
Block until all connections are completed
62 63 64 |
# 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 ⇒ Object
Block until all connections are openend
52 53 54 |
# File 'lib/xrbp/websocket/multi/multi_connection.rb', line 52 def wait_for_open connections.each { |c| c.wait_for_open } end |