Class | DRb::DRbObject
In: | drb/gw.rb drb/eq.rb drb/drb.rb
Parent: | Object

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.

### Methods

== __drbref __drburi _dump _dump _load _load eql? hash method_missing new new_with new_with_uri prepare_backtrace respond_to? with_friend

### Public Class methods

_load(s)

[Source]

    # File drb/gw.rb, line 35
        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

_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.

[Source]

    # File drb/drb.rb, line 998
        def self._load(s)
          uri, ref = Marshal.load(s)

          if DRb.here?(uri)
            obj = DRb.to_obj(ref)
            if ((! obj.tainted?) && Thread.current[:drb_untaint])
              Thread.current[:drb_untaint].push(obj)
            end
            return obj
          end

          self.new_with(uri, ref)
        end

new(obj, uri=nil)

Create a new remote object stub.

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

[Source]

    # File drb/drb.rb, line 1036
        def initialize(obj, uri=nil)
          @uri = nil
          @ref = nil
          if obj.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

new_with(uri, ref)

[Source]

    # File drb/drb.rb, line 1012
        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.

[Source]

    # File drb/drb.rb, line 1020
        def self.new_with_uri(uri)
          self.new(nil, uri)
        end

prepare_backtrace(uri, result)

[Source]

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

with_friend(uri) {|| ...}

[Source]

    # File drb/drb.rb, line 1098
        def self.with_friend(uri)
          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

### Public Instance methods

==(other)

[Source]

    # File drb/eq.rb, line 5
        def ==(other)
          return false unless DRbObject === other
         (@ref == other.__drbref) && (@uri == other.__drburi)
        end

__drbref()

Get the reference of the object, if local.

[Source]

    # File drb/drb.rb, line 1055
        def __drbref
          @ref
        end

__drburi()

Get the URI of the remote object.

[Source]

    # File drb/drb.rb, line 1050
        def __drburi
          @uri
        end

_dump(lv)

[Source]

    # File drb/gw.rb, line 44
        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

_dump(lv)

Marshall this object.

The URI and ref of the object are marshalled.

[Source]

    # File drb/drb.rb, line 1027
        def _dump(lv)
          Marshal.dump([@uri, @ref])
        end

eql?(other)

Alias for #==

hash()

[Source]

    # File drb/eq.rb, line 10
        def hash
          [@uri, @ref].hash
        end

method_missing(msg_id, *a, &b)

Routes method calls to the referenced object.

[Source]

    # File drb/drb.rb, line 1074
        def method_missing(msg_id, *a, &b)
          if DRb.here?(@uri)
            obj = DRb.to_obj(@ref)
            DRb.current_server.check_insecure_method(obj, msg_id)
            return obj.__send__(msg_id, *a, &b)
          end

          succ, result = self.class.with_friend(@uri) do
            DRbConn.open(@uri) do |conn|
              conn.send_message(self, msg_id, a, b)
            end
          end

          if succ
            return result
          elsif DRbUnknown === result
            raise result
          else
            bt = self.class.prepare_backtrace(@uri, result)
            result.set_backtrace(bt + caller)
            raise result
          end
        end

respond_to?(msg_id, priv=false)

[Source]

    # File drb/drb.rb, line 1062
        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

[Validate]