Re: ClassCastException after retrieving an Entry
Gregg Wonderly <[email protected]> Mon, 8 Jan 2007 10:19:02 -0600
| Newsgroups | gmane.comp.java.sun.javaspaces |
|---|---|
| Message-ID | <[email protected]> |
Christian Hager wrote:
> Ok I modified the code again a little.
>
> ClassLoaderUtil.displayContextClassLoaderTree ();
> Entry entry = javaSpace.take (taskTmpl, txn, 30000);
> ClassLoaderUtil.displayClassLoaderTree (entry.getClass ().getClassLoader());
> Thread.currentThread ().setContextClassLoader
(entry.getClass().getClassLoader ());
> ClassLoaderUtil.displayContextClassLoaderTree ();
> ClassLoaderUtil.displayClassLoaderTree (TaskEntry.class.getClassLoader());
> TaskEntry task = (TaskEntry) entry;
This won't do what needs to be done. You need to do the following, in this order.
Entry entry;
ClassLoader ld = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(
TaskEntry.class.getClassLoader () );
entry = javaSpace.take (taskTmpl, txn, 30000);
} finally {
Thread.currentThread().setContextClassLoader( ld );
}
TaskEntry task = (TaskEntry) entry;
> I think the problem would be solved if I get TaskEntry to be loaded by the
> RMIClassLoader. Am I right? Does anyone know how to do this?
Not really. TaskEntry must be resolved by the same ClassLoader that is visible
in all contexts that it will be used.
Gregg Wonderly
===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff JAVASPACES-USERS". For general help, send email to
[email protected] and include in the body of the message "help".
To view past JAVASPACES-USERS postings, please see:
http://archives.java.sun.com/archives/javaspaces-users.html