Hi - I'm wanting to use yajb to script a fairly complex interface and I'm wondering if it's possible.
The interface is of the form:
$ cat iface.java
package org.wbh.testing;
import java.util.Vector;
public interface iface {
public void v();
public int i();
public String s();
public String[] a();
public Vector V();
// public void p(int i);
}
$ cat aimpl.java
package org.wbh.testing;
import java.util.Vector;
public abstract class aimpl implements iface {
public aimpl() {
System.out.println("---> java constructor");
}
protected void finalize() {
System.out.println("---> java finalizor");
}
public void jtest() {
System.out.println("---> jtest() called");
this.v();
System.out.println("---> i() gave " + this.i());
System.out.println("---> s() gave " + this.s());
for(int i=0;i<this.a().length;i++) {
System.out.println("---> a() gave " + i + " " + this.a()[i]);
}
System.out.println("---> V().firstElement()= "+this.V().firstElement());
// this.p(31);
System.out.println("---> jtest() finished");
}
}
$ cat rtest.rb
require 'yajb/jbridge'
include JavaBridge
#JBRIDGE_OPTIONS={:jvm_log_level =>"debug",:bridge_log=>true}
jimport "java.util.Vector"
jimport "org.wbh.testing.*"
tclass=jextend(:aimpl)
class << tclass
def rtest
puts "---> rtest called"
end
def v
puts "---> void method"
end
def i
puts "---> int() method"
return 42
end
def s
puts "---> String() method"
return "String??? Rope!!!"
end
def a
puts "---> String[]() method"
return [:t_string,"A001","A002"]
end
def V
puts "---> V() method"
vec=jnew(:Vector)
vec.addElement(7)
return vec
end
# def p(arg)
# puts "---> Param given: " + arg
# end
end
tclass.jtest
tclass.rtest
puts "---> That's all, folks!!!"
OK - How can I pass a value *from* java to the ruby implementation of the abstract class??? If the commented out code is activated it gives:
jbridge.RemoteRuntimeException: class=TypeError message=can't convert
Fixnum into String
Also, this code seems to suffer from a race. *Sometimes* rtest is called before jtest has finished! Possibly related, one run can finish fine, but the next run gives:
Full thread dump Java HotSpot(TM) Client VM (1.4.2_09-b05 mixed mode):
"Thread-16" prio=1 tid=0x081c4520 nid=0x7cb8 waiting on condition [4d063000..4d0638b8]
at java.lang.Thread.sleep(Native Method)
at jbridge.BridgeServer$1.run(BridgeServer.java:248)
at java.lang.Thread.run(Unknown Source)
How can I syncronize properly (I'm guessing this is an issue of the ruby end of the bridge quitting before the java's done, but I'd prefer not to have to do a wrapper on the java end of things.)
Any pointers? Thanks!
Bill
BTW, really like yajb for the integration, the way there's only jars and ruby, no JNI to mess around with!