Re: Dynamic Class Loading & AbstractMethodError

Miguel Correia Ricardo <[email protected]>
Newsgroups gmane.comp.java.sun.rmi
Message-ID <[email protected]>
Hello again!

I've decided to follow the advices of the article "The Lifecycle of an
RMI Server", and change somethings in setup of my applications.

[1] I've started the rmiregistry like this:  rmiregistry
-J-Dsun.rmi.loader.logLevel=VERBOSE,
with no CLASSPATH defined.

[2] Launched a CustomClassLoader that listen's for HTTP requests in
port 3000. And placed all the classes of my system in a directory that
is used by the CustomClassLoader.

[2] I've placed in a directory called server the following files:
Task.class; TaskMessage.class; MyServerInterface.class;
MyServerInterfaceImpl.class; MyServerInterfaceImpl_Stub.class

[3] Launched the server like this: java -cp server
-Djava.security.policy="policy.all"
-Djava.rmi.server.codebase="http:/localhost:3000/"
MyServerInterfaceImpl

[4] And i've noticed, seeing the rmiregistry console,once i ran the
server, that the downloaded classes were: Task.class;
MyServerInterfaceImpl_Stub.class; MyServerInterfaceImpl.class

--First question: Why is it always necessary to place all the classes
of my application in the classpath of my server, if they are
downloaded by the rmiregistry? Is it because of the codebase? RMI has
to download the classes to force the codebase to be set? But if that
is true, the classes on the classpath of the server, are only
necessary to launch the server itself, because they will always be
downloaded from the CustomClassLoader, am i right?

[5] Second i've launched my client like this: java -cp client
-Dsun.rmi.loader.logLevel=VERBOSE -Djava.security.policy=policy.all
-Djava.security.manager MyClient

In the client directory were only these files: MyClient.class;
MyServerInterface.class; Task.class

And, when i ran the client, the downloaded files were:
TaskMessage.class; MyServerInterfaceImpl_Stub.class

And this time all went well.

With the verbose flag's i've noticed that when rmiregistry downloaded
the file, the output message is "found via codebase". But when is the
client it says "found via defaultLoader...
defined by http:/localhost:3000". That's confusing... Java states that
is using defaultLoder,
but is downloading the classes..."found via codebase" is the proper
message i think...

But the real question is...If i don't put the TaskMessage.class inside
the directory of server,
even if this is one of the classes that the rmiregistry doesn't
download(see point [4]), the client will not work(it complains of
NoDefClassFoundError) Why? Is it always necessary to duplicate the
number of classes? One in the customclassloader and in the classpath
of the server? In this case, the TaskMessage.class has to be in both
places? Otherwise it will not work?

If one can help me, i appreciate!

Thanks,
Miguel




On 10/17/05, Miguel Correia Ricardo <[email protected]> wrote:
> Hello to everyone!
>
> I'm a newbie when it matters to dynamic class loading.
>
> What's happening is this:
>
> 1- I start rmiregistry
> 2- I Launch a RMI server with one method only. And this RMI stub is
> dynamically downloaded thru a ClassServer(like the one in the O'Reilly Java
> RMI book).
>
> Let's say that the only remote method that exists is: "public Task getTask();"
> (And Task being a interface)
>
> 3- In the implementation of that method i do "return new TaskMessage();"
> (that implements Task interface)
>
> 4- I launch the client, and the client get's the stub and Task.class
> dynamically.(Only these one by the way).
>
> 5- And for some reason, that i don't understand, java throws the following
> error: AbstractMethodError " "StubFileName".getTask(); " In the following
> line of the client source code:
>
> "Task t = stub.getTask();"
>
> Does anyone has a sugestion?
>
> And another question, i've noticed that java was only interested in the
> interface and in the stub. But if i have various concrete classes that
> implements the Task Interface, how does he know which one to get? Or that is
> done automatically when i invoke a method of that class... In these case i
> didn't had the chance to see how it run's, because it gives the error in the
> line stated before.
>
> I hope anyone can help.
>
> Thank you,
> Miguel
>
> ===========================================================================
> 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
>
>

===========================================================================
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.