# Disabling DRbUndumped

**URL:** <https://www.ruby-forum.com/t/disabling-drbundumped/85082>\
**Category:** Ruby\
**Created:** [February 9, 2007, 10:50pm UTC](https://www.ruby-forum.com/t/disabling-drbundumped/85082 "2007-02-09T22:50:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 9, 2007, 10:50pm UTC](https://www.ruby-forum.com/t/disabling-drbundumped/85082/1 "2007-02-09T22:50:53Z")

</div>

anyone got a slick way of temporaily disabling DRbUndumped?

-a

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 10, 2007, 9:49am UTC](https://www.ruby-forum.com/t/disabling-drbundumped/85082/2 "2007-02-10T09:49:49Z")

</div>

removed\_email\_address@domain.invalid schrieb:

> anyone got a slick way of temporaily disabling DRbUndumped?

Ara, can you tell us a bit more, probably via a testcase?

Regards,  
Pit

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 10, 2007, 12:17pm UTC](https://www.ruby-forum.com/t/disabling-drbundumped/85082/3 "2007-02-10T12:17:59Z")

</div>

On Feb 9, 2007, at 13:49, removed\_email\_address@domain.invalid wrote:

> anyone got a slick way of temporaily disabling DRbUndumped?

Hrm, you’d need to move #\_dump around to get this to work. Since  
#\_dump isn’t defined on Object, raising TypeError or calling super  
isn’t going to work, and I’m not smart enough to make it work.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 10, 2007, 6:55pm UTC](https://www.ruby-forum.com/t/disabling-drbundumped/85082/4 "2007-02-10T18:55:37Z")

</div>

On Sat, 10 Feb 2007, Eric H. wrote:

> On Feb 9, 2007, at 13:49, removed\_email\_address@domain.invalid wrote:
> 
> > anyone got a slick way of temporaily disabling DRbUndumped?
> 
> Hrm, you’d need to move #\_dump around to get this to work. Since #\_dump  
> isn’t defined on Object, raising TypeError or calling super isn’t going to  
> work, and I’m not smart enough to make it work.

i’ve just been doing

def marshal src  
klass = src.class  
dst = klass.allocate  
src.instance\_variables.each do |ivar|  
…  
…  
…

because the objects in question are simply state… but it’s a work  
around.

sigh.

-a

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 10, 2007, 5:14pm UTC](https://www.ruby-forum.com/t/disabling-drbundumped/85082/5 "2007-02-10T17:14:30Z")

</div>

On Sat, Feb 10, 2007 at 06:49:59AM +0900, removed\_email\_address@domain.invalid wrote:

> anyone got a slick way of temporaily disabling DRbUndumped?

Strained, but works. It can be made thread-safe quite easily also.

```
$ cat drb_client.rb
#!/usr/bin/env ruby
require 'drb'
require 'time_service'

DRb.start_service

r_obj = DRbObject.new_with_uri(ARGV.shift)
p r_obj
puts "-" * 40

def d(o)
  puts "OBJECT -> #{o.inspect}"
  p o.get_time
end

t = r_obj.time
d t

puts "\nDisabling undumped"
t.disable_undumped
t = r_obj.time
d t

puts "\nEnabling"
r_obj.enable_undumped(TimeServer)
t = r_obj.time
d t

$ ruby drb_client.rb druby://localhost:50011
#<DRb::DRbObject:0xa7d9d4e0 @ref=nil, 

```

@uri=“druby://localhost:50011”\>  
----------------------------------------  
OBJECT -\> #\<DRb::DRbObject:0xa7d9ccfc @ref=-739674518,  
@uri=“druby://localhost:50011”\>  
Sat Feb 10 17:04:04 +0100 2007

```
Disabling undumped
OBJECT -> #<TimeServer:0xa7d9bf3c>
Sat Feb 10 17:04:04 +0100 2007

Enabling
OBJECT -> #<DRb::DRbObject:0xa7d9b4ec @ref=-739674518, 

```

@uri=“druby://localhost:50011”\>  
Sat Feb 10 17:04:04 +0100 2007

```
$ cat time_service.rb

require 'drb'
require 'suspend_undumped'

class TimeServer
  include DRb::DRbUndumped
  def get_time; return Time.now end
end

$ cat suspend_undumped.rb

module DRb::DRbUndumped
  disabled = @disabled = {}
  ::Kernel.module_eval do

```

old\_kind\_of = instance\_method(:kind\_of?)  
define\_method(:kind\_of?) do |klass|  
#puts “OBJ is #{self.inspect} in #{caller[0]}” if $DEBUG  
if DRb::DRbUndumped == klass && disabled[self.class]  
false  
else  
old\_kind\_of.bind(self).call(klass)  
end  
end  
end

```
  define_method(:respond_to?) do |meth|

```

if disabled[self.class] && :\_dump == meth  
false  
else  
super  
end  
end

```
  # all these executed in the server
  def self.disable_undumped(klass)

```

@disabled[klass] = true  
end

```
  def self.enable_undumped(klass)

```

@disabled.delete(klass)  
end

```
  def disable_undumped

```

DRb::DRbUndumped.disable\_undumped(self.class)  
end  
end

```
class Object
  def enable_undumped(klass)

```

# in the server

DRb::DRbUndumped.enable\_undumped(klass)  
end  
end

```
class DRb::DRbObject
  def enable_undumped(klass)

```

# in the client

method\_missing(:enable\_undumped, klass)  
end  
end

Finally, a trivial server (just so the email is self-complete):

```
require 'drb'
require 'time_service'

URI = "druby://localhost:50011"

Service = Struct.new(:time, :foo)

obj = Service.new(TimeServer.new, nil)
DRb.start_service(URI, obj)

puts DRb.uri

DRb.thread.join
```

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 10, 2007, 6:59pm UTC](https://www.ruby-forum.com/t/disabling-drbundumped/85082/6 "2007-02-10T18:59:37Z")

</div>

On Sun, 11 Feb 2007, Mauricio F. wrote:

> On Sat, Feb 10, 2007 at 06:49:59AM +0900, removed\_email\_address@domain.invalid wrote:
> 
> > anyone got a slick way of temporaily disabling DRbUndumped?
> 
> Strained, but works. It can be made thread-safe quite easily also.

coming it at from the other direction - NICE!

boy - it might be easier to patch drb though… seems like a good  
feature to  
have?

thanks a bunch - i’ll play with this

cheers.

-a

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 10, 2007, 11:35pm UTC](https://www.ruby-forum.com/t/disabling-drbundumped/85082/7 "2007-02-10T23:35:07Z")

</div>

removed\_email\_address@domain.invalid schrieb:

> (… mauricio’s as always fine solution …)
> 
> thanks a bunch - i’ll play with this

Ara, do you need to control this on the client or on the server? Per  
object or per class? There are several possible implementations based on  
Mauricio’s code. For example, with the following the disable/enable  
methods work on a per object basis:

module DRbUndumped

```
 @undumped_disabled = {}

 def self.undumped_disabled? obj
   @undumped_disabled[DRb.to_id(obj)]
 end

 def self.disable_undumped obj
   @undumped_disabled[DRb.to_id(obj)] = true
 end

 def self.enable_undumped obj
   @undumped_disabled.delete DRb.to_id(obj)
 end

 def undumped_disabled?
   DRbUndumped.undumped_disabled? self
 end

 def disable_undumped
   DRbUndumped.disable_undumped self
 end

 def enable_undumped
   DRbUndumped.enable_undumped self
 end

 def kind_of? arg
   (arg != DRbUndumped || !undumped_disabled?) && super
 end

 def respond_to? arg
   (arg != :_dump || !undumped_disabled?) && super
 end

```

end

It doesn’t allow to re-enable DRbUndumped on the client side. If you  
need this, the code has to be changed a little bit.

Regards,  
Pit
