Class: DRb::ThreadObject

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

Instance Method Summary collapse

Constructor Details

#initialize(&blk) ⇒ ThreadObject

Returns a new instance of ThreadObject.



1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
# File 'lib/drb/drb.rb', line 1230

def initialize(&blk)
  super()
  @wait_ev = new_cond
  @req_ev = new_cond
  @res_ev = new_cond
  @status = :wait
  @req = nil
  @res = nil
  @thread = Thread.new(self, &blk)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(msg, *arg, &blk) ⇒ Object



1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
# File 'lib/drb/drb.rb', line 1250

def method_missing(msg, *arg, &blk)
  synchronize do
    @wait_ev.wait_until { @status == :wait }
    @req = [msg] + arg
    @status = :req
    @req_ev.broadcast
    @res_ev.wait_until { @status == :res }
    value = @res
    @req = @res = nil
    @status = :wait
    @wait_ev.broadcast
    return value
  end
end

Instance Method Details

#_executeObject



1265
1266
1267
1268
1269
1270
1271
1272
# File 'lib/drb/drb.rb', line 1265

def _execute()
  synchronize do
    @req_ev.wait_until { @status == :req }
    @res = yield(@req)
    @status = :res
    @res_ev.signal
  end
end

#alive?Boolean

Returns:

  • (Boolean)


1241
1242
1243
# File 'lib/drb/drb.rb', line 1241

def alive?
  @thread.alive?
end

#killObject



1245
1246
1247
1248
# File 'lib/drb/drb.rb', line 1245

def kill
  @thread.kill
  @thread.join
end