Class: DRb::DRbConn

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

Overview

Class handling the connection between a DRbObject and the server the real object lives on.

This class maintains a pool of connections, to reduce the overhead of starting and closing down connections for each method call.

This class is used internally by DRbObject. The user does not normally need to deal with it directly.

Constant Summary collapse

POOL_SIZE =

:nodoc:

16

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(remote_uri) ⇒ DRbConn

:nodoc:



1187
1188
1189
1190
# File 'lib/drb/drb.rb', line 1187

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

Instance Attribute Details

#uriObject (readonly)

:nodoc:



1191
1192
1193
# File 'lib/drb/drb.rb', line 1191

def uri
  @uri
end

Class Method Details

.open(remote_uri) ⇒ Object

:nodoc:



1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
# File 'lib/drb/drb.rb', line 1152

def self.open(remote_uri)  # :nodoc:
  begin
	conn = nil

	@mutex.synchronize do
	  #FIXME
	  new_pool = []
	  @pool.each do |c|
 if conn.nil? and c.uri == remote_uri
   conn = c if c.alive?
 else
   new_pool.push c
 end
	  end
	  @pool = new_pool
	end

	conn = self.new(remote_uri) unless conn
	succ, result = yield(conn)
	return succ, result

  ensure
	if conn
	  if succ
 @mutex.synchronize do
   @pool.unshift(conn)
   @pool.pop.close while @pool.size > POOL_SIZE
 end
	  else
 conn.close
	  end
	end
  end
end

Instance Method Details

#alive?Boolean

:nodoc:

Returns:

  • (Boolean)


1203
1204
1205
1206
# File 'lib/drb/drb.rb', line 1203

def alive?  # :nodoc:
  return false unless @protocol
  @protocol.alive?
end

#closeObject

:nodoc:



1198
1199
1200
1201
# File 'lib/drb/drb.rb', line 1198

def close  # :nodoc:
  @protocol.close
  @protocol = nil
end

#send_message(ref, msg_id, arg, block) ⇒ Object

:nodoc:



1193
1194
1195
1196
# File 'lib/drb/drb.rb', line 1193

def send_message(ref, msg_id, arg, block)  # :nodoc:
  @protocol.send_request(ref, msg_id, arg, block)
  @protocol.recv_reply
end