[exo-jcr-commits] exo-jcr SVN: r1396 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow: persistent and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Jan 14 12:03:14 EST 2010


Author: areshetnyak
Date: 2010-01-14 12:03:13 -0500 (Thu, 14 Jan 2010)
New Revision: 1396

Modified:
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/AbstractPersistedValueData.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFilePersistedValueData.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FilePersistedValueData.java
Log:
EXOJCR-404 : Add serializatio to AbstractPersistedValueData, FilePersistentValueData, CleanableFilePersistedValuData.

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/AbstractPersistedValueData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/AbstractPersistedValueData.java	2010-01-14 16:26:03 UTC (rev 1395)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/AbstractPersistedValueData.java	2010-01-14 17:03:13 UTC (rev 1396)
@@ -18,6 +18,11 @@
  */
 package org.exoplatform.services.jcr.impl.dataflow;
 
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
 import org.exoplatform.services.jcr.datamodel.ValueData;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
@@ -28,7 +33,7 @@
  * @author <a href="mailto:peter.nedonosko at exoplatform.com">Peter Nedonosko</a>
  * @version $Id$
  */
-public abstract class AbstractPersistedValueData implements ValueData
+public abstract class AbstractPersistedValueData implements ValueData, Externalizable
 {
 
    protected final static Log LOG = ExoLogger.getLogger("jcr.PersistedValueData");
@@ -39,6 +44,13 @@
    {
       this.orderNumber = orderNumber;
    }
+   
+   /**
+    *  Empty constructor to serialization.
+    */
+   protected AbstractPersistedValueData()
+   {
+   }
 
    /**
     * {@inheritDoc}
@@ -69,4 +81,14 @@
     * @throws RepositoryException if error ocurs
     */
    public abstract TransientValueData createTransientCopy() throws RepositoryException;
+   
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      orderNumber = in.readInt();
+   }
+
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      out.writeInt(orderNumber);
+   }
 }

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFilePersistedValueData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFilePersistedValueData.java	2010-01-14 16:26:03 UTC (rev 1395)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CleanableFilePersistedValueData.java	2010-01-14 17:03:13 UTC (rev 1396)
@@ -41,7 +41,14 @@
 
    protected final static Log LOG = ExoLogger.getLogger("jcr.CleanableFileStreamValueData");
 
-   protected final FileCleaner cleaner;
+   protected FileCleaner cleaner;
+   
+   /**
+    *   Empty constructor to serialization.
+    */
+   public CleanableFilePersistedValueData()
+   {
+   }
 
    /**
     * CleanableFilePersistedValueData constructor.
@@ -74,12 +81,16 @@
 
          if (!file.delete())
          {
-            cleaner.addFile(file);
-
-            if (LOG.isDebugEnabled())
+            //TODO FileCleaner maybe null. 
+            if (cleaner != null)
             {
-               LOG.debug("Could not remove temporary file on finalize: inUse=" + (((SwapFile)file).inUse()) + ", "
-                  + file.getAbsolutePath());
+               cleaner.addFile(file);
+   
+               if (LOG.isDebugEnabled())
+               {
+                  LOG.debug("Could not remove temporary file on finalize: inUse=" + (((SwapFile)file).inUse()) + ", "
+                     + file.getAbsolutePath());
+               }
             }
          }
       }

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FilePersistedValueData.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FilePersistedValueData.java	2010-01-14 16:26:03 UTC (rev 1395)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/FilePersistedValueData.java	2010-01-14 17:03:13 UTC (rev 1396)
@@ -22,11 +22,14 @@
 import org.exoplatform.services.jcr.impl.dataflow.AbstractPersistedValueData;
 import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
 
+import java.io.Externalizable;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.io.OutputStream;
 import java.nio.ByteBuffer;
 import java.nio.MappedByteBuffer;
@@ -46,11 +49,20 @@
 public class FilePersistedValueData extends AbstractPersistedValueData
 {
 
+   private static final long serialVersionUID = -8183328056670315388L;
+   
    protected File file;
 
    protected FileChannel channel;
 
    /**
+    *   Empty constructor to serialization.
+    */
+   public FilePersistedValueData()
+   {
+   }
+   
+   /**
     * FilePersistedValueData  constructor.
     * @param orderNumber int
     * @param file File
@@ -214,4 +226,24 @@
          fch.close();
       }
    }
+
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      super.readExternal(in);
+
+      // read canonical file path
+      byte[] buf = new byte[in.readInt()];
+      
+      file = new File(new String(buf, "UTF-8"));
+   }
+
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      super.writeExternal(out);
+      
+      // write canonical file path 
+      byte[] buf = file.getCanonicalPath().getBytes("UTF-8");
+      out.writeInt(buf.length);
+      out.write(buf);
+   }
 }



More information about the exo-jcr-commits mailing list