Re: [jboss-user] [EJB 3.0] - JBoss 4.2.1 RemoteEJB Lookup ClassCastException
by Marcus Linke
Marcus Linke [http://community.jboss.org/people/marcuslinke] replied to the discussion
"JBoss 4.2.1 RemoteEJB Lookup ClassCastException"
To view the discussion, visit: http://community.jboss.org/message/549052#549052
--------------------------------------------------------------
I've read this and found a simpler solution / workaround for this problem (without the need of patching). It's simple to integrate the appropriate code taken from EJBTHREE-1889 into the own JNDI lookup. Because of performance reasons this hack of course should be used only for JVM internal remote lookups (which is the case with isolated EAR's). This may be realized by using different JNDI lookup wrapper classes...
public class JBossRemoteJndiLookup<T> {
public T lookup(String resourceName) {
Object o = new InitialContext().lookup(resourceName);
o = refineObjectInContextClassLoader(o);
return (T) o;
}
/**
* This is a workaround for http://community.jboss.org/thread/111016 http://community.jboss.org/thread/111016. It is taken from
* https://jira.jboss.org/browse/EJBTHREE-1889 https://jira.jboss.org/browse/EJBTHREE-1889. See modifications of ProxyObjectFactory.java
*/
private Object refineObjectInContextClassLoader(Object o) {
// EJBTHREE-1889: if the lookup has been performed locally on a remote (business)
// interface that's defined in the current TCL, then the proxy must implement
// that TCL defined interface.
// redefine in TCL
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
try {
o = redefineObjectInClassLoader(o, tcl);
} catch (Exception e) {
throw new RuntimeException(e);
}
return o;
}
private Object redefineObjectInClassLoader(Object obj, ClassLoader target) throws ClassNotFoundException,
IOException {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bout);
out.writeObject(obj);
out.flush();
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
ObjectInputStream in = new ObjectInputStreamWithClassLoader(bin, target);
Object result = in.readObject();
in.close();
return result;
}
}
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/549052#549052]
Start a new discussion in EJB 3.0 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
15 years, 10 months
[JBoss Microcontainer Development] - Removing cached entry in VFSCLPolicy on load
by Ales Justin
Ales Justin [http://community.jboss.org/people/alesj] created the discussion
"Removing cached entry in VFSCLPolicy on load"
To view the discussion, visit: http://community.jboss.org/message/549039#549039
--------------------------------------------------------------
Does something like this make sense to add directly, or should it be optional?
public VFSClassLoaderPolicy(String name, VirtualFile[] roots, VirtualFile[] excludedRoots)
{
...
this.excludedRoots = excludedRoots;
+ addClassFoundHandler(new VFSCacheRemove());
}
+
+ private class VFSCacheRemove implements ClassFoundHandler
+ {
+ public void classFound(ClassFoundEvent event)
+ {
+ String className = event.getClassName();
+ String path = ClassLoaderUtils.classNameToPath(className);
+ vfsCache.remove(path); // remove the entry once we loaded the class
+ }
+ }
}
This would definitely decrease the memory, since every already loaded class's lookup cache would be released.
And with CL cache fixed, we access the class on next invocaton directly form CL cache, hence no need to path cache.
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/549039#549039]
Start a new discussion in JBoss Microcontainer Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
15 years, 10 months