Problem of feedtools with jruby

Hi, guys
I play feedtools with jruby, but get exceptions like

=======================================
D:\ruby-workspace\learning>jruby feed_tools_exam.rb
Description: Mars Today Top Stories
D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_tools/feed_item.
rb:67:in each_object': ObjectSpace is disabled; each_object will only work with Class, pass +O to enable (RuntimeError) from D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_too ls/feed_item.rb:67:infeed’
from
D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_too
ls/feed_item.rb:141:in configurations' from D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_too ls/feed_item.rb:1757:intime’
from
D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_too
ls/feed.rb:2446:in entries' from D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_too ls/feed.rb:2445:insort’
from
D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_too
ls/feed.rb:2445:in `entries’

Source code is very sample:

require ‘rubygems’
require “feed_tools”

URL = “http://www.marstoday.com/rss/mars.xml
FeedTools.configurations[:feed_cache] = nil
feed = FeedTools::Feed.open(URL)
puts “Description: #{feed.title}”

feed.entries.each {|item| puts item.title}

Anyone can help me ?

On Wed, Jul 23, 2008 at 12:19 PM, Yin AnPing [email protected]
wrote:

I play feedtools with jruby, but get exceptions like

=======================================
D:\ruby-workspace\learning>jruby feed_tools_exam.rb
Description: Mars Today Top Stories
D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_tools/feed_item.
rb:67:in `each_object’: ObjectSpace is disabled; each_object will only work
with
Class, pass +O to enable (RuntimeError)

Did you try with

jruby +O feed_tools_exam.rb

as advertised by the error message ?

Best regards,


John M. - http://jmettraux.wordpress.com


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Yes, but I still get error message:
jruby: unknown option +O

On Wed, Jul 23, 2008 at 12:24 PM, Yin AnPing [email protected]
wrote:

Yes, but I still get error message:
jruby: unknown option +O

Maybe

./bin/jruby -J-Djruby.objectspace.enabled=true feed_tools_exam.rb

seen on :

http://wiki.jruby.org/wiki/Performance_Tuning

Best regards,


John M. - http://jmettraux.wordpress.com


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Yin AnPing wrote:

Hi, guys
I play feedtools with jruby, but get exceptions like

=======================================
D:\ruby-workspace\learning>jruby feed_tools_exam.rb
Description: Mars Today Top Stories
D:/jruby-1.1.3/lib/ruby/gems/1.8/gems/feedtools-0.2.29/lib/feed_tools/feed_item.
rb:67:in `each_object’: ObjectSpace is disabled; each_object will only
work with
Class, pass +O to enable (RuntimeError)

Oops, sorry about that, it’s a bad error message. The correct flag to
turn on full ObjectSpace is -X+O. We moved it under the -X options to
avoid any future conflict with normal Ruby obtions.

I’ll fix the error.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

thanks ! It works !

On Wed, Jul 23, 2008 at 12:32 PM, Charles Oliver N. <

another way to run it
thanks everybody !

require ‘rubygems’
require “feed_tools”
require ‘jruby’

JRuby.objectspace=true

URL = “http://www.marstoday.com/rss/mars.xml
FeedTools.configurations[:feed_cache] = nil
feed = FeedTools::Feed.open(URL)
puts “Description: #{feed.title}\n”

feed.entries.each {|item| puts item.title}

On Wed, Jul 23, 2008 at 12:56 AM, Yin AnPing [email protected]
wrote:

FeedTools.configurations[:feed_cache] = nil
feed = FeedTools::Feed.open(URL)
puts “Description: #{feed.title}\n”

feed.entries.each {|item| puts item.title}

I don’t mean to hijack this thread and we can move it elsewhere if
necessary, but I am surprised to see such a “simple” library using
ObjectSpace.each_object. I know the JRuby team made the decision to
turn ObjectSpace.each_object off by default because of a large
performance hit and the fact that ObjectSpace.each_object is seldom
used.

If I recall correctly test/unit used to use each_object and it was
able to be patched to avoid using it entirely, anyone remember if this
is correct?

The offending method and author’s comment prior to it are listed at
the bottom of this email and at http://pastie.org/242073.

I guess I could ask elsewhere, but I do not understand the author’s
motivation described in the comment below. I am assuming there is a
simple hierarchy between feeds and feed items with a feed being the
parent of a feed item. I am curious what type of havoc storing the
parent in the feed item could cause with GC?

Storing a reference to the parent object of a child object in a
hierarchy seems like a fairly common thing to do, is it not?

Also, I know that JRuby uses a different GC than MRI, would JRuby’s GC
mechanism be less likely to experience the pitfalls (which I am still
trying to understand) than MRI?

I just guess I am surprised to see ObjectSpace.each_object used in
such a simple situation. I always assumed most use cases could be
implemented using some other means.

Thanks,
Michael G.

<<-CODE

Returns the parent feed of this feed item

Warning, this method may be slow if you have a

large number of FeedTools::Feed objects. Can’t

use a direct reference to the parent because it plays

havoc with the garbage collector. Could’ve used

a WeakRef object, but really, if there are multiple

parent feeds, something is going to go wrong, and the

programmer needs to be notified. A WeakRef

implementation can’t detect this condition.

def feed
parent_feed = nil
ObjectSpace.each_object(FeedTools::Feed) do |feed|
if feed.instance_variable_get("@entries").nil?
feed.items
end
unsorted_items = feed.instance_variable_get("@entries")
for item in unsorted_items
if item.object_id == self.object_id
if parent_feed.nil?
parent_feed = feed
break
else
raise “Multiple parent feeds found.”
end
end
end
end
return parent_feed
end

CODE


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs