[infinispan-commits] Infinispan SVN: r419 - in trunk/core/src/main/java/org/infinispan: commands/read and 2 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Tue Jun 9 11:55:01 EDT 2009


Author: mircea.markus
Date: 2009-06-09 11:55:01 -0400 (Tue, 09 Jun 2009)
New Revision: 419

Modified:
   trunk/core/src/main/java/org/infinispan/commands/CommandsFactoryImpl.java
   trunk/core/src/main/java/org/infinispan/commands/read/GetKeyValueCommand.java
   trunk/core/src/main/java/org/infinispan/commands/remote/ClusteredGetCommand.java
   trunk/core/src/main/java/org/infinispan/context/InvocationContextContainer.java
Log:
[ISPN-68] (ClusterGet - fix) implemented

Modified: trunk/core/src/main/java/org/infinispan/commands/CommandsFactoryImpl.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/commands/CommandsFactoryImpl.java	2009-06-09 13:59:40 UTC (rev 418)
+++ trunk/core/src/main/java/org/infinispan/commands/CommandsFactoryImpl.java	2009-06-09 15:55:01 UTC (rev 419)
@@ -228,7 +228,7 @@
             break;
          case ClusteredGetCommand.COMMAND_ID:
             ClusteredGetCommand clusteredGetCommand = (ClusteredGetCommand) c;
-            clusteredGetCommand.initialize(dataContainer, cacheLoaderManager, icc);
+            clusteredGetCommand.initialize(dataContainer, icc, this, interceptorChain);
             break;
          case LockControlCommand.COMMAND_ID:
             LockControlCommand lcc = (LockControlCommand)c;

Modified: trunk/core/src/main/java/org/infinispan/commands/read/GetKeyValueCommand.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/commands/read/GetKeyValueCommand.java	2009-06-09 13:59:40 UTC (rev 418)
+++ trunk/core/src/main/java/org/infinispan/commands/read/GetKeyValueCommand.java	2009-06-09 15:55:01 UTC (rev 419)
@@ -39,6 +39,7 @@
    private static final Log log = LogFactory.getLog(GetKeyValueCommand.class);
    private static final boolean trace = log.isTraceEnabled();
    private CacheNotifier notifier;
+   private boolean returnCacheEntry;
 
    public GetKeyValueCommand(Object key, CacheNotifier notifier) {
       this.key = key;
@@ -52,6 +53,13 @@
       return visitor.visitGetKeyValueCommand(ctx, this);
    }
 
+   /**
+    * Will make this method to return an {@link CacheEntry} insted of the coresponding value associated with the key.
+    */
+   public void setReturnCacheEntry(boolean returnCacheEntry) {
+      this.returnCacheEntry = returnCacheEntry;
+   }
+
    public Object perform(InvocationContext ctx) throws Throwable {
       CacheEntry entry = ctx.lookupEntry(key);
       if (entry == null || entry.isNull()) {
@@ -63,7 +71,7 @@
          return null;
       }
       notifier.notifyCacheEntryVisited(key, true, ctx);
-      Object result = entry.getValue();
+      Object result = returnCacheEntry ? entry : entry.getValue();
       if (trace) log.trace("Found value " + result);
       notifier.notifyCacheEntryVisited(key, false, ctx);
       return result;

Modified: trunk/core/src/main/java/org/infinispan/commands/remote/ClusteredGetCommand.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/commands/remote/ClusteredGetCommand.java	2009-06-09 13:59:40 UTC (rev 418)
+++ trunk/core/src/main/java/org/infinispan/commands/remote/ClusteredGetCommand.java	2009-06-09 15:55:01 UTC (rev 419)
@@ -21,13 +21,18 @@
  */
 package org.infinispan.commands.remote;
 
-import org.infinispan.CacheException;
+import org.infinispan.commands.CommandsFactory;
+import org.infinispan.commands.read.GetKeyValueCommand;
 import org.infinispan.container.DataContainer;
+import org.infinispan.container.entries.CacheEntry;
 import org.infinispan.container.entries.InternalCacheEntry;
 import org.infinispan.container.entries.InternalCacheValue;
+import org.infinispan.container.entries.MVCCEntry;
+import org.infinispan.container.entries.InternalEntryFactory;
 import org.infinispan.context.InvocationContext;
 import org.infinispan.context.InvocationContextContainer;
-import org.infinispan.loaders.CacheLoaderManager;
+import org.infinispan.context.impl.NonTxInvocationContext;
+import org.infinispan.interceptors.InterceptorChain;
 import org.infinispan.util.logging.Log;
 import org.infinispan.util.logging.LogFactory;
 
@@ -49,8 +54,9 @@
    private String cacheName;
 
    private DataContainer dataContainer;
-   private CacheLoaderManager cacheLoaderManager;
    private InvocationContextContainer icc;
+   private CommandsFactory commandsFactory;
+   private InterceptorChain invoker;
 
    public ClusteredGetCommand() {
    }
@@ -60,10 +66,11 @@
       this.cacheName = cacheName;
    }
 
-   public void initialize(DataContainer dataContainer, CacheLoaderManager clManager, InvocationContextContainer icc) {
+   public void initialize(DataContainer dataContainer, InvocationContextContainer icc, CommandsFactory commandsFactory, InterceptorChain interceptorChain) {
       this.dataContainer = dataContainer;
-      this.cacheLoaderManager = clManager;
       this.icc = icc;
+      this.commandsFactory = commandsFactory;
+      this.invoker = interceptorChain;
    }
 
    /**
@@ -73,23 +80,22 @@
     * @return returns an <code>CacheEntry</code> or null, if no entry is found.
     */
    public InternalCacheValue perform(InvocationContext context) throws Throwable {
-      if (key != null) {
-         InternalCacheEntry cacheEntry = dataContainer.get(key);
-         if (trace) log.trace("Found InternalCacheEntry {0} for key {1}", cacheEntry, key);
-         if (cacheEntry == null) {
-            if (trace) log.trace("Checking in cache loader");
-            // hack -> the call is here to make sure that the current thread is associated with
-            // the remote InvocationCOntext in order to make sure that ClusterCL won't trigger a recurring cluster get
-            // which might result in infinite loops 
-            icc.createRemoteInvocationContext();
-            // lookup
-            if (cacheLoaderManager != null && cacheLoaderManager.getCacheLoader() != null) {
-               cacheEntry = cacheLoaderManager.getCacheLoader().load(key);
-            }
-         }
-         return cacheEntry != null ? cacheEntry.toInternalCacheValue() : null;
+      GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(key);
+      command.setReturnCacheEntry(true);
+      NonTxInvocationContext invocationContext = icc.createRemoteInvocationContext();
+      CacheEntry cacheEntry = (CacheEntry) invoker.invoke(invocationContext, command);
+      if (cacheEntry == null) {
+         if (trace) log.trace("Did not find anything, returning null");
+         return null;
+      }
+      //this might happen if the value was fetched from a cache loader
+      if (cacheEntry instanceof MVCCEntry) {
+         if (trace) log.trace("Handloing an internal cache entry...");
+         MVCCEntry mvccEntry = (MVCCEntry) cacheEntry;
+         return InternalEntryFactory.createValue(mvccEntry.getValue(), -1, mvccEntry.getLifespan(), -1, mvccEntry.getMaxIdle());
       } else {
-         throw new CacheException("Invalid command. Missing key!");
+         InternalCacheEntry internalCacheEntry = (InternalCacheEntry) cacheEntry;
+         return internalCacheEntry.toInternalCacheValue();
       }
    }
 

Modified: trunk/core/src/main/java/org/infinispan/context/InvocationContextContainer.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/context/InvocationContextContainer.java	2009-06-09 13:59:40 UTC (rev 418)
+++ trunk/core/src/main/java/org/infinispan/context/InvocationContextContainer.java	2009-06-09 15:55:01 UTC (rev 419)
@@ -50,7 +50,7 @@
     * org.infinispan.context.impl.NonTxInvocationContext#isOriginLocal()} flag will be true. The context is also
     * associated with the current thread, so further calls to {@link #getInvocationContext()} will return same instace.
     */
-   InvocationContext createRemoteInvocationContext();
+   NonTxInvocationContext createRemoteInvocationContext();
 
    /**
     * Returns the {@link InvocationContext}  that is currently associated with the calling thread. Important:




More information about the infinispan-commits mailing list