Class: DRb::DRbConn

Inherits:
Object
  • Object
show all
Defined in:
lib/drb/drb_conn.rb

Constant Summary collapse

POOL_SIZE =
16

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(remote_uri) ⇒ DRbConn

Returns a new instance of DRbConn.



16
17
18
19
# File 'lib/drb/drb_conn.rb', line 16

def initialize(remote_uri)
  @uri = remote_uri
  @protocol = DRbProtocol.open(remote_uri, DRb::default_config)
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



20
21
22
# File 'lib/drb/drb_conn.rb', line 20

def uri
  @uri
end

Class Method Details

.open(remote_uri) {|conn| ... } ⇒ Object

Yields:

  • (conn)


6
7
8
9
10
11
12
13
14
# File 'lib/drb/drb_conn.rb', line 6

def self.open(remote_uri)
  conn = @pool[remote_uri]
  unless conn&.alive?
    conn = self.new(remote_uri)
    @pool[remote_uri] = conn
  end

  yield(conn)
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/drb/drb_conn.rb', line 33

def alive?
  return false unless @protocol
  @protocol.alive?
end

#closeObject



28
29
30
31
# File 'lib/drb/drb_conn.rb', line 28

def close
  @protocol.close
  @protocol = nil
end

#send_message(ref, msg_id, arg, b, &callback) ⇒ Object



22
23
24
25
26
# File 'lib/drb/drb_conn.rb', line 22

def send_message(ref, msg_id, arg, b, &callback)
  @protocol.send_request(ref, msg_id, arg, b) do |stream|
    callback.call(@protocol.recv_reply(stream))
  end
end