[jbosscache-commits] JBoss Cache SVN: r7864 - in core/branches/flat/src/main/java/org/horizon: factories and 2 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Mar 5 12:45:04 EST 2009


Author: manik.surtani at jboss.com
Date: 2009-03-05 12:45:03 -0500 (Thu, 05 Mar 2009)
New Revision: 7864

Modified:
   core/branches/flat/src/main/java/org/horizon/container/CachedValue.java
   core/branches/flat/src/main/java/org/horizon/container/MVCCEntry.java
   core/branches/flat/src/main/java/org/horizon/factories/EntryFactory.java
   core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java
   core/branches/flat/src/main/java/org/horizon/interceptors/LockingInterceptor.java
   core/branches/flat/src/main/java/org/horizon/loader/StoredEntry.java
Log:
Minor performance tweaks after a brief profiling session

Modified: core/branches/flat/src/main/java/org/horizon/container/CachedValue.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/container/CachedValue.java	2009-03-05 17:22:27 UTC (rev 7863)
+++ core/branches/flat/src/main/java/org/horizon/container/CachedValue.java	2009-03-05 17:45:03 UTC (rev 7864)
@@ -1,6 +1,6 @@
 package org.horizon.container;
 
-public class CachedValue {
+public class CachedValue implements MVCCEntry {
    protected Object value;
    protected long modifiedTime;
 
@@ -20,15 +20,61 @@
       return modifiedTime;
    }
 
+   public Object getKey() {
+      return null;
+   }
+
    public final Object getValue() {
       return value;
    }
 
-   public final void setValue(Object value) {
+   public final Object setValue(Object value) {
       this.value = value;
+      return null;
    }
 
+   public final boolean isNullEntry() {
+      return false;
+   }
+
+   public void copyForUpdate(DataContainer container, boolean writeSkewCheck) {
+   }
+
+   public void commitUpdate(DataContainer container) {
+   }
+
+   public void rollbackUpdate() {
+   }
+
+   public final boolean isChanged() {
+      return false;
+   }
+
+   public final boolean isCreated() {
+      return false;
+   }
+
+   public void setCreated(boolean created) {
+   }
+
+   public final boolean isDeleted() {
+      return false;
+   }
+
+   public void setDeleted(boolean deleted) {
+   }
+
+   public final boolean isValid() {
+      return false;
+   }
+
+   public void setValid(boolean valid) {
+   }
+
    public long getLifespan() {
       return -1;
    }
+
+   public void setLifespan(long lifespan) {
+   }
 }
\ No newline at end of file

Modified: core/branches/flat/src/main/java/org/horizon/container/MVCCEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/container/MVCCEntry.java	2009-03-05 17:22:27 UTC (rev 7863)
+++ core/branches/flat/src/main/java/org/horizon/container/MVCCEntry.java	2009-03-05 17:45:03 UTC (rev 7864)
@@ -21,15 +21,13 @@
  */
 package org.horizon.container;
 
-import java.util.Map.Entry;
-
 /**
  * // TODO: MANIK: Document this
  *
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
  * @since 1.0
  */
-public interface MVCCEntry extends Entry {
+public interface MVCCEntry {
    boolean isNullEntry();
 
    void copyForUpdate(DataContainer container, boolean writeSkewCheck);
@@ -55,4 +53,10 @@
    long getLifespan();
 
    void setLifespan(long lifespan);
+
+   Object getKey();
+
+   Object getValue();
+
+   Object setValue(Object value);
 }

Modified: core/branches/flat/src/main/java/org/horizon/factories/EntryFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/EntryFactory.java	2009-03-05 17:22:27 UTC (rev 7863)
+++ core/branches/flat/src/main/java/org/horizon/factories/EntryFactory.java	2009-03-05 17:45:03 UTC (rev 7864)
@@ -35,7 +35,8 @@
    void releaseLock(InvocationContext ctx, Object key);
 
    /**
-    * Attempts to lock an entry if the lock isn't already held in the current scope, and records the lock in the context.
+    * Attempts to lock an entry if the lock isn't already held in the current scope, and records the lock in the
+    * context.
     *
     * @param ctx context
     * @param key Key to lock
@@ -49,7 +50,5 @@
 
    MVCCEntry wrapEntryForWriting(InvocationContext ctx, Object key, boolean createIfAbsent, boolean forceLockIfAbsent) throws InterruptedException;
 
-   MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key, boolean putInContext, boolean forceWriteLock) throws InterruptedException;
-
-   MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key, boolean putInContext) throws InterruptedException;
+   MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key) throws InterruptedException;
 }

Modified: core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java	2009-03-05 17:22:27 UTC (rev 7863)
+++ core/branches/flat/src/main/java/org/horizon/factories/EntryFactoryImpl.java	2009-03-05 17:45:03 UTC (rev 7864)
@@ -71,26 +71,27 @@
       return useRepeatableRead ? new RepeatableReadEntry(key, value, lifespan) : new ReadCommittedEntry(key, value, lifespan);
    }
 
-   public final MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key, boolean putInContext) throws InterruptedException {
-      return wrapEntryForReading(ctx, key, putInContext, false);
-   }
-
-   public final MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key, boolean putInContext, boolean forceWriteLock) throws InterruptedException {
-      // TODO: Do we need to wrap for reading if we are not in a TX?
-      // TODO: Also, do we need to wrap for reading even IN a TX if we are using read-committed?
-
+   public final MVCCEntry wrapEntryForReading(InvocationContext ctx, Object key) throws InterruptedException {
       MVCCEntry mvccEntry;
-      if (forceWriteLock) {
+      if (ctx.hasOption(Options.FORCE_WRITE_LOCK)) {
          if (trace) log.trace("Forcing lock on reading");
          return wrapEntryForWriting(ctx, key, false, false);
       } else if ((mvccEntry = ctx.lookupEntry(key)) == null) {
          if (trace) log.trace("Key " + key + " is not in context, fetching from container.");
          // simple implementation.  Peek the entry, wrap it, put wrapped entry in the context.
          CachedValue se = container.getEntry(key);
-         mvccEntry = se == null ?
-               createWrappedEntry(key, null, false, -1) :
-               createWrappedEntry(key, se.getValue(), false, se.getLifespan());
-         if (mvccEntry != null && putInContext) ctx.putLookedUpEntry(key, mvccEntry);
+
+         // do not bother wrapping though if this is not in a tx.  repeatable read etc are all meaningless unless there is a tx.
+         // TODO: Do we need to wrap for reading even IN a TX if we are using read-committed?
+         if (ctx.getTransaction() == null) {
+            if (se != null) ctx.putLookedUpEntry(key, se);
+         } else {
+            mvccEntry = se == null ?
+                  createWrappedEntry(key, null, false, -1) :
+                  createWrappedEntry(key, se.getValue(), false, se.getLifespan());
+            if (mvccEntry != null) ctx.putLookedUpEntry(key, mvccEntry);
+         }
+
          return mvccEntry;
       } else {
          if (trace) log.trace("Key is already in context");

Modified: core/branches/flat/src/main/java/org/horizon/interceptors/LockingInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/interceptors/LockingInterceptor.java	2009-03-05 17:22:27 UTC (rev 7863)
+++ core/branches/flat/src/main/java/org/horizon/interceptors/LockingInterceptor.java	2009-03-05 17:45:03 UTC (rev 7864)
@@ -109,7 +109,7 @@
    @Override
    public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable {
       try {
-         entryFactory.wrapEntryForReading(ctx, command.getKey(), true);
+         entryFactory.wrapEntryForReading(ctx, command.getKey());
          return invokeNextInterceptor(ctx, command);
       }
       finally {

Modified: core/branches/flat/src/main/java/org/horizon/loader/StoredEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/StoredEntry.java	2009-03-05 17:22:27 UTC (rev 7863)
+++ core/branches/flat/src/main/java/org/horizon/loader/StoredEntry.java	2009-03-05 17:45:03 UTC (rev 7864)
@@ -34,6 +34,7 @@
       setLifespan(lifespan);
    }
 
+   @Override
    public final Object getKey() {
       return key;
    }




More information about the jbosscache-commits mailing list