[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Ruby vs Java (this,self/main

Charles Oliver Nutter

6/30/2007 7:04:00 PM

list. rb wrote:
> ###### Ruby Version:
> df = Java::Establisher.connect(user_pass_etc, "FeedSubscriberPublisher")
> pfconn = Java::FSStarter.startConn(df, self)
> pfconn.start
> puts "Subscribing to Feed events"
> pfconn.subscribe("PFEventFeedUpdate")
> def newEvent(event)
> puts event
> end
>
>
> The Ruby version breaks when providing 'self' as the 'this' equivalent when
> connecting(line two in the ruby script, here it is in IRB):

I think the problem here is that the "self" you're passing doesn't
implement whatever interfaces you need on the Java side.

Because we have to match the static types Java's looking for, simply
implementing the method isn't enough; you need to give JRuby a chance to
actually create a real Java type:

class MySubscriber
include Java::PFSubscriber

def newEvent(event)
puts event
end
end
df = Java::Establisher.connect(user_pass_etc, "FeedSubscriberPublisher")
pfconn = Java::FSStarter.startConn(df, MySubscriber.new)
pfconn.start
puts "Subscribing to Feed events"
pfconn.subscribe("PFEventFeedUpdate")

There's also some shortcut syntaxes that are somewhat experimental, but
make this process a little easier:

pfconn = Java::FSStarter.startConn(df, PFSubscriber.impl {|method,
*args| puts args[0]})

- Charlie

2 Answers

Charles Oliver Nutter

7/1/2007 11:03:00 AM

0

list. rb wrote:
> Awesome Charles.
>
> I had to make one change to your suggestion:
> class MySubscriber < com.feed.service.PFSubscriber
> def newEvent(event)
> puts event
> end
> end
>
> For some reason, the other syntax was throwing an error.

If PFSubscriber is an interface, the above syntax doesn't work in 1.0.
What version of JRuby are you using?

If it's not an interface, nevermind :)

- Charlie

Charles Oliver Nutter

7/1/2007 6:27:00 PM

0

list. rb wrote:
> java-jruby0.9.8
>
> The error I get is in javasupport:551 `method_missing`: undefined method
> `java_class` for NilClass (NoMethodError)
>
> in StartConnection..
>
> It sounds like I should upgrade then?

Yes, I'd recommend upgrading. You don't want to be building apps on
pre-1.0 due to the syntax changes that happened. They're not major, but
it would be unfortunate to have to go back and modify things.

- Charlie