Hitimes java extension in the works, some help needed

Hi all,

I have the Hitimes gem (http://copiousfreetime.rubyforge.org/hitimes/),
and I
received a request to have it work on JRuby. It has an embedded C
extension,
and does not link to an external library. I figured, why not take the
opportunity to learn how to write a pure JRuby extension.

After looking at the extensions and Ruby class implmenations in the
jruby
distribution I think I implemented what I needed correctly, using
annotations.

It compiles, and creates the .jar. Only now, the annotated classes and
methods
do not appear to exist in the runtime.

I’m sure I have missed something simple, I just need the obvious pointed
out
to me. If someone could take a few minutes and help me out, I would
greatly
appreciate it.

http://github.com/copiousfreetime/hitimes/tree/java-ext

The gem list you need to run the rake tasks is:

configuration (0.0.4)
jruby-openssl (0.7)
json_pure (1.4.3)
rake (0.8.7)
rdoc (2.5.8)
rspec (1.3.0)
rubyforge (2.0.4)

If you check out that tree, then you can build and locally install the
jar.

rake ext:build_jruby

I then drop into irb and attempt this:

% irb
>> $: << "lib"
>> require 'hitimes'
>> puts Hitimes::Interval
NameError: uninitialized constant Hitimes::Interval

The Hitimes::Interval class is defined in the extension.

Any and all help is appreciated.

thanks,

-jeremy

Jeremy H. [email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Not answering the question that you asked, but just pointing out a bug
in your code:

Where you have code like:

        if ( INSTANT_NOT_SET == this.start_instant ) {
            return getRuntime().getFalseClass();
        }
        return getRuntime().getTrueClass();

the above will return the classes for true/false, not instances of
true/false.

You probably want:

      return getRuntime().newBoolean(INSTANT_NOT_SET == 

this.start_instant);

Also, its a good idea to pass in ThreadContext as your first
parameter, and use that to get the runtime.

e.g.
@JRubyMethod( name = “stopped?” )
public IRubyObject is_stopped(ThreadContext context) {
return context.getRuntime().newBoolean(INSTANT_NOT_SET ==
this.stop_instant);
}

IRubyObject#getRuntime() (used to be?/still is?) polymophic, so is
less efficient than ThreadContext#getRuntime()

btw, the hitimes C extension might work using the cext branch of
jruby. It would be interesting to see how badly performance is
affected vs native on MRI, and the java extension.

On 27 July 2010 03:06, Jeremy H. [email protected]
wrote:

rake ext:build_jruby


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Jul 27, 2010, at 9:18 AM, Wayne M. wrote:

btw, the hitimes C extension might work using the cext branch of
jruby. It would be interesting to see how badly performance is
affected vs native on MRI, and the java extension.

The hitimes spec on jruby cext currently has a very large number of
failures. Comparing performance when/if it gets ready would be
interesting.

-Tim


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Mon, Jul 26, 2010 at 11:06:13AM -0600, Jeremy H. wrote:

It compiles, and creates the .jar. Only now, the annotated classes and methods
do not appear to exist in the runtime.

I’m sure I have missed something simple, I just need the obvious pointed out
to me. If someone could take a few minutes and help me out, I would greatly
appreciate it.

http://github.com/copiousfreetime/hitimes/tree/java-ext

Most of the problem was attempting:

public class HitimesService implements Library {
}

Instead of :

public class HitimesService implements BasicLibraryService {
}

User error here. It is now building and passing all of the tests
that existed for the MRI extension. I’ll make an official release
here in the next day or two.

I would still appreciate it if someone to take a look at the hitimes
java extension and let me know if I have developed it in an acceptable
manner, followed extension conventions (if there are any), etc.

enjoy,

-jeremy

Jeremy H. [email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Thanks!

This bug got caught by my existing tests once I could run them. true is
not
TrueClass :-).

I’m working up some more thoughts/questions in general about java
extensions,
stay tuned.

On Tue, Jul 27, 2010 at 05:18:25PM +1000, Wayne M. wrote:

the above will return the classes for true/false, not instances of true/false.
public IRubyObject is_stopped(ThreadContext context) {

After looking at the extensions and Ruby class implmenations in the jruby
? ?http://github.com/copiousfreetime/hitimes/tree/java-ext

? ?NameError: uninitialized constant Hitimes::Interval


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Jeremy H. [email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Tue, Jul 27, 2010 at 07:32:27PM +0200, Tim F. wrote:

On Jul 27, 2010, at 9:18 AM, Wayne M. wrote:

btw, the hitimes C extension might work using the cext branch of
jruby. It would be interesting to see how badly performance is
affected vs native on MRI, and the java extension.

The hitimes spec on jruby cext currently has a very large number of failures. Comparing performance when/if it gets ready would be interesting.

I’ll give it a look and see what I come up with.

-jeremy

Jeremy H. [email protected]


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