[e-cvs] cvs commit: e/src/jsrc/org/erights/e/elib/serial PersistenceReplacer.java PersistenceResolver.java Serializer.java Unserializer.java

markm@eros.cs.jhu.edu markm@eros.cs.jhu.edu
Sun, 19 Aug 2001 20:45:04 -0400


markm       01/08/19 20:45:04

  Modified:    src/jsrc/org/erights/e/elib/serial PersistenceReplacer.java
                        PersistenceResolver.java Serializer.java
                        Unserializer.java
  Log:
  removed redundant streamHeader.  Comments reflect refactoring

Revision  Changes    Path
1.2       +14 -3     e/src/jsrc/org/erights/e/elib/serial/PersistenceReplacer.java

Index: PersistenceReplacer.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/serial/PersistenceReplacer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PersistenceReplacer.java	2001/08/19 22:26:10	1.1
+++ PersistenceReplacer.java	2001/08/20 00:45:04	1.2
@@ -21,11 +21,17 @@
 Contributor(s): ______________________________________.
 */
 
+import org.erights.e.elib.prim.E;
 import org.erights.e.elib.ref.Ref;
 import org.erights.e.elib.util.OneArgFunc;
 
 /**
- * 
+ * Used to specialize the Serializer so that, on checkpointing, a live object 
+ * may be replaced by a different object to be checkpointed as its 
+ * representative.
+ * <p>
+ * The corresponding revived object is not simply this representative.  It is 
+ * this representative as resolved by {@link PersistenceResolver}.
  *
  * @author <a href="mailto:markm@erights.org">Mark S. Miller</a>
  */
@@ -40,7 +46,12 @@
     private PersistenceReplacer() {}
     
     /**
-     * Just insists that ref {@link Ref#isPersistent(Object)}.
+     * If ref {@link Ref#isPersistent(Object)}, then this currently just 
+     * returns ref; otherwise an appropriately broken reference.
+     * <p>
+     * This way, a non-persistent object in a graph doesn't prevent the graph 
+     * from being checkpointed.  However, that doesn't mean such a 
+     * partially-broken graph will be revivable or useful.
      */
     public Object run(Object ref) {
         ref = Ref.resolution(ref);
@@ -55,6 +66,6 @@
                 return Ref.broken("Was a promise");
             }
         }
-        return Ref.broken("not persistent: " + ref);
+        return Ref.broken("not persistent: " + E.toQuote(ref));
     }
 }



1.2       +1 -1      e/src/jsrc/org/erights/e/elib/serial/PersistenceResolver.java

Index: PersistenceResolver.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/serial/PersistenceResolver.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PersistenceResolver.java	2001/08/19 22:26:10	1.1
+++ PersistenceResolver.java	2001/08/20 00:45:04	1.2
@@ -25,7 +25,7 @@
 import org.erights.e.elib.util.OneArgFunc;
 
 /**
- * 
+ * Used to specialize the Unserializer for reviving from persistent state.
  *
  * @author <a href="mailto:markm@erights.org">Mark S. Miller</a>
  */



1.9       +27 -19    e/src/jsrc/org/erights/e/elib/serial/Serializer.java

Index: Serializer.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/serial/Serializer.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Serializer.java	2001/08/19 22:26:10	1.8
+++ Serializer.java	2001/08/20 00:45:04	1.9
@@ -30,13 +30,21 @@
 
 /**
  * Made usable from E by parameterization rather than subclassing.
- * This stream should be used at least for persistence and pluribus.  It will 
- * probably need more parameters, but we should add them as we find we need 
- * them, rather than create another subclass. 
  * <p>
- * Note that reset() is considered legitimate usage of a Serializer.
+ * This stream should be used at least for persistence and CapTP.  It is 
+ * specialized by composition rather than subclassing -- by providing a 
+ * replacer(..) function rather than overriding the .replaceObject(..) 
+ * method, so E programs (which can't subclass Java classes) can still 
+ * specialize serialization behavior. 
+ * <p>
+ * Serializer will probably need more parameters, but we should add them as 
+ * we find we need them, rather than create another subclass. 
+ * <p> 
+ * Likely additional parameters: <ul>
+ * <li>version string
+ * </ul>
  * <p>
- * Likely additional parameters: version string
+ * Note that reset() is considered legitimate usage of a Serializer.
  *
  * @author <a href="mailto:markm@erights.org">Mark S. Miller</a>
  */
@@ -45,25 +53,26 @@
     private final OneArgFunc myReplacer;
     
     /**
-     * Makes an ObjectOutputStream on out with the following differences:
-     * 1) The stream header is written first, identifying the format about to 
-     * be written to the stream.
-     * 2) When you do serializer.writeObject(foo), rather than foo being 
-     * written, replacer(foo) is written, and likewise for every object 
-     * reachable from the replacement objects.  replacer is used as the 
-     * overriding of replaceObject().  See the Java Serialization spec for 
-     * the detailed implications of this.
+     * Makes Serializer specialized by 'replacer'.
+     * <p>
+     * Makes an ObjectOutputStream on out with the following differences: 
+     * <ul> 
+     * <li>When you do serializer.writeObject(foo), rather than foo being 
+     *     written, replacer(foo) is written, and likewise for every object 
+     *     reachable from the replacement objects.
+     * </ul>
+     * replacer(..) is used as the overriding of .replaceObject(..).  See the 
+     * Java Serialization spec for the detailed implications of this. 
      */
     public Serializer(OutputStream out, OneArgFunc replacer)
     throws IOException {
         super(out);
         enableReplaceObject(true);
         myReplacer = replacer;
-        writeStreamHeader();
     }
     
     /**
-     * replacer defaults to identity function
+     * replacer(..) defaults to {@link PersistenceReplacer}.
      */
     public Serializer(OutputStream out) throws IOException {
         this(out, PersistenceReplacer.TheOne);
@@ -85,7 +94,7 @@
     }
     
     /**
-     * replacer defaults to the identity function
+     * replacer(..) defaults to {@link PersistenceReplacer}.
      */
     static public byte[] record(Object specimen)
     throws IOException {
@@ -104,7 +113,7 @@
     }
     
     /**
-     * replacer defaults to the identity function
+     * replacer(..) defaults to {@link PersistenceReplacer}.
      */
     static public void recordFile(File file, Object specimen)
     throws IOException {
@@ -112,8 +121,7 @@
     }
     
     /**
-     * Just applies the replacer I was constructed with, and insists that the 
-     * resulting object {@link Ref#isPersistent(Object)}.
+     * returns the {@link Ref#resolution(Object)} of replacer(ref)
      */
     protected Object replaceObject(Object ref) {
         return Ref.resolution(myReplacer.run(ref));



1.8       +5 -8      e/src/jsrc/org/erights/e/elib/serial/Unserializer.java

Index: Unserializer.java
===================================================================
RCS file: /cvs/e/src/jsrc/org/erights/e/elib/serial/Unserializer.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Unserializer.java	2001/08/19 22:26:10	1.7
+++ Unserializer.java	2001/08/20 00:45:04	1.8
@@ -33,9 +33,9 @@
  * <p>
  * This stream should be used at least for persistence and CapTP.  It is 
  * specialized by composition rather than subclassing -- by providing a 
- * resolver(..) function rather than overriding the .resolver(..) method, so
- * E programs (which can't subclass Java classes) can still specialize 
- * unserialization behavior.
+ * resolver(..) function rather than overriding the .resolveObject(..) 
+ * method, so E programs (which can't subclass Java classes) can still 
+ * specialize unserialization behavior. 
  * <p>
  * Unserializer will probably need more parameters, but we should add them as 
  * we find we need them, rather than create another subclass. 
@@ -55,11 +55,9 @@
      * Makes an Unserializer specialized by 'resolver'.
      * <p>
      * Makes an ObjectInputStream on inp with the following differences: <ul>
-     * <li>The stream header is read first, checking that the format 
-     *     in which the stream is encoded in one we can read.
      * <li>When you do unserializer.readObject(), rather than the encoded 
-     *     object, let's say foo, being returned, resolver(foo) is used, and 
-     *     likewise for every object reachable from foo.  
+     *     object, let's say foo, being returned, resolver(foo) is returned, 
+     *     and likewise for every object reachable from foo. 
      * </ul>
      * resolver(..) is used as the overriding of .resolveObject(..).  See the 
      * Java Serialization spec for the detailed implications of this. 
@@ -69,7 +67,6 @@
         super(inp);
         enableResolveObject(true);
         myResolver = resolver;
-        readStreamHeader();
     }
     
     /**