Re: Using an interface between two dl'ed applications

Niclas Hedhman <[email protected]> Mon, 19 Jan 2009 16:14:08 +0100
Newsgroups gmane.comp.java.sun.jini
Message-ID <[email protected]>
On Mon, Jan 19, 2009 at 2:49 PM, Calum Shaw-Mackay
<[email protected]> wrote:
> Okay to make things clearer

Thanks.

> System 'A' is a container of sorts, Object 'B' is a component that Object C
> (the caller) wishes to utilise and conenct with at runtime

Well, a lot depends on what the "Container of Sorts" really do.

It definitely looks like the classes will end up in separate
classloader, hence be perceived different. AFAICT, you are out of
luck, unless you can dig up some cool feature in the container. What
container are we talking about?
But hold on a second, if the container passes an instance from B to C,
then there should not be much classloading involved. You should more
likely get a ClassCastException. Weird.

One way you should get this to work would be a reflective bridge,
which is a lot more effective than networked communications. In
essence;

 Create in C a dynamic proxy implementing Interface, whose invocation
handler has a reference to the object retrieved from B, and the
InvHandler do

public Object invoke( Object proxy, Method m, Object[] args )
{
   Method m2 = b.getMethod( m.getName(), m.getArgumentTypes() );
   return m.invoke( b, m2, args );
}

but you will still have problems if any arguments are other shared types.


Cheers
--
http://www.qi4j.org - New Energy for Java



-- 
http://www.qi4j.org - New Energy for Java

--------------------------------------------------------------------------
Getting Started:     http://www.jini.org/wiki/Category:Getting_Started
Community Web Site:  http://jini.org
jini-users Archive:  http://archives.java.sun.com/archives/jini-users.html
Unsubscribing:       email "signoff JINI-USERS"  to [email protected]