[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

DRB+Mixin, a defect or an usage error?

yangpeng

1/31/2008 4:51:00 AM

[Note: parts of this message were removed to make it a legal post.]


I found a strange thing when I include a module to a Drb object.I'm confused.
server.rb:require 'drb'require 'module_a'
class ServerHello include TestModule1 def sayHello puts 'I am server' end endDRb.start_service("druby://127.0.0.1:2222", ServerHello.new)DRb.thread.join
client.rb:
require 'drb' require 'module_a' include TestModule1DRb.start_service info = DRbObject.new(nil, "druby://127.0.0.1:2222") info.sayHello() info.sayHello2
module_a.rb:
require 'drb'module TestModule1 def sayHello2 puts "who am i" endend
The three files in one path, I run server.rb first, then client.rb. The result is.server.rb output:I am serverclietn.rb output:who am iBut my expected result is:server.rb output both "I am server" and "who am i"
the "sayHello2" is executed in local, not remote..(or exactly, it's "client invoke server, server invoke client backly", for if we changed "puts "who am i"" to "puts self", the result is "DRbObject")
If I comments the "include TestModule1" of client.rb, the result is good.But this is not I want, for there are many standard code share between server and client.
It's it a defect or my usage error?

_________________________________________________________________
Windows Live Photo gallery êy???à?úµ?3???°é?????á?é1üàíoí±à?-???????1?ü??×÷è??°?àí???
http://get.live.cn/product/...
4 Answers

Daniel Brumbaugh Keeney

1/31/2008 5:40:00 PM

0

2008/1/30 yangpeng <edge_hh@hotmail.com>:

> I found a strange thing when I include a module to a Drb object.
> I'm confused.
>
> module_a.rb:
>
> require 'drb'
> module TestModule1
> def sayHello2
> puts "who am i"
> end
> end
>
> server.rb:
>
> require 'drb'
> require 'module_a'
>
> class ServerHello
> include TestModule1
> def sayHello
> puts 'I am server'
> end
> end
>
> DRb.start_service("druby://127.0.0.1:2222", ServerHello.new)
> DRb.thread.join
>
>
> client.rb:
>
> require 'drb'
> require 'module_a'
> include TestModule1
> DRb.start_service
> info = DRbObject.new(nil, "druby://127.0.0.1:2222")
> info.sayHello()
> info.sayHello2
>
> The three files in one path, I run server.rb first, then client.rb.
> The result is
>
> server.rb output:
> I am server
>
> client.rb output:
> who am i
>
> But my expected result is:
>
> server.rb output both "I am server" and "who am i"
>
> the "sayHello2" is executed in local, not remote. (or exactly, it's "client invoke server, server invoke client backly",
> for if we changed "puts "who am i"" to "puts self", the result is "DRbObject")
> If I comments the "include TestModule1" of client.rb, the result is good.
> But this is not I want, for there are many standard code share between server and client.
> It's it a defect or my usage error


Wow, this is surprising. I would really appreciate some enlightenment
by somebody more experienced with DRB, but I would call this a bug.

Daniel Brumbaugh Keeney

yangpeng

2/1/2008 1:01:00 AM

0

[Note: parts of this message were removed to make it a legal post.]


yeah, then how can I report this defect, if it is a defect? > Date: Fri, 1 Feb 2008 02:40:02 +0900> From: devi.webmaster@gmail.com> Subject: Re: DRB+Mixin, a defect or an usage error?> To: ruby-talk@ruby-lang.org> > 2008/1/30 yangpeng <edge_hh@hotmail.com>:> > > I found a strange thing when I include a module to a Drb object.> > I'm confused.> >> > module_a.rb:> >> > require 'drb'> > module TestModule1> > def sayHello2> > puts "who am i"> > end> > end> >> > server.rb:> >> > require 'drb'> > require 'module_a'> >> > class ServerHello> > include TestModule1> > def sayHello> > puts 'I am server'> > end> > end> >> > DRb.start_service("druby://127.0.0.1:2222", ServerHello.new)> > DRb.thread.join> >> >> > client.rb:> >> > require 'drb'> > require 'module_a'> > include TestModule1> > DRb.start_service> > info = DRbObject.new(nil, "druby://127.0.0.1:2222")> > info.sayHello()> > info.sayHello2> >> > The three files in one path, I run server.rb first, then client.rb.> > The result is> >> > server.rb output:> > I am server> >> > client.rb output:> > who am i> >> > But my expected result is:> >> > server.rb output both "I am server" and "who am i"> >> > the "sayHello2" is executed in local, not remote. (or exactly, it's "client invoke server, server invoke client backly",> > for if we changed "puts "who am i"" to "puts self", the result is "DRbObject")> > If I comments the "include TestModule1" of client.rb, the result is good.> > But this is not I want, for there are many standard code share between server and client.> > It's it a defect or my usage error> > > Wow, this is surprising. I would really appreciate some enlightenment> by somebody more experienced with DRB, but I would call this a bug.> > Daniel Brumbaugh Keeney>
_________________________________________________________________
MSNê?µ?à????eèèµ?3????a·?·?·??D???ìà'áìè?°é??
http://im.live.cn/emotic...

Daniel Brumbaugh Keeney

2/1/2008 8:25:00 PM

0

2008/1/31 yangpeng <edge_hh@hotmail.com>:
>
> yeah, then how can I report this defect, if it is a defect?

I've spent some more time looking through the various Ruby test
suites, but I can't find any tests for this behavior. It's definitely
a bug. I believe the bug report for this should go to
http://rubyforge.org/tracker/?func=add&group_id=426&...
under the category "Misc / Other Standard Library"

The issue seems to be that DRb is including the client version of
modules if it is available, whereas it should always include the
server one. To use RSpec in your example:
info.kind_of?(TestModule1).should be_false

or generically
describe DRb::DRbObject do


Daniel Brumbaugh Keeney

Daniel Brumbaugh Keeney

2/1/2008 8:26:00 PM

0

On Feb 1, 2008 2:24 PM, Daniel Brumbaugh Keeney
<devi.webmaster@gmail.com> wrote:
> 2008/1/31 yangpeng <edge_hh@hotmail.com>:
> >
> > yeah, then how can I report this defect, if it is a defect?
>
> I've spent some more time looking through the various Ruby test
> suites, but I can't find any tests for this behavior. It's definitely
> a bug. I believe the bug report for this should go to
> http://rubyforge.org/tracker/?func=add&group_id=426&...
> under the category "Misc / Other Standard Library"
>
> The issue seems to be that DRb is including the client version of
> modules if it is available, whereas it should always include the
> server one. To use RSpec in your example:
> info.kind_of?(TestModule1).should be_false
>
> or generically
info.class.included_modules.should == [Kernel]

Daniel Brumbaugh Keeney


blast, tabs don't do the same thing in browsers they do in text editors