123456789_123456789_123456789_123456789_123456789_

Class: DRb::DRbObject

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/drb/drb.rb,
lib/drb/eq.rb,
lib/drb/gw.rb

Overview

Object wrapping a reference to a remote drb object.

Method calls on this object are relayed to the remote object that this object is a stub for.

Class Method Summary

Instance Method Summary

Constructor Details

.new(obj, uri = nil) ⇒ DRbObject

Create a new remote object stub.

obj is the (local) object we want to create a stub for. Normally this is nil. DRb.uri is the URI of the remote object that this will be a stub for.

[ GitHub ]

  
# File 'lib/drb/drb.rb', line 1089

def initialize(obj, uri=nil)
  @uri = nil
  @ref = nil
  case obj
  when Object
    is_nil = obj.nil?
  when BasicObject
    is_nil = false
  end

  if is_nil
    return if uri.nil?
    @uri, option = DRbProtocol.uri_option(uri, DRb.config)
    @ref = DRbURIOption.new(option) unless option.nil?
  else
    @uri = uri ? uri : (DRb.uri rescue nil)
    @ref = obj ? DRb.to_id(obj) : nil
  end
end

Class Method Details

._load(s)

Unmarshall a marshalled DRbObject.

If the referenced object is located within the local server, then the object itself is returned. Otherwise, a new DRbObject is created to act as a stub for the remote referenced object.

[ GitHub ]

  
# File 'lib/drb/drb.rb', line 1051

def self._load(s)
  uri, ref = Marshal.load(s)
  if DRb.uri == uri
    return ref ? DRb.to_obj(ref) : DRb.front
  end

  self.new_with(DRb.uri, [:DRbObject, uri, ref])
end

.new_with(uri, ref)

Creates a DRbObject given the reference information to the remote host DRb.uri and object ref.

[ GitHub ]

  
# File 'lib/drb/drb.rb', line 1065

def self.new_with(uri, ref)
  it = self.allocate
  it.instance_variable_set(:@uri, uri)
  it.instance_variable_set(:@ref, ref)
  it
end

.new_with_uri(uri)

Create a new DRbObject from a URI alone.

[ GitHub ]

  
# File 'lib/drb/drb.rb', line 1073

def self.new_with_uri(uri)
  self.new(nil, uri)
end

.prepare_backtrace(uri, result)

Returns a modified backtrace from result with the DRb.uri where each call in the backtrace came from.

[ GitHub ]

  
# File 'lib/drb/drb.rb', line 1173

def self.prepare_backtrace(uri, result) # :nodoc:
  prefix = "(#{uri}) "
  bt = []
  result.backtrace.each do |x|
    break if /[`']__send__'$/ =~ x
    if /\A\(druby:\/\// =~ x
      bt.push(x)
    else
      bt.push(prefix + x)
    end
  end
  bt
end

.with_friend(uri)

Given the DRb.uri of another host executes the block provided.

[ GitHub ]

  
# File 'lib/drb/drb.rb', line 1160

def self.with_friend(uri) # :nodoc:
  friend = DRb.fetch_server(uri)
  return yield() unless friend

  save = Thread.current['DRb']
  Thread.current['DRb'] = { 'server' => friend }
  return yield
ensure
  Thread.current['DRb'] = save if friend
end

Instance Method Details

#==(other) Also known as: #eql?

[ GitHub ]

  
# File 'lib/drb/eq.rb', line 4

def ==(other)
  return false unless DRbObject === other
 (@ref == other.__drbref) && (@uri == other.__drburi)
end

#__drbref

Get the reference of the object, if local.

[ GitHub ]

  
# File 'lib/drb/drb.rb', line 1115

def __drbref
  @ref
end

#__drburi

Get the URI of the remote object.

[ GitHub ]

  
# File 'lib/drb/drb.rb', line 1110

def __drburi
  @uri
end

#_dump(lv)

Marshall this object.

The URI and ref of the object are marshalled.

[ GitHub ]

  
# File 'lib/drb/drb.rb', line 1080

def _dump(lv)
  if DRb.uri == @uri
    if Array === @ref && @ref[0] == :DRbObject
      Marshal.dump([@ref[1], @ref[2]])
    else
      Marshal.dump([@uri, @ref]) # ??
    end
  else
    Marshal.dump([DRb.uri, [:DRbObject, @uri, @ref]])
  end
end

#eql?(other)

Alias for #==.

[ GitHub ]

  
# File 'lib/drb/eq.rb', line 13

alias eql? ==

#hash

[ GitHub ]

  
# File 'lib/drb/eq.rb', line 9

def hash
  [@uri, @ref].hash
end

#pretty_print(q)

[ GitHub ]

  
# File 'lib/drb/drb.rb', line 1187

def pretty_print(q)   # :nodoc:
  q.pp_object(self)
end

#pretty_print_cycle(q)

[ GitHub ]

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

def pretty_print_cycle(q)   # :nodoc:
  q.object_address_group(self) {
    q.breakable
    q.text '...'
  }
end

#respond_to?(msg_id, priv = false) ⇒ Boolean

Routes respond_to? to the referenced remote object.

[ GitHub ]

  
# File 'lib/drb/drb.rb', line 1123

def respond_to?(msg_id, priv=false)
  case msg_id
  when :_dump
    true
  when :marshal_dump
    false
  else
    method_missing(:respond_to?, msg_id, priv)
  end
end