|
From: <php...@li...> - 2007-07-24 15:59:27
|
hi to all.
first of all, i'm sorry for my bad english.. i hope you will understand me.
I was doing an experiment with php classes and java interfaces.
i have a java class:
public class ObjPassing
{
public void visit( Object o)
{ System.out.println("first visit method"); }
public void visit( IVisit o) // <-- i wish to run this one
{ System.out.println("second visit method"); }
}
I need to pass a php object(Obj is it's name) who implements my IVisit
java interface, to ObjPassing, but i never manage to invoke the second
method: the first method is always invoked.
from php i do:
$obj = new Java('ObjPassing');
$obj->visit(java_get_closure(new Obj(),null, new JavaClass("IVisit")));
is it possible to call the second method? if yes, where is my fault?
thank you
|
|
From: <php...@li...> - 2007-07-25 20:07:49
|
Hi
[please excuse the delay]
your code is a little bit unusual because it uses a generated proxy class. Looking at the
current implementation it seems that the bridge caches the generated proxies, which it shouldn't
do. But this is a minor problem.
> public class ObjPassing
> {
> public void visit( Object o)
> { System.out.println("first visit method"); }
>
> public void visit( IVisit o) // <-- i wish to run this one
> { System.out.println("second visit method"); }
> }
>
> I need to pass a php object(Obj is it's name) who implements my IVisit
> java interface, to ObjPassing, but i never manage to invoke the second
> method: the first method is always invoked.
The bridge should invoke the second method, because the closure (the dynamic proxy) implements the
IVisit interface, which makes it cheaper than the first method which should have a weight of at
least 32 (IVisit -> Object conversion)
> is it possible to call the second method? if yes, where is my fault?
Can you please set the log level to 5 or above? The bridge should display the weight and why it
has selected the wrong method. My guess is that you have loaded IVisit from a different
classloader, so that it is assignment-incompatible with IVisit used by the visit method. Do you
have two java_require() calls in your code?
Regards,
Jost Boekemeier
__________________________________ Wissenswertes zum Thema PC, Zubehör oder Programme. BE A BETTER INTERNET-GURU! www.yahoo.de/clever
|
|
From: <php...@li...> - 2007-07-27 23:46:19
|
2007/7/25, php...@li...
<php...@li...>:
> [please excuse the delay]
no problem! thanks for your attention
> your code is a little bit unusual
if you can advice me a bettter solution, i will thank you! ^_^
> Can you please set the log level to 5 or above? The bridge should display the weight and why it
> has selected the wrong method.
.the log is at the end o this mail
> Do you
> have two java_require() calls in your code?
i have only one:
<?php
require_once("http://localhost:8080/JavaBridge/java/Java.inc");
java_require("/var/www/prove");
$o = new Obj();
$o->exec();
class Obj
{
var $a = 'pluto';
function __construct(){ $this->a='paperina';}
function exec()
{
try {
$obj = new Java('ObjPassing');
$a = java_Cast($obj->testMe(),'string');
$obj->visit(java_get_closure(new Obj()));
$obj->visit2(java_get_closure(new Obj()));
$obj->visit(java_get_closure($this));
$obj->visit(java_get_closure(new Obj(),null, new JavaClass("IVisit")));
}
catch(JavaException $ex)
{
$exStr = java_cast($ex, "string");
echo "\nException occured; mixed trace: $exStr\n";
}
}
public function eccolo() { }
}
// suppress the warning message from the use of reset.
@java_reset();
?>
PS: even if i don't know why, i've noticed that i manage to call the
rigth method if the exec method of my class is only:
function exec()
{
try {
$obj = new Java('ObjPassing');
$obj->visit(java_get_closure(new Obj(),null, new JavaClass("IVisit")));
}
catch(JavaException $ex)
{
$exStr = java_cast($ex, "string");
echo "\nException occured; mixed trace: $exStr\n";
}
}
=============== VERBOSE LOG ========================
Jul 28 01:41:49 JavaBridge DEBUG: Starting HTTP server thread from thread pool
Jul 28 01:41:50 JavaBridge DEBUG: Socket connection accepted
Jul 28 01:41:50 JavaBridge DEBUG: Starting HTTP server thread from thread pool
Jul 28 01:41:50 JavaBridge DEBUG: end:
Thread[JavaBridgeHttpServerThreadPool#1,5,JavaBridgeHttpServerThreadPool#1]
Jul 28 01:41:50 JavaBridge DEBUG: new context: 1@, # of contexts: 1
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@1113708 --> <I v="0"
m="updateJarLibraryPath" p="I" >
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@1113708 --> <S v="/var/www/prove" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@1113708 --> <S v="./" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@1113708 --> </I>
Jul 28 01:41:50 JavaBridge DEBUG:
Invoking [Object 3341135 - Class:
php.java.bridge.JavaBridge:ID783148:LOADER-ID11126876].updateJarLibraryPath([Object
19456522 - Class: java.lang.String:ID17829242:LOADER-ID0],[Object
15006066 - Class: java.lang.String:ID17829242:LOADER-ID0]);
Jul 28 01:41:50 JavaBridge DEBUG:
Result [Object null]
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@1113708 <-- <N />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@1113708 re-directing to port#
Socket:9267
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@1113708 waiting for context: 1@
Jul 28 01:41:50 JavaBridge DEBUG: end:
Thread[JavaBridgeHttpServerThreadPool#2,5,JavaBridgeHttpServerThreadPool#2]
Jul 28 01:41:50 JavaBridge DEBUG: starting a new ContextRunner
php.java.bridge.http.ContextRunner@b4d3d5
Jul 28 01:41:50 JavaBridge DEBUG: Added LOADER-ID29315749
OrigPath: ;/var/www/prove
Translated: file:/var/www/prove/
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <C v="ObjPassing" p="I" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> </C>
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class: ObjPassing
from: LOADER-ID29315749
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class:
java.lang.Object from: LOADER-ID29315749
Jul 28 01:41:50 JavaBridge DEBUG:
Invoking [Object 8843841 - Class:
ObjPassing:ID25872184:LOADER-ID29315749].ObjPassing();
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 <-- <O v="1" p="O"/>
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <I v="1"
m="testMe" p="I" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> </I>
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class: IVisit from:
LOADER-ID29315749
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class:
java.lang.String from: LOADER-ID29315749
Jul 28 01:41:50 JavaBridge DEBUG:
Invoking [Object 8843841 - Class:
ObjPassing:ID25872184:LOADER-ID29315749].testMe();
Jul 28 01:41:50 JavaBridge DEBUG:
Result [Object 11546234 - Class: java.lang.String:ID17829242:LOADER-ID0]
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 <-- <O v="2" p="O"/>
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <I v="0"
m="castToString" p="I" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <O v="2" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> </I>
Jul 28 01:41:50 JavaBridge DEBUG:
Invoking [Object 3341135 - Class:
php.java.bridge.JavaBridge:ID783148:LOADER-ID11126876].castToString([Object
11546234 - Class: java.lang.String:ID17829242:LOADER-ID0]);
Jul 28 01:41:50 JavaBridge DEBUG:
Result [Object 11546234 - Class: java.lang.String:ID17829242:LOADER-ID0]
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 <-- <S v="ZnVuemlvbm8=
"/>
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <U v="2" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <I v="0"
m="makeClosure" p="I" >
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <L v="1" p="O" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> </I>
Jul 28 01:41:50 JavaBridge DEBUG:
Invoking [Object 3341135 - Class:
php.java.bridge.JavaBridge:ID783148:LOADER-ID11126876].makeClosure([Object
27432475 - Class: java.lang.Long:ID19727353:LOADER-ID0]);
Jul 28 01:41:50 JavaBridge DEBUG:
Result [Object 6290200 - Class:
php.java.bridge.PhpProcedureProxy:ID22936951:LOADER-ID11126876]
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 <-- <O v="3" p="O"/>
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <I v="1" m="visit" p="I" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <O v="3" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> </I>
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 Selected: public void
ObjPassing.visit(java.lang.Object) 0
Jul 28 01:41:50 JavaBridge DEBUG:
Invoking [Object 8843841 - Class:
ObjPassing:ID25872184:LOADER-ID29315749].visit([Object 1026511 -
Class: $Proxy0:ID24670264:LOADER-ID1088076]);
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class:
java.lang.System from: LOADER-ID29315749
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class:
java.io.PrintStream from: LOADER-ID29315749
metodo visit, param obj
Jul 28 01:41:50 JavaBridge DEBUG:
Result [Object null]
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 <-- <N />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <U v="3" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <I v="0"
m="makeClosure" p="I" >
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <L v="2" p="O" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> </I>
Jul 28 01:41:50 JavaBridge DEBUG:
Invoking [Object 3341135 - Class:
php.java.bridge.JavaBridge:ID783148:LOADER-ID11126876].makeClosure([Object
5592862 - Class: java.lang.Long:ID19727353:LOADER-ID0]);
Jul 28 01:41:50 JavaBridge DEBUG:
Result [Object 13271847 - Class:
php.java.bridge.PhpProcedureProxy:ID22936951:LOADER-ID11126876]
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 <-- <O v="4" p="O"/>
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <I v="1"
m="visit2" p="I" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <O v="4" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> </I>
Jul 28 01:41:50 JavaBridge DEBUG:
Invoking [Object 8843841 - Class:
ObjPassing:ID25872184:LOADER-ID29315749].visit2([Object 23631794 -
Class: $Proxy0:ID24670264:LOADER-ID1088076]);
metodo visit2
Jul 28 01:41:50 JavaBridge DEBUG:
Result [Object null]
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 <-- <N />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <U v="4" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <I v="0"
m="makeClosure" p="I" >
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <L v="3" p="O" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> </I>
Jul 28 01:41:50 JavaBridge DEBUG:
Invoking [Object 3341135 - Class:
php.java.bridge.JavaBridge:ID783148:LOADER-ID11126876].makeClosure([Object
29321072 - Class: java.lang.Long:ID19727353:LOADER-ID0]);
Jul 28 01:41:50 JavaBridge DEBUG:
Result [Object 18881061 - Class:
php.java.bridge.PhpProcedureProxy:ID22936951:LOADER-ID11126876]
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 <-- <O v="5" p="O"/>
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <I v="1" m="visit" p="I" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <O v="5" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> </I>
Jul 28 01:41:50 JavaBridge DEBUG:
Invoking [Object 8843841 - Class:
ObjPassing:ID25872184:LOADER-ID29315749].visit([Object 9737354 -
Class: $Proxy0:ID24670264:LOADER-ID1088076]);
metodo visit, param obj
Jul 28 01:41:50 JavaBridge DEBUG:
Result [Object null]
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 <-- <N />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <U v="5" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <C v="IVisit" p="C" >
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> </C>
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class: IVisit from:
LOADER-ID29315749
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 <-- <O v="6" p="O"/>
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <I v="0"
m="makeClosure" p="I" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <L v="4" p="O" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <O v="" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <O v="6" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> </I>
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 weight long class
php.java.bridge.PhpExactNumber: 0
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 weight interface
java.util.Map null: 0
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 weight class
[Ljava.lang.Class; interface IVisit: 9999
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 best: public
java.lang.Object
php.java.bridge.JavaBridge.makeClosure(long,java.util.Map,java.lang.Class[])
9999
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 weight long class
php.java.bridge.PhpExactNumber: 0
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 weight interface
java.util.Map null: 0
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 weight class
java.lang.Class interface IVisit: 0
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 Selected: public
java.lang.Object
php.java.bridge.JavaBridge.makeClosure(long,java.util.Map,java.lang.Class)
0
Jul 28 01:41:50 JavaBridge DEBUG:
Invoking [Object 3341135 - Class:
php.java.bridge.JavaBridge:ID783148:LOADER-ID11126876].makeClosure([Object
24087760 - Class: java.lang.Long:ID19727353:LOADER-ID0],[Object
null],[Object 8761216 - Class:
java.lang.Class:ID10748354:LOADER-ID0]);
Jul 28 01:41:50 JavaBridge DEBUG:
Result [Object 12915541 - Class:
php.java.bridge.PhpProcedureProxy:ID22936951:LOADER-ID11126876]
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 <-- <O v="7" p="O"/>
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <U v="6" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <I v="1" m="visit" p="I" >
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <O v="7" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> </I>
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class:
java.lang.reflect.Proxy from: LOADER-ID29315749
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class:
java.lang.Throwable from: LOADER-ID29315749
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class:
java.lang.RuntimeException from: LOADER-ID29315749
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class:
java.lang.Error from: LOADER-ID29315749
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class:
java.lang.reflect.UndeclaredThrowableException from: LOADER-ID29315749
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class:
java.lang.ClassNotFoundException from: LOADER-ID29315749
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class:
java.lang.NoSuchMethodException from: LOADER-ID29315749
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class:
java.lang.NoSuchMethodError from: LOADER-ID29315749
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class:
java.lang.NoClassDefFoundError from: LOADER-ID29315749
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class:
java.lang.reflect.InvocationHandler from: LOADER-ID29315749
Jul 28 01:41:50 JavaBridge DEBUG: trying to load class:
java.lang.Class from: LOADER-ID29315749
Jul 28 01:41:50 JavaBridge DEBUG:
Invoking [Object 8843841 - Class:
ObjPassing:ID25872184:LOADER-ID29315749].visit([Object 1333195 -
Class: $Proxy1:ID23063136:LOADER-ID29315749]);
metodo visit, param obj
Jul 28 01:41:50 JavaBridge DEBUG:
Result [Object null]
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 <-- <N />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <U v="7" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <U v="1" />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <I v="0" m="reset" p="I" >
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> </I>
Jul 28 01:41:50 JavaBridge DEBUG:
Invoking [Object 3341135 - Class:
php.java.bridge.JavaBridge:ID783148:LOADER-ID11126876].reset();
Jul 28 01:41:50 JavaBridge WARNING: 32fb4f@10b9d04 Your PHP script has
called the privileged procedure "reset()", which resets the backend to
its initial state. Therefore all session variables and all caches are
now gone.
Jul 28 01:41:50 JavaBridge DEBUG:
Result [Object null]
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 <-- <N />
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <F p="A" />
Jul 28 01:41:50 JavaBridge DEBUG: end:
Thread[JavaBridgeContextRunner#1,5,JavaBridgeContextRunner#1]
Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 <-- <F p="A"/>
Jul 28 01:41:50 JavaBridge DEBUG: context finished: 1@
Jul 28 01:41:50 JavaBridge DEBUG: removed context: Context# 1@,
isInitialized: false, # of contexts: 0
Jul 28 01:41:50 JavaBridge DEBUG: end:
Thread[JavaBridgeContextRunner#1,5,JavaBridgeContextRunner#1]
|
|
From: <php...@li...> - 2007-07-28 12:17:36
|
Hi,
are you sure that you call the right code?
According to your log java_get_closure() is called with only one argument:
> Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <I v="0"
> m="makeClosure" p="I" >
> Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> <L v="1" p="O" />
> Jul 28 01:41:50 JavaBridge DEBUG: 32fb4f@10b9d04 --> </I>
Since the bridge doesn't have any information about the type, "Object" is assumed.
Regards,
Jost Boekemeier
dddd
|
|
From: <php...@li...> - 2007-07-28 14:04:06
|
Hi,
> are you sure that you call the right code?
it's the cache problem I've mentioned before. Is that really a problem in practice?
If so, I could prepare a version 3.2.1b, which switches off the cache when one of the arguments
is a proxy for a dynamic proxy.
Regards,
Jost Boekemeier
__________________________________ Wissenswertes für Bastler und Hobby Handwerker. BE A BETTER HEIMWERKER! www.yahoo.de/clever
|
|
From: <php...@li...> - 2007-07-29 08:26:27
|
2007/7/28, php...@li... <php...@li...>: > it's the cache problem I've mentioned before. Is that really a problem in practice? > If so, I could prepare a version 3.2.1b, which switches off the cache when one of the arguments > is a proxy for a dynamic proxy. the bridge caches the first istance of Obj that i create without any particular interface, and when i try to create a new istance of Obj with IVisit interface, the bridge uses the cached version anyhow. Is it right? then, if i create the first istance with all the interfaces i need, i should have no caching problem. right? if i'm right, i don't need a new version. maybe, it would be nice to compare the proxy passed as argument and the cached one checking their interfaces too (i suppose the bridge checks the class only) thank you a lot for paying me attention! my best greeetings |
|
From: <php...@li...> - 2007-07-30 09:02:41
Attachments:
php-java-bridge-4.2.1a_to_4.2.1b.diff
|
Hi,
> the bridge caches the first istance of Obj that i create without any
> particular interface
sort of. The cache algorithm applies before the dynamic proxy proxy is resolved;
the cache sees a ProcedureProxy, not a DynamicProxy.
> , and when i try to create a new istance of Obj
> with IVisit interface, the bridge uses the cached version anyhow. Is
> it right?
Yes. However, I have attached a patch which solves this problem.
Thank you very much for reporting this issue!
Regards,
Jost Boekemeier
dddd |