[jbosscache-commits] JBoss Cache SVN: r5597 - in core/trunk/src: main/java/org/jboss/cache/commands/cachedata and 6 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Fri Apr 18 12:26:54 EDT 2008


Author: mircea.markus
Date: 2008-04-18 12:26:54 -0400 (Fri, 18 Apr 2008)
New Revision: 5597

Modified:
   core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
   core/trunk/src/main/java/org/jboss/cache/commands/cachedata/GetDataMapCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/remote/ClusteredGetCommand.java
   core/trunk/src/main/java/org/jboss/cache/commands/remote/ReplicateCommand.java
   core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java
   core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
   core/trunk/src/main/java/org/jboss/cache/invocation/CacheLifecycleManager.java
   core/trunk/src/main/java/org/jboss/cache/invocation/InterceptorChain.java
   core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java
   core/trunk/src/main/java/org/jboss/cache/marshall/InactiveRegionAwareRpcDispatcher.java
   core/trunk/src/test/java/org/jboss/cache/api/NodeAPIOptimisticTest.java
   core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java
   core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java
   core/trunk/src/test/java/org/jboss/cache/api/NodeMoveOptimisticTest.java
   core/trunk/src/test/java/org/jboss/cache/api/NodeReplicatedMoveOptimisticTest.java
   core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java
   core/trunk/src/test/resources/log4j.xml
Log:
revactored chained invocation pattern

Modified: core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java	2008-04-18 15:12:16 UTC (rev 5596)
+++ core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java	2008-04-18 16:26:54 UTC (rev 5597)
@@ -28,6 +28,9 @@
 import org.jboss.cache.transaction.TransactionTable;
 import org.jboss.cache.util.ThreadGate;
 import org.jboss.cache.util.reflect.ReflectionUtil;
+import org.jboss.cache.invocation.InvocationContextContainer;
+import org.jboss.cache.invocation.InterceptorChain;
+import org.jboss.cache.invocation.CacheLifecycleManager;
 import org.jgroups.Address;
 import org.jgroups.Channel;
 import org.jgroups.ChannelException;
@@ -82,17 +85,22 @@
    private Configuration configuration;
    private Notifier notifier;
    private CacheSPI spi;
+   private InvocationContextContainer invocationContextContainer;
    private boolean trace = log.isTraceEnabled();
    private Marshaller marshaller;
    private TransactionManager txManager;
    private TransactionTable txTable;
+   private InterceptorChain interceptorChain;
+   private CacheLifecycleManager lifecycleManager;
 
    private boolean isUsingBuddyReplication;
    private boolean isInLocalMode;
 
    @Inject
    private void setupDependencies(CacheMessageListener messageListener, Configuration configuration, Notifier notifier,
-                                  CacheSPI spi, Marshaller marshaller, TransactionTable txTable, TransactionManager txManager)
+                                  CacheSPI spi, Marshaller marshaller, TransactionTable txTable,
+                                  TransactionManager txManager, InvocationContextContainer container, InterceptorChain interceptorChain,
+                                    CacheLifecycleManager lifecycleManager)
    {
       this.messageListener = messageListener;
       this.configuration = configuration;
@@ -101,6 +109,9 @@
       this.marshaller = marshaller;
       this.txManager = txManager;
       this.txTable = txTable;
+      this.invocationContextContainer = container;
+      this.interceptorChain = interceptorChain;
+      this.lifecycleManager = lifecycleManager;
    }
 
    // ------------ START: Lifecycle methods ------------
@@ -273,11 +284,13 @@
       // but only if we are using region based marshalling?!??
       if (configuration.isUseRegionBasedMarshalling())
       {
-         disp = new InactiveRegionAwareRpcDispatcher(channel, messageListener, new MembershipListenerAdaptor(), spi);
+         disp = new InactiveRegionAwareRpcDispatcher(channel, messageListener, new MembershipListenerAdaptor(),
+               spi, invocationContextContainer, interceptorChain, lifecycleManager);
       }
       else
       {
-         disp = new CommandAwareRpcDispatcher(channel, messageListener, new MembershipListenerAdaptor(), spi);
+         disp = new CommandAwareRpcDispatcher(channel, messageListener, new MembershipListenerAdaptor(),
+               invocationContextContainer, invocationContextContainer, interceptorChain, lifecycleManager);
       }
 
       disp.setRequestMarshaller(marshaller);

Modified: core/trunk/src/main/java/org/jboss/cache/commands/cachedata/GetDataMapCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/cachedata/GetDataMapCommand.java	2008-04-18 15:12:16 UTC (rev 5596)
+++ core/trunk/src/main/java/org/jboss/cache/commands/cachedata/GetDataMapCommand.java	2008-04-18 16:26:54 UTC (rev 5597)
@@ -8,6 +8,8 @@
 import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.invocation.CacheData;
 
+import java.util.Collections;
+
 /**
  * Implements functionality defined by {@link org.jboss.cache.Cache#getData(org.jboss.cache.Fqn)}
  *
@@ -41,7 +43,7 @@
    {
       NodeSPI n = cacheData.findNode(fqn);
       if (n == null) return null;
-      return n.getDataDirect();
+      return Collections.unmodifiableMap(n.getDataDirect());
    }
 
    public Object accept(InvocationContext ctx, CommandsVisitor handler) throws Throwable

Modified: core/trunk/src/main/java/org/jboss/cache/commands/remote/ClusteredGetCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/remote/ClusteredGetCommand.java	2008-04-18 15:12:16 UTC (rev 5596)
+++ core/trunk/src/main/java/org/jboss/cache/commands/remote/ClusteredGetCommand.java	2008-04-18 16:26:54 UTC (rev 5597)
@@ -65,7 +65,7 @@
       try
       {
          if (trace) log.trace("Clustered get: invoking call with Fqn " + cacheDataComand.getFqn());
-         callResults = interceptorChain.invoke(cacheDataComand, false);
+         callResults = interceptorChain.invokeRemote(cacheDataComand);
          boolean found = validResult(callResults);
          if (trace) log.trace("Got result " + callResults + ", found=" + found);
          if (found && callResults == null) callResults = createEmptyResults();

Modified: core/trunk/src/main/java/org/jboss/cache/commands/remote/ReplicateCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/remote/ReplicateCommand.java	2008-04-18 15:12:16 UTC (rev 5596)
+++ core/trunk/src/main/java/org/jboss/cache/commands/remote/ReplicateCommand.java	2008-04-18 16:26:54 UTC (rev 5597)
@@ -80,7 +80,7 @@
       {
          if (trace) log.trace("Invoking command " + cacheCommand + ", with originLocal flag set to false.");
 
-         Object retVal = invoker.invoke(cacheCommand, false);
+         Object retVal = invoker.invokeRemote(cacheCommand);
          // we only need to return values for a set of remote calls; not every call.
          if (returnValueForRemoteCall(cacheCommand))
          {

Modified: core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java	2008-04-18 15:12:16 UTC (rev 5596)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java	2008-04-18 16:26:54 UTC (rev 5597)
@@ -3,7 +3,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheStatus;
 import org.jboss.cache.InvocationContext;
 import org.jboss.cache.commands.CacheCommand;
 import org.jboss.cache.config.Configuration;
@@ -46,120 +45,10 @@
       this.lifecycleManager = lifecycleManager;
    }
 
-   /**
-    * Passes a method call up the interceptor chain.
-    *
-    * @param call methodcall to pass
-    * @return an Object, the generic return type for the interceptors.
-    * @throws Throwable in the event of problems
-    */
-   public Object invoke(CacheCommand command) throws CacheException
-   {
-      assertIsConstructed();
-      InvocationContext ctx = invocationContextContainer.get();
-      return invoke(command, ctx.getOptionOverrides().isSkipCacheStatusCheck(), ctx);
-   }
 
-   /**
-    * Passes a method call up the interceptor chain, optionally allowing you to skip cache status checks.
-    *
-    * @return an Object, the generic return type for the interceptors.
-    * @throws Throwable in the event of problems
-    */
-   protected Object invoke(CacheCommand command, boolean skipCacheStatusCheck) throws CacheException
-   {
-      assertIsConstructed();
-      return invoke(command, skipCacheStatusCheck, invocationContextContainer.get());
-   }
-
    protected void assertIsConstructed()
    {
       if (invocationContextContainer == null) throw new IllegalStateException("The cache has been destroyed!");
    }
 
-   private Object invoke(CacheCommand command, boolean skipCacheStatusCheck, InvocationContext ctx) throws CacheException
-   {
-      if (!lifecycleManager.getCacheStatus().allowInvocations() && !skipCacheStatusCheck)
-      {
-         // only throw an exception if this is a locally originating call - JBCACHE-1179
-         if (originLocal)
-         {
-            throw new IllegalStateException("Cache not in STARTED state!");
-         }
-         else
-         {
-            if (lifecycleManager.getCacheStatus() == CacheStatus.STARTING)
-            {
-               try
-               {
-                  blockUntilCacheStarts();
-               }
-               catch (InterruptedException e)
-               {
-                  Thread.currentThread().interrupt();
-               }
-            }
-            else
-            {
-               log.warn("Received a remote call but the cache is not in STARTED state - ignoring call.");
-               return null;
-            }
-         }
-      }
-
-      CacheCommand oldCommand = null;
-      try
-      {
-         // check if we had a method call lurking around
-         oldCommand = ctx.getExecutingCommand();
-         ctx.setExecutingCommand(command);
-         // only set this if originLocal is EXPLICITLY passed in as FALSE.  Otherwise leave it as a default.
-         if (!originLocal) ctx.setOriginLocal(false);
-         return invoker.invoke(ctx, command);
-      }
-      catch (CacheException e)
-      {
-         throw e;
-      }
-      catch (RuntimeException e)
-      {
-         throw e;
-      }
-      catch (Throwable t)
-      {
-         throw new CacheException(t);
-      }
-      finally
-      {
-         if (!originLocal) ctx.setOriginLocal(true);
-         // reset old method call
-         if (ctx == null) ctx = invocationContextContainer.get();
-         ctx.setExecutingCommand(oldCommand);
-      }
-   }
-
-   /**
-    * Blocks until the current cache instance is in it's {@link org.jboss.cache.CacheStatus#STARTED started} phase.  Blocks
-    * for up to {@link org.jboss.cache.config.Configuration#getStateRetrievalTimeout()} milliseconds, throwing an IllegalStateException
-    * if the cache doesn't reach this state even after this maximum wait time.
-    *
-    * @throws InterruptedException  if interrupted while waiting
-    * @throws IllegalStateException if even after waiting the cache has not started.
-    */
-   private void blockUntilCacheStarts() throws InterruptedException, IllegalStateException
-   {
-      int pollFrequencyMS = 100;
-      long startupWaitTime = configuration.getStateRetrievalTimeout();
-      long giveUpTime = System.currentTimeMillis() + startupWaitTime;
-
-      while (System.currentTimeMillis() < giveUpTime)
-      {
-         if (lifecycleManager.getCacheStatus().allowInvocations()) break;
-         Thread.sleep(pollFrequencyMS);
-      }
-
-      // check if we have started.
-      if (!lifecycleManager.getCacheStatus().allowInvocations())
-         throw new IllegalStateException("Cache not in STARTED state, even after waiting " + configuration.getStateRetrievalTimeout() + " millis.");
-   }
 }

Modified: core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java	2008-04-18 15:12:16 UTC (rev 5596)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java	2008-04-18 16:26:54 UTC (rev 5597)
@@ -56,24 +56,6 @@
    {
    }
 
-//   @Inject
-//   public void initialize(CacheData cacheData)
-//   {
-//      this.stateTransferManager = stateTransferManager;
-//      this.cacheLoaderManager = cacheLoaderManager;
-//      this.notifier = notifier;
-//      this.transactionManager = transactionManager;
-//      this.buddyManager = buddyManager;
-//      this.transactionTable = transactionTable;
-//      this.rpcManager = rpcManager;
-//      this.regionManager = regionManager;
-//      this.marshaller = marshaller;
-//      this.cacheData = cacheData;
-//      this.commandsFactory = commandsFactory;
-//      this.transactionHelper = transactionHelper;
-
-   //   }
-
    @Inject
    public void initialize(StateTransferManager stateTransferManager, CacheLoaderManager cacheLoaderManager, Notifier notifier,
                           TransactionManager transactionManager, BuddyManager buddyManager, TransactionTable transactionTable,
@@ -244,8 +226,9 @@
 
    public GravitateResult gravitateData(Fqn fqn, boolean searchBuddyBackupSubtrees, InvocationContext ctx)
    {
+      cacheStatusCheck(ctx);
       GravitateDataCommand command = commandsFactory.buildGravitateDataCacheCommand(fqn, searchBuddyBackupSubtrees);
-      return (GravitateResult) invoke(command);
+      return (GravitateResult) invoker.invoke(ctx, command);
 //      return (GravitateResult) command.perform(null);
    }
 
@@ -333,8 +316,10 @@
 
    public void move(Fqn<?> nodeToMove, Fqn<?> newParent) throws NodeNotExistsException
    {
+      InvocationContext ctx = invocationContextContainer.get();
+      cacheStatusCheck(ctx);
       MoveCommand command = commandsFactory.buildMoveCommand(nodeToMove, newParent);
-      invoke(command);
+      invoker.invoke(ctx, command);
    }
 
    public void move(String nodeToMove, String newParent) throws NodeNotExistsException
@@ -354,10 +339,12 @@
 
    public void evict(Fqn<?> fqn, boolean recursive)
    {
+      InvocationContext ctx = invocationContextContainer.get();
+      cacheStatusCheck(ctx);
       List<Fqn> nodesToEvict = cacheData.getNodesForEviction(fqn, recursive);
       for (Fqn aFqn : nodesToEvict)
       {
-         invoke(commandsFactory.buildEvictFqnCommand(aFqn));
+         invoker.invoke(ctx, commandsFactory.buildEvictFqnCommand(aFqn));
       }
    }
 
@@ -368,8 +355,10 @@
 
    public V get(Fqn<?> fqn, K key)
    {
+      InvocationContext ctx = invocationContextContainer.get();
+      cacheStatusCheck(ctx);
       GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(fqn, key, true);
-      return (V) invoke(command);
+      return (V) invoker.invoke(ctx, command);
    }
 
    public V get(String fqn, K key)
@@ -396,12 +385,13 @@
             }
          }
          return result;
-      }
-      else
+      } else
       {
+         InvocationContext ctx = invocationContextContainer.get();
+         cacheStatusCheck(ctx);
          GlobalTransaction tx = transactionHelper.getCurrentTransaction();
          RemoveNodeCommand command = commandsFactory.buildRemoveNodeCommand(tx, fqn, true, true, false);
-         Object retval = invoke(command);
+         Object retval = invoker.invoke(ctx, command);
          return retval != null && (Boolean) retval;
       }
    }
@@ -413,8 +403,10 @@
 
    public NodeSPI<K, V> getNode(Fqn<?> fqn)
    {
+      InvocationContext ctx = invocationContextContainer.get();
+      cacheStatusCheck(ctx);
       GetNodeCommand command = commandsFactory.buildGetNodeCommand(fqn);
-      return (NodeSPI) invoke(command);
+      return (NodeSPI) invoker.invoke(ctx, command);
    }
 
    public NodeSPI<K, V> getNode(String fqn)
@@ -424,9 +416,11 @@
 
    public V remove(Fqn<?> fqn, K key) throws CacheException
    {
+      InvocationContext ctx = invocationContextContainer.get();
+      cacheStatusCheck(ctx);
       GlobalTransaction tx = transactionHelper.getCurrentTransaction();
       RemoveKeyCommand command = commandsFactory.buildRemoveKeyCommand(tx, fqn, key, true);
-      return (V) invoke(command);
+      return (V) invoker.invoke(ctx, command);
    }
 
    public V remove(String fqn, K key)
@@ -436,8 +430,10 @@
 
    public void put(Fqn<?> fqn, Map<K, V> data)
    {
+      InvocationContext ctx = invocationContextContainer.get();
+      cacheStatusCheck(ctx);
       PutDataMapCommand command = commandsFactory.buildPutDataMapCommand(null, fqn, data, true, false);
-      invoke(command);
+      invoker.invoke(ctx, command);
    }
 
    public void put(String fqn, Map<K, V> data)
@@ -447,15 +443,16 @@
 
    public void putForExternalRead(Fqn<?> fqn, K key, V value)
    {
+      InvocationContext ctx = invocationContextContainer.get();
+      cacheStatusCheck(ctx);
       // if the node exists then this should be a no-op.
       if (peek(fqn, false, false) == null)
       {
          getInvocationContext().getOptionOverrides().setFailSilently(true);
          getInvocationContext().getOptionOverrides().setForceAsynchronous(true);
          PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(null, fqn, key, value, false, true);
-         invoke(command);
-      }
-      else
+         invoker.invoke(ctx, command);
+      } else
       {
          if (log.isDebugEnabled())
             log.debug("putForExternalRead() called with Fqn " + fqn + " and this node already exists.  This method is hence a no op.");
@@ -464,9 +461,11 @@
 
    public V put(Fqn<?> fqn, K key, V value)
    {
+      InvocationContext ctx = invocationContextContainer.get();
+      cacheStatusCheck(ctx);
       GlobalTransaction tx = transactionHelper.getCurrentTransaction();
       PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(tx, fqn, key, value, false, false);
-      return (V) invoke(command);
+      return (V) invoker.invoke(ctx, command);
    }
 
    public V put(String fqn, K key, V value)
@@ -498,8 +497,10 @@
     */
    public Map<K, V> getData(Fqn<?> fqn)
    {
+      InvocationContext ctx = invocationContextContainer.get();
+      cacheStatusCheck(ctx);
       GetDataMapCommand command = commandsFactory.buildGetDataMapCommand(fqn);
-      return (Map<K, V>) invoke(command);
+      return (Map<K, V>) invoker.invoke(ctx, command);
    }
 
    /**
@@ -523,8 +524,10 @@
     */
    public Set<K> getKeys(Fqn<?> fqn)
    {
+      InvocationContext ctx = invocationContextContainer.get();
+      cacheStatusCheck(ctx);
       GetKeysCommand command = commandsFactory.buildGetKeysCommand(fqn);
-      return (Set<K>) invoke(command);
+      return (Set<K>) invoker.invoke(ctx, command);
    }
 
    /**
@@ -540,8 +543,10 @@
     */
    public void clearData(Fqn fqn)
    {
+      InvocationContext ctx = invocationContextContainer.get();
+      cacheStatusCheck(ctx);
       GlobalTransaction tx = getCurrentTransaction();
-      invoke(commandsFactory.buildRemoveDataCommand(tx, fqn, true, false, false));
+      invoker.invoke(ctx, commandsFactory.buildRemoveDataCommand(tx, fqn, true, false, false));
    }
 
    /**
@@ -553,8 +558,10 @@
     */
    public <E> Set<E> getChildrenNames(Fqn<E> fqn)
    {
+      InvocationContext ctx = invocationContextContainer.get();
+      cacheStatusCheck(ctx);
       GetChildrenNamesCommand command = commandsFactory.buildGetChildrenNamesCommand(fqn);
-      Set<E> retval = (Set<E>) invoke(command);
+      Set<E> retval = (Set<E>) invoker.invoke(ctx, command);
       if (retval != null)
          retval = Collections.unmodifiableSet(new HashSet<E>(retval));
       else
@@ -577,7 +584,7 @@
       assertIsConstructed();
       BlockChannelCommand command = commandsFactory.buildBlockChannelCommand();
       // need to skip status check here because this typically happens before the cache is in it's STARTED state
-      invoke(command, true);
+      invoker.invoke(invocationContextContainer.get(), command);
    }
 
    public void unblock()
@@ -585,7 +592,15 @@
       assertIsConstructed();
       UnblockChannelCommand command = commandsFactory.buildUnblockChannelCommand();
       // need to skip status check here because this typically happens before the cache is in it's STARTED state
-      invoke(command, true);
+      invoker.invoke(invocationContextContainer.get(), command);
    }
 
+   protected void cacheStatusCheck(InvocationContext ctx)
+   {
+      assertIsConstructed();
+      if (!ctx.getOptionOverrides().isSkipCacheStatusCheck())
+      {
+         lifecycleManager.allowsInvocation(true);
+      }
+   }
 }

Modified: core/trunk/src/main/java/org/jboss/cache/invocation/CacheLifecycleManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/CacheLifecycleManager.java	2008-04-18 15:12:16 UTC (rev 5596)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/CacheLifecycleManager.java	2008-04-18 16:26:54 UTC (rev 5597)
@@ -146,8 +146,7 @@
                log.warn("Needed to call stop() before destroying but stop() " +
                      "threw exception. Proceeding to destroy", e);
             }
-         }
-         else
+         } else
             return;
       }
 
@@ -283,8 +282,7 @@
          };
 
          Runtime.getRuntime().addShutdownHook(shutdownHook);
-      }
-      else
+      } else
       {
          if (log.isTraceEnabled())
             log.trace("Not registering a shutdown hook.  Configured behavior = " + configuration.getShutdownHookBehavior());
@@ -417,8 +415,7 @@
                   category.append(rpcManager.getLocalAddress().toString().replace('.', '_'));
                }
             }
-         }
-         else
+         } else
          {
             // we're in LOCAL mode
             category.append("_LOCAL");
@@ -445,6 +442,64 @@
       }
    }
 
+   /**
+    * For local calls, if chache is not in STARTED mode will throw an IllegalStateException.
+    * For remote cache, if cache is STRTED returns true. If cache is STARTING waits for the cache to wait
+    * for {@link org.jboss.cache.config.Configuration#getStateRetrievalTimeout()} milliseconds, if cache starts
+    * returns true, otherwise returns false.
+    */
+   public boolean allowsInvocation(boolean originLocal)
+   {
+      if (getCacheStatus().allowInvocations()) return true;
+      // only throw an exception if this is a locally originating call - JBCACHE-1179
+      if (originLocal)
+      {
+         throw new IllegalStateException("Cache not in STARTED state!");
+      }
+      if (getCacheStatus() == CacheStatus.STARTING)
+      {
+         try
+         {
+            blockUntilCacheStarts();
+            return true;
+         }
+         catch (InterruptedException e)
+         {
+            Thread.currentThread().interrupt();
+         }
+      } else
+      {
+         log.warn("Received a remote call but the cache is not in STARTED state - ignoring call.");
+      }
+      return false;
+   }
+
+   /**
+    * Blocks until the current cache instance is in it's {@link org.jboss.cache.CacheStatus#STARTED started} phase.  Blocks
+    * for up to {@link org.jboss.cache.config.Configuration#getStateRetrievalTimeout()} milliseconds, throwing an IllegalStateException
+    * if the cache doesn't reach this state even after this maximum wait time.
+    *
+    * @throws InterruptedException  if interrupted while waiting
+    * @throws IllegalStateException if even after waiting the cache has not started.
+    */
+   private void blockUntilCacheStarts() throws InterruptedException, IllegalStateException
+   {
+      int pollFrequencyMS = 100;
+      long startupWaitTime = configuration.getStateRetrievalTimeout();
+      long giveUpTime = System.currentTimeMillis() + startupWaitTime;
+
+      while (System.currentTimeMillis() < giveUpTime)
+      {
+         if (getCacheStatus().allowInvocations()) break;
+         Thread.sleep(pollFrequencyMS);
+      }
+
+      // check if we have started.
+      if (!getCacheStatus().allowInvocations())
+         throw new IllegalStateException("Cache not in STARTED state, even after waiting " + configuration.getStateRetrievalTimeout() + " millis.");
+   }
+
+
    public CacheStatus getCacheStatus()
    {
       return cacheStatus;

Modified: core/trunk/src/main/java/org/jboss/cache/invocation/InterceptorChain.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/InterceptorChain.java	2008-04-18 15:12:16 UTC (rev 5596)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/InterceptorChain.java	2008-04-18 16:26:54 UTC (rev 5597)
@@ -3,6 +3,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.jboss.cache.InvocationContext;
+import org.jboss.cache.CacheException;
 import org.jboss.cache.commands.CacheCommand;
 import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.interceptors.base.ChainedInterceptor;
@@ -226,19 +227,35 @@
    /**
     * Walks the command through the interceptor chain. The received ctx is being passed in.
     */
-   public Object invoke(InvocationContext ctx, CacheCommand command) throws Throwable
+   public Object invoke(InvocationContext ctx, CacheCommand command)
    {
-      return command.accept(ctx, firstInChain);
+      ctx.setExecutingCommand(command);
+      try
+      {
+         return command.accept(ctx, firstInChain);
+      }
+      catch (CacheException e)
+      {
+         throw e;
+      }
+      catch (RuntimeException e)
+      {
+         throw e;
+      }
+      catch (Throwable t)
+      {
+         throw new CacheException(t);
+      }
    }
 
    /**
     * Similar to {@link #invoke(org.jboss.cache.InvocationContext, org.jboss.cache.commands.CacheCommand)}, but
     * constructs a invocation context on the fly, using {@link InvocationContextContainer#get()}
     */
-   public Object invoke(CacheCommand cacheCommand, boolean isOriginLocal) throws Throwable
+   public Object invokeRemote(CacheCommand cacheCommand) throws Throwable
    {
       InvocationContext ctxt = invocationContextContainer.get();
-      ctxt.setOriginLocal(isOriginLocal);
+      ctxt.setOriginLocal(false);
       return cacheCommand.accept(ctxt, firstInChain);
    }
 

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java	2008-04-18 15:12:16 UTC (rev 5596)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java	2008-04-18 16:26:54 UTC (rev 5597)
@@ -3,6 +3,10 @@
 import org.jboss.cache.commands.CacheCommand;
 import org.jboss.cache.commands.remote.DirectCommand;
 import org.jboss.cache.invocation.CacheInvocationDelegate;
+import org.jboss.cache.invocation.InvocationContextContainer;
+import org.jboss.cache.invocation.InterceptorChain;
+import org.jboss.cache.invocation.CacheLifecycleManager;
+import org.jboss.cache.InvocationContext;
 import org.jgroups.Channel;
 import org.jgroups.MembershipListener;
 import org.jgroups.Message;
@@ -17,13 +21,19 @@
  */
 public class CommandAwareRpcDispatcher extends RpcDispatcher
 {
-   protected CacheInvocationDelegate cid;
+   protected InvocationContextContainer invocationContextContainer;
+   protected InterceptorChain interceptorChain;
+   protected CacheLifecycleManager lifecycleManager;
    protected boolean trace;
 
-   public CommandAwareRpcDispatcher(Channel channel, MessageListener l, MembershipListener l2, Object server_obj)
+   public CommandAwareRpcDispatcher(Channel channel, MessageListener l, MembershipListener l2, Object server_obj,
+                                    InvocationContextContainer container, InterceptorChain interceptorChain,
+                                    CacheLifecycleManager lifecycleManager)
    {
       super(channel, l, l2, server_obj);
-      cid = (CacheInvocationDelegate) server_obj;
+      this.invocationContextContainer = container;
+      this.lifecycleManager = lifecycleManager;
+      this.interceptorChain = interceptorChain;
       trace = log.isTraceEnabled();
    }
 
@@ -78,8 +88,13 @@
          DirectCommand dCmd = (DirectCommand) cmd;
          return dCmd.performDirectly();
       }
-
-      return cid.invoke(cmd);
+      InvocationContext ctx = invocationContextContainer.get();
+      ctx.setOriginLocal(false);
+      if (!lifecycleManager.allowsInvocation(false))
+      {
+         return null;
+      }
+      return interceptorChain.invoke(ctx, cmd);
    }
 
    @Override

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/InactiveRegionAwareRpcDispatcher.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/InactiveRegionAwareRpcDispatcher.java	2008-04-18 15:12:16 UTC (rev 5596)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/InactiveRegionAwareRpcDispatcher.java	2008-04-18 16:26:54 UTC (rev 5597)
@@ -1,6 +1,9 @@
 package org.jboss.cache.marshall;
 
 import org.jboss.cache.commands.CacheCommand;
+import org.jboss.cache.invocation.InvocationContextContainer;
+import org.jboss.cache.invocation.InterceptorChain;
+import org.jboss.cache.invocation.CacheLifecycleManager;
 import org.jgroups.Channel;
 import org.jgroups.MembershipListener;
 import org.jgroups.Message;
@@ -20,9 +23,11 @@
    /**
     * Only provide the flavour of the {@link RpcDispatcher} constructor that we care about.
     */
-   public InactiveRegionAwareRpcDispatcher(Channel channel, MessageListener l, MembershipListener l2, Object server_obj)
+   public InactiveRegionAwareRpcDispatcher(Channel channel, MessageListener l, MembershipListener l2, Object serverObj,
+                                           InvocationContextContainer container, InterceptorChain interceptorChain,
+                                    CacheLifecycleManager lifecycleManager)
    {
-      super(channel, l, l2, server_obj);
+      super(channel, l, l2, serverObj, container, interceptorChain, lifecycleManager);
    }
 
    @Override

Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeAPIOptimisticTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeAPIOptimisticTest.java	2008-04-18 15:12:16 UTC (rev 5596)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeAPIOptimisticTest.java	2008-04-18 16:26:54 UTC (rev 5597)
@@ -12,4 +12,10 @@
    {
       optimistic = true;
    }
+
+   @Override
+   public void testDoubleRemovalOfData() throws Exception
+   {
+      super.testDoubleRemovalOfData();    //To change body of overridden methods use File | Settings | File Templates.
+   }
 }

Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java	2008-04-18 15:12:16 UTC (rev 5596)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java	2008-04-18 16:26:54 UTC (rev 5597)
@@ -375,6 +375,8 @@
       tm.begin();
       assertEquals(cache.get("/foo/1/2/3", "item"), 1);
       cache.removeNode("/foo/1");
+      cache.exists("/foo/1");
+      assertFalse(cache.exists("/foo/1"));
       assertNull(cache.get("/foo/1", "item"));
       cache.removeNode("/foo/1/2/3");
       assertNull(cache.get("/foo/1/2/3", "item"));

Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java	2008-04-18 15:12:16 UTC (rev 5596)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java	2008-04-18 16:26:54 UTC (rev 5597)
@@ -286,6 +286,7 @@
 
    protected void doCacheLoaderTest(boolean pasv, boolean useTx) throws Exception
    {
+//      cache.stop();
       cache.destroy();
       cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig(pasv, "", DummyInMemoryCacheLoader.class.getName(), null, false, false, false, false));
       cache.start();
@@ -311,56 +312,12 @@
       nodeD.put(k, vD);
       nodeE = nodeD.addChild(E);
       nodeE.put(k, vE);
-      /*
-      Node nodeF = nodeE.addChild(Fqn.fromString("F"));
-      nodeF.put(k, vE);
-      Node nodeG = nodeF.addChild(Fqn.fromString("G"));
-      nodeG.put(k, vE);
-      */
-
-      assertNotNull(cache.peek(A, false));
-      assertNotNull(cache.peek(B, false));
-      assertNull(cache.peek(C, false));
-      assertNotNull(cache.peek(Fqn.fromRelativeFqn(A, C), false));
-      assertNotNull(cache.peek(Fqn.fromRelativeFqn(Fqn.fromRelativeFqn(A, C), D), false));
-      assertNotNull(cache.peek(Fqn.fromRelativeFqn(Fqn.fromRelativeFqn(Fqn.fromRelativeFqn(A, C), D), E), false));
-
-      // test data
-      assertEquals(vA, nodeA.get(k));
-      assertEquals(vB, nodeB.get(k));
-      assertEquals(vC, nodeC.get(k));
-      assertEquals(vD, nodeD.get(k));
-      assertEquals(vE, nodeE.get(k));
-
-      // parentage
-      assertEquals(rootNode, nodeA.getParent());
-      assertEquals(rootNode, nodeB.getParent());
-      assertEquals(nodeA, nodeC.getParent());
-      assertEquals(nodeC, nodeD.getParent());
-      assertEquals(nodeD, nodeE.getParent());
-
-      System.out.println("Loader" + loader);
-
       cache.evict(Fqn.ROOT, true);
 
       // move
       if (useTx) tm.begin();
       cache.move(nodeC.getFqn(), nodeB.getFqn());
-
-      //      Fqn[] fqns = {A, B, new Fqn(B, C), new Fqn(new Fqn(B, C), D), new Fqn(new Fqn(new Fqn(B, C), D), E)};
-      //      System.out.println("*** LOADER BEFORE COMMIT ");
-      //      for (Fqn f: fqns)
-      //      {
-      //         System.out.println("  Fqn: " + f);
-      //         System.out.println("  Contents in loader: " + loader.get(f));
-      //      }
       if (useTx) tm.commit();
-      //      System.out.println("*** LOADER AFTER COMMIT ");
-      //      for (Fqn f: fqns)
-      //      {
-      //         System.out.println("  Fqn: " + f);
-      //         System.out.println("  Contents in loader: " + loader.get(f));
-      //      }
 
       // after eviction, the node objects we hold are probably stale.
       nodeA = rootNode.getChild(A);
@@ -375,15 +332,6 @@
       Fqn old_D = Fqn.fromRelativeFqn(old_C, D);
       Fqn old_E = Fqn.fromRelativeFqn(old_D, E);
 
-      assertNotNull(cache.peek(A, false));
-      assertNotNull(cache.peek(B, false));
-      assertNull(cache.peek(C, false));
-      assertNull(cache.peek(Fqn.fromRelativeFqn(A, C), false));
-      assertNotNull(cache.peek(Fqn.fromRelativeFqn(B, C), false));
-
-      assertNotNull(cache.peek(Fqn.fromRelativeFqn(Fqn.fromRelativeFqn(B, C), D), false));
-      assertNotNull(cache.peek(Fqn.fromRelativeFqn(Fqn.fromRelativeFqn(Fqn.fromRelativeFqn(B, C), D), E), false));
-
       // test data
       assertEquals(vA, nodeA.get(k));
       assertEquals(vB, nodeB.get(k));

Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeMoveOptimisticTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeMoveOptimisticTest.java	2008-04-18 15:12:16 UTC (rev 5596)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeMoveOptimisticTest.java	2008-04-18 16:26:54 UTC (rev 5597)
@@ -6,7 +6,9 @@
  */
 package org.jboss.cache.api;
 
+import org.testng.annotations.Test;
 
+
 public class NodeMoveOptimisticTest extends NodeMoveAPITest
 {
    public NodeMoveOptimisticTest()
@@ -23,4 +25,18 @@
    {
       // no op
    }
+
+   @Override
+   @Test(groups = {"functional"})
+   public void testWithCacheloaders() throws Exception
+   {
+      super.testWithCacheloaders();    //To change body of overridden methods use File | Settings | File Templates.
+   }
+
+   @Override
+   @Test(groups = {"functional"})
+   public void testWithPassivation() throws Exception
+   {
+      super.testWithPassivation();    //To change body of overridden methods use File | Settings | File Templates.
+   }
 }

Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeReplicatedMoveOptimisticTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeReplicatedMoveOptimisticTest.java	2008-04-18 15:12:16 UTC (rev 5596)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeReplicatedMoveOptimisticTest.java	2008-04-18 16:26:54 UTC (rev 5597)
@@ -15,4 +15,10 @@
    {
       optimistic = true;
    }
+
+   @Override
+   public void testReplicatability()
+   {
+      super.testReplicatability();    //To change body of overridden methods use File | Settings | File Templates.
+   }
 }

Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java	2008-04-18 15:12:16 UTC (rev 5596)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java	2008-04-18 16:26:54 UTC (rev 5597)
@@ -125,7 +125,7 @@
    //         }
    //      }
    //
-   //      algo.invoke(region);
+   //      algo.invokeRemote(region);
    ////      LFUQueue queue = (LFUQueue) algo.evictionQueue;
    ////      Iterator it = queue.iterate();
    //

Modified: core/trunk/src/test/resources/log4j.xml
===================================================================
--- core/trunk/src/test/resources/log4j.xml	2008-04-18 15:12:16 UTC (rev 5596)
+++ core/trunk/src/test/resources/log4j.xml	2008-04-18 16:26:54 UTC (rev 5597)
@@ -22,7 +22,7 @@
 
    <!-- A time/date based rolling appender -->
    <appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
-      <param name="File" value="../jbosscache.log"/>
+      <param name="File" value="jbosscache.log"/>
       <param name="Append" value="false"/>
 
       <!-- Rollover at midnight each day -->
@@ -31,7 +31,7 @@
       <!-- Rollover at the top of each hour
       <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
       -->
-      <param name="Threshold" value="DEBUG"/>
+      <param name="Threshold" value="TRACE"/>
 
       <layout class="org.apache.log4j.PatternLayout">
          <!-- The default pattern: Date Priority [Category] Message\n -->
@@ -63,7 +63,7 @@
    <!-- ================ -->
 
    <category name="org.jboss.cache">
-      <priority value="WARN"/>
+      <priority value="TRACE"/>
    </category>
 
    <category name="org.jboss.tm">
@@ -79,7 +79,7 @@
    <!-- ======================= -->
 
    <root>
-      <!-- <appender-ref ref="CONSOLE"/> -->
+       <!--<appender-ref ref="CONSOLE"/>-->
       <appender-ref ref="FILE"/>
    </root>
 




More information about the jbosscache-commits mailing list