Re: Dynamic Class downloading
Kalyan Mudumbai <[email protected]>
| Newsgroups | gmane.comp.java.sun.rmi |
|---|---|
| Message-ID | <[email protected]> |
Thanks Peter. It's really enlightening to see your mail and the discussions.
Thank you very much.
Does your point about class loaders mean that, say, I am using a
URLClassLoader which is pointing to the RMI Server Code base and then I make
this class loader to be the one that also loads my code snippet, then do you
think it would work without having the interface classes on the client
classpath? I tried this option too, but of no luck. I still get the
NoClassDefFoundError.
For example (the pseudo code might look like this):
public ClassA
{
ClassA()
{
Object o = context.lookup("example");
ExampleHome home = (ExampleHome) o;
}
}
main()
{
URLClassLoader ucl = new URLClassLoader(new URL[] {new URL("
http://rmi.server.codebase:port/")});
ucl.loadClass("ClassA");
}
Thanks,
Kalyan.
On 10/12/05, Peter Jones - JavaSoft East <[email protected]> wrote:
>
> > Does the dynamic class downloading feature of RMI download any class
> that's
> > not available in the client's class path?
> >
> > Let's say I have the following code on the client:
> >
> > Object o = context.lookup("jndiName");
> > ExampleHome h = (ExampleHome)o;
> >
> > (I know that I have to use PortableRemote.. class to typecast, but it's
> just
> > for brevity's sake that I simply typcasted it)
>
> [Note that using PortableRemoteObject.narrow, instead of a normal cast
> expression, is only necessary when (possibly) using RMI-IIOP stubs.]
>
> > Now, is it mandatory that I have this the ExampleHome's class file in
> the
> > classpath for this client program to run? Or does it get dynamically
> > downloaded from the server (you can assume that it's already present on
> the
> > server, which exposes it using the codebase url).
>
> The simple answer to the first question is Yes, you must have
> ExampleHome in the client's class path. More precisely, ExampleHome
> must be loadable by the same class loader that defined the class
> containing the above code snippet, because that class's definition
> will have a symbolic reference to ExampleHome, which (by the Java VM
> specification) must be resolved by that class's defining class loader.
> The class loader used to download classes from another remote codebase
> doesn't come into play.
>
> This topic (can types directly referenced by client code be
> downloaded?) has come up several times on this list; see the following
> posts/threads for further disucssion:
>
> http://archives.java.sun.com/cgi-bin/wa?A2=ind9909&L=rmi-users&P=16343
> http://archives.java.sun.com/cgi-bin/wa?A2=ind0107&L=rmi-users&P=14759
> http://archives.java.sun.com/cgi-bin/wa?A2=ind0107&L=rmi-users&P=17803
> http://archives.java.sun.com/cgi-bin/wa?A2=ind0110&L=rmi-users&P=14664
> http://archives.java.sun.com/cgi-bin/wa?A2=ind0112&L=rmi-users&P=5706
> http://archives.java.sun.com/cgi-bin/wa?A2=ind0305&L=rmi-users&P=2858
>
> > If this class has to be present in the client's classpath, then what
> exactly
> > does the dynamic class downloading do?
>
> It can be used to download the actual classes of objects unmarshalled
> as part of arguments and return values, which may be implementations
> or subclasses of the types directly used by the receiving code. The
> most basic example is remote stub classes (which client applications
> should not reference directly). There is more information in this
> tutorial:
> http://java.sun.com/j2se/1.5.0/docs/guide/rmi/codebase.html
>
> In this tutorial, the client also provides classes to be downloaded by
> the server, a generic "compute server" that can execute tasks whose code
> it was not deployed with:
> http://java.sun.com/docs/books/tutorial/rmi/index.html
>
> Presentation #2 on this page, by John McClain, explores the benefits
> of dynamically loading "smart" proxy classes (i.e. not just simple
> remote stub classes) for remote services:
> http://www.jini.org/webinar/
>
> -- Peter
>
===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff RMI-USERS". For general help, send email to
[email protected] and include in the body of the message "help".
For a list of frequently asked RMI questions please refer to:
http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html
To view past RMI-USERS postings, please see:
http://archives.java.sun.com/archives/rmi-users.html