[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: ClassInfo being serializable

adrian@jboss.org do-not-reply at jboss.com
Wed Jul 11 11:47:21 EDT 2007


I don't understand this new helper?


  | Modified: projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/ClassInfoImpl.java
  | ===================================================================
  | --- projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/ClassInfoImpl.java       2007-07-11 14:58:35 UTC (rev 63972)
  | +++ projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/ClassInfoImpl.java       2007-07-11 15:16:44 UTC (rev 63973)
  | @@ -26,6 +26,9 @@
  |  import java.util.Collection;
  |  import java.util.HashMap;
  |  import java.util.Map;
  | +import java.io.ObjectInputStream;
  | +import java.io.IOException;
  | +import java.io.ObjectOutputStream;
  |  
  |  import org.jboss.reflect.spi.ClassInfo;
  |  import org.jboss.reflect.spi.ConstructorInfo;
  | @@ -108,27 +111,86 @@
  |     protected PackageInfo packageInfo;
  |     
  |     /** The class info helper */
  | -   protected ClassInfoHelper classInfoHelper;
  | +   protected transient ClassInfoHelper classInfoHelper;
  |  
  |     /** The type info factory */
  | -   protected TypeInfoFactory typeInfoFactory;
  | +   protected transient TypeInfoFactory typeInfoFactory;
  |  
  |     /** The attachments */
  |     private transient TypeInfoAttachments attachments;
  |  
  | +   /** The serialization helper */
  | +   private SerializationHelper serializationHelper;
  | 

I don't really understand why you are serializing any state
except the annotatedElement.

All you need to do is rehook into the typeinfo factory using some package
protected method and recreate the other state during deserialization
(most of it can be left to be initialized lazily?)


  | public void readObject(...)
  | {
  |    super.readObject(...);
  |    typeInfoFactory = new IntrospectionTypeInfoFactory(...);
  |    classInfoHelper =   typeInfoFactory.getClassInfoHelper();
  |    // etc.
  | }
  | 

In fact, a much more trivial mechanism would be to use "readResolve"


  | Object readResolve()
  | {
  |    IntrospectionTypeInfoFactory factory = new IntrospectionTypeInfoFactory();
  |    return factory.getTypeInfo(annotatedElement);
  | }
  | 

Then you aren't creating multiple ClassInfo objects during deserialization,
especially if they are already present in the cache.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4063066#4063066

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4063066



More information about the jboss-dev-forums mailing list