anyone got a slick way of temporaily disabling DRbUndumped?
-a
···
--
we can deny everything, except that we have the possibility of being better.
simply reflect on that.
- the dalai lama
anyone got a slick way of temporaily disabling DRbUndumped?
-a
--
we can deny everything, except that we have the possibility of being better.
simply reflect on that.
- the dalai lama
ara.t.howard@noaa.gov schrieb:
anyone got a slick way of temporaily disabling DRbUndumped?
Ara, can you tell us a bit more, probably via a testcase?
Regards,
Pit
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.
On Feb 9, 2007, at 13:49, ara.t.howard@noaa.gov 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">
On Sat, Feb 10, 2007 at 06:49:59AM +0900, ara.t.howard@noaa.gov wrote:
anyone got a slick way of temporaily disabling DRbUndumped?
----------------------------------------
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
--
Mauricio Fernandez - http://eigenclass.org - singular Ruby
** Latest postings **
What's new in Ruby 1.9, Feb. 07 update
http://eigenclass.org/hiki.rb?Changes-in-Ruby-1.9-update-6
Firebrigade: automated, sandboxed testing of RubyGems packages by other devels
http://eigenclass.org/hiki.rb?firebrigade-launched
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
On Sat, 10 Feb 2007, Eric Hodel wrote:
On Feb 9, 2007, at 13:49, ara.t.howard@noaa.gov 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.
--
we can deny everything, except that we have the possibility of being better.
simply reflect on that.
- the dalai lama
<snip>
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
On Sun, 11 Feb 2007, Mauricio Fernandez wrote:
On Sat, Feb 10, 2007 at 06:49:59AM +0900, ara.t.howard@noaa.gov wrote:
anyone got a slick way of temporaily disabling DRbUndumped?
Strained, but works. It can be made thread-safe quite easily also.
--
we can deny everything, except that we have the possibility of being better.
simply reflect on that.
- the dalai lama
ara.t.howard@noaa.gov 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