Class: DRb::DRbConn
- Inherits:
-
Object
- Object
- DRb::DRbConn
- Defined in:
- lib/opal/drb/drb_conn.rb
Constant Summary collapse
- POOL_SIZE =
16
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #alive? ⇒ Boolean
- #close ⇒ Object
-
#initialize(remote_uri) ⇒ DRbConn
constructor
A new instance of DRbConn.
- #send_message(ref, msg_id, arg, b, &callback) ⇒ Object
Constructor Details
#initialize(remote_uri) ⇒ DRbConn
Returns a new instance of DRbConn.
34 35 36 37 |
# File 'lib/opal/drb/drb_conn.rb', line 34 def initialize(remote_uri) @uri = remote_uri @protocol = DRbProtocol.open(remote_uri, DRb::default_config) end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
38 39 40 |
# File 'lib/opal/drb/drb_conn.rb', line 38 def uri @uri end |
Class Method Details
.open(remote_uri) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/opal/drb/drb_conn.rb', line 6 def self.open(remote_uri) begin conn = nil @pool = @pool.each_with_object([]) do |c, new_pool| if conn.nil? and c.uri == remote_uri conn = c if c.alive? else new_pool.push c end end conn = self.new(remote_uri) unless conn succ, result = yield(conn) return succ, result ensure if conn if succ @pool.unshift(conn) @pool.pop.close while @pool.size > POOL_SIZE else conn.close end end end end |
Instance Method Details
#alive? ⇒ Boolean
51 52 53 54 |
# File 'lib/opal/drb/drb_conn.rb', line 51 def alive? return false unless @protocol @protocol.alive? end |
#close ⇒ Object
46 47 48 49 |
# File 'lib/opal/drb/drb_conn.rb', line 46 def close @protocol.close @protocol = nil end |
#send_message(ref, msg_id, arg, b, &callback) ⇒ Object
40 41 42 43 44 |
# File 'lib/opal/drb/drb_conn.rb', line 40 def (ref, msg_id, arg, b, &callback) @protocol.send_request(ref, msg_id, arg, b).then do |stream| callback.call(@protocol.recv_reply(stream)) end end |