[jboss-dev-forums] [Design the new POJO MicroContainer] - ClassInfo being serializable
alesj
do-not-reply at jboss.com
Wed Jul 11 07:29:18 EDT 2007
As http://jira.jboss.com/jira/browse/JBMICROCONT-128 states, ClassInfo is holding reference to TypeInfoFactory.
Solutions:
(a) making TypeInfoFactory transient - lazy constructing on deserialization
(b) making TypeInfoFactory serializable
Can (a) be done in reasonable way?
I've taken (b) approach.
Making TypeInfoFactory means making WeakTypeCache serializable.
Is this legit:
| public abstract class WeakTypeCache<T> implements Serializable
| {
| private static final long serialVersionUID = 7314636572425329549L;
|
| /** The cache */
| private transient Map<ClassLoader, Map<String, T>> cache;
|
| private Map<ClassLoader, Map<String, T>> getCache()
| {
| if (cache == null)
| cache = new WeakHashMap<ClassLoader, Map<String,T>>();
| return cache;
| }
|
| ...
|
| private synchronized Map<String, T> getClassLoaderCache(ClassLoader cl)
| {
| Map<ClassLoader, Map<String, T>> cache = getCache();
| Map<String, T> result = cache.get(cl);
| if (result == null)
| {
| result = new WeakValueHashMap<String, T>();
| cache.put(cl, result);
| }
| return result;
| }
| }
|
I've added 'new' WeakClassCache (similar to existing in commons) for JavassistTypeInfoFactoryImpl to extend.
| public abstract class WeakClassCache extends WeakTypeCache<Object>
| {
| private static final long serialVersionUID = 2352263033415675186L;
|
| protected Object instantiate(ParameterizedType type)
| {
| throw new UnsupportedOperationException("No such method in WeakClassCache from JBoss-Commons.");
| }
|
| protected void generate(ParameterizedType type, Object result)
| {
| throw new UnsupportedOperationException("No such method in WeakClassCache from JBoss-Commons.");
| }
| }
|
After doing this I'm able to get ClassInfoTestSuite running for Introspection test cases, but I get new failures for Javassist:
- CtClass not being serializable in JavassistInheritableAnnotationHolder
- javassist AnnotationImpl not being serializable
- ...
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4062925#4062925
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4062925
More information about the jboss-dev-forums
mailing list