[exo-jcr-commits] exo-jcr SVN: r748 - jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Nov 18 06:54:25 EST 2009


Author: nzamosenchuk
Date: 2009-11-18 06:54:25 -0500 (Wed, 18 Nov 2009)
New Revision: 748

Modified:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java
Log:
EXOJCR-243: Updated LockData to be Externalizable.

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java	2009-11-18 11:28:16 UTC (rev 747)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java	2009-11-18 11:54:25 UTC (rev 748)
@@ -18,6 +18,13 @@
  */
 package org.exoplatform.services.jcr.impl.core.lock;
 
+import org.exoplatform.services.jcr.impl.Constants;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
 /**
  * Created by The eXo Platform SAS.
  * 
@@ -25,7 +32,7 @@
  * @version $Id$
  */
 
-public class LockData
+public class LockData implements Externalizable
 {
    /**
     * The time of birth. From this time we start count the time of death. death = birthday+TIME_OUT;
@@ -36,14 +43,9 @@
     * If isDeep is true then the lock applies to this node and all its descendant nodes; if false,
     * the lock applies only to this, the holding node.
     */
-   private final boolean deep;
+   private boolean deep;
 
    /**
-    * 
-    */
-   private boolean live;
-
-   /**
     * A lock token is a string that uniquely identifies a particular lock and acts as a “key”
     * allowing a user to alter a locked node. LockData stores only token hash.
     */
@@ -65,7 +67,7 @@
     * expire until explicitly unlocked or automatically unlocked due to a implementation-specific
     * limitation, such as a timeout.
     */
-   private final boolean sessionScoped;
+   private boolean sessionScoped;
 
    /**
     * <B>8.4.9 Timing Out</B> An implementation may unlock any lock at any time due to
@@ -73,6 +75,13 @@
     */
    private long timeOut;
 
+   // Need for Externalizable
+   public LockData()
+   {
+      this.sessionScoped = false;
+      this.deep = false;
+   }
+
    /**
     * @param nodeIdentifier
     * @param lockToken
@@ -90,7 +99,6 @@
       this.sessionScoped = sessionScoped;
       this.owner = owner;
       this.timeOut = timeOut;
-      this.live = true;
       this.birthday = System.currentTimeMillis() / 1000;
    }
 
@@ -172,4 +180,58 @@
       return timeOut;
    }
 
+   /**
+    * @see java.io.Externalizable#readExternal(java.io.ObjectInput)
+    */
+   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+   {
+      // read boolean
+      this.deep = in.readBoolean();
+      this.sessionScoped = in.readBoolean();
+      // read long
+      this.birthday = in.readLong();
+      this.timeOut = in.readLong();
+      //read strings
+      // read uuid
+      byte[] buf;
+      buf = new byte[in.readInt()];
+      in.readFully(buf);
+      this.nodeIdentifier = new String(buf, Constants.DEFAULT_ENCODING);
+      // read uuid
+      buf = new byte[in.readInt()];
+      in.readFully(buf);
+      this.owner = new String(buf, Constants.DEFAULT_ENCODING);
+      // read uuid
+      buf = new byte[in.readInt()];
+      in.readFully(buf);
+      this.tokenHash = new String(buf, Constants.DEFAULT_ENCODING);
+   }
+
+   /**
+    * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
+    */
+   public void writeExternal(ObjectOutput out) throws IOException
+   {
+      // write boolean
+      out.writeBoolean(deep);
+      out.writeBoolean(sessionScoped);
+      // write long
+      out.writeLong(birthday);
+      out.writeLong(timeOut);
+      // write string
+      // node uuid
+      byte[] ptbuf = nodeIdentifier.getBytes(Constants.DEFAULT_ENCODING);
+      out.writeInt(ptbuf.length);
+      out.write(ptbuf);
+      // node uuid
+      ptbuf = owner.getBytes(Constants.DEFAULT_ENCODING);
+      out.writeInt(ptbuf.length);
+      out.write(ptbuf);
+      // node uuid
+      ptbuf = tokenHash.getBytes(Constants.DEFAULT_ENCODING);
+      out.writeInt(ptbuf.length);
+      out.write(ptbuf);
+
+   }
+
 }



More information about the exo-jcr-commits mailing list