Class: DRb::DRbConn

Inherits:
Object
  • Object
show all
Defined in:
lib/opal/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.



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

#uriObject (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

Returns:

  • (Boolean)


51
52
53
54
# File 'lib/opal/drb/drb_conn.rb', line 51

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

#closeObject



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 send_message(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