[jbosscache-commits] JBoss Cache SVN: r4842 - in core/trunk/src: main/java/org/jboss/cache/factories and 8 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Dec 12 09:41:07 EST 2007


Author: manik.surtani at jboss.com
Date: 2007-12-12 09:41:07 -0500 (Wed, 12 Dec 2007)
New Revision: 4842

Modified:
   core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
   core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
   core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
   core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java
   core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java
   core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java
   core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java
   core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
   core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/InvalidatedOptNodeValidityTest.java
   core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/InvalidatedPessNodeValidityTest.java
   core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/NodeValidityTestBase.java
   core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java
   core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
   core/trunk/src/test/java/org/jboss/cache/options/FailSilentlyTest.java
Log:
Updated stuff

Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -20,6 +20,7 @@
 import org.jboss.cache.factories.InterceptorChainFactory;
 import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.interceptors.Interceptor;
+import org.jboss.cache.invocation.RemoteCacheInvocationDelegate;
 import org.jboss.cache.loader.CacheLoader;
 import org.jboss.cache.loader.CacheLoaderManager;
 import org.jboss.cache.lock.IsolationLevel;
@@ -182,20 +183,13 @@
     */
    private StateTransferManager stateTransferManager;
 
+   private RemoteCacheInvocationDelegate remoteDelegate;
+
    /**
     * Cache notifier handler class.
     */
    private Notifier notifier;
 
-   private ThreadLocal<InvocationContext> invocationContextContainer = new ThreadLocal<InvocationContext>()
-   {
-      @Override
-      protected InvocationContext initialValue()
-      {
-         return new InvocationContext();
-      }
-   };
-
    private final Configuration configuration;
    private final ComponentRegistry componentRegistry;
    private NodeFactory nodeFactory;
@@ -227,7 +221,7 @@
    @Inject
    private void injectDependencies(Notifier notifier, RegionManager regionManager, TransactionManager transactionManager,
                                    TransactionTable transactionTable, StateTransferManager stateTransferManager, NodeFactory nodeFactory,
-                                   CacheSPI spi, CacheMessageListener messageListener)
+                                   CacheSPI spi, CacheMessageListener messageListener, RemoteCacheInvocationDelegate remoteDelegate)
    {
       this.notifier = notifier;
       this.regionManager = regionManager;
@@ -237,6 +231,7 @@
       this.nodeFactory = nodeFactory;
       this.spi = spi;
       this.messageListener = messageListener;
+      this.remoteDelegate = remoteDelegate;
    }
 
    public Configuration getConfiguration()
@@ -561,10 +556,10 @@
       if (root == null || !root.getClass().equals(tempRoot.getClass()))
          root = tempRoot;
 
-      if (configuration.getCacheLoaderConfig() != null && cacheLoaderManager == null)
-      {
-         initialiseCacheLoaderManager();
-      }
+//      if (configuration.getCacheLoaderConfig() != null && cacheLoaderManager == null)
+//      {
+//         initialiseCacheLoaderManager();
+//      }
       // first set up the Buddy Manager and an RPCManager
 //      if (configuration.getCacheMode() != Configuration.CacheMode.LOCAL)
 //      {
@@ -680,6 +675,19 @@
     */
    private void internalStart() throws CacheException, IllegalArgumentException
    {
+      // re-wire all dependencies in case stuff has changed since the cache was created?
+      // TODO: Do we really need to nuke old deps?  :/
+      CacheSPI spi = componentRegistry.getComponent(CacheSPI.class);
+      componentRegistry.reset();
+
+      componentRegistry.registerComponent(configuration);
+      componentRegistry.registerComponent(this);
+      componentRegistry.registerComponent(CacheSPI.class, spi);
+      componentRegistry.registerComponent(componentRegistry);
+
+      componentRegistry.updateDependencies();
+      componentRegistry.wireDependencies(root);
+
       cacheStatus = CacheStatus.STARTING;
 
 //      createTransactionManager();
@@ -786,7 +794,7 @@
          regionManager.startEvictionThread();
       }
 
-      notifier.notifyCacheStarted(spi, getInvocationContext());
+      notifier.notifyCacheStarted(spi, spi.getInvocationContext());
 
       addShutdownHook();
 
@@ -967,7 +975,7 @@
 
       if (notifier != null)
       {
-         notifier.notifyCacheStopped(spi, getInvocationContext());
+         notifier.notifyCacheStopped(spi, spi.getInvocationContext());
          notifier.removeAllCacheListeners();
       }
 
@@ -1281,7 +1289,7 @@
 
    public Object _get(Fqn<?> fqn, Object key, boolean sendNodeEvent) throws CacheException
    {
-      InvocationContext ctx = getInvocationContext();
+      InvocationContext ctx = spi.getInvocationContext();
       if (log.isTraceEnabled())
       {
          log.trace(new StringBuffer("_get(").append("\"").append(fqn).append("\", \"").append(key).append("\", \"").
@@ -1489,7 +1497,7 @@
       {
          boolean result = true;
          // we need to preserve options
-         InvocationContext ctx = getInvocationContext();
+         InvocationContext ctx = spi.getInvocationContext();
          Option o = ctx.getOptionOverrides();
          for (Object childName : _getChildrenNames(fqn))
          {
@@ -1523,7 +1531,7 @@
       {
          // special treatment for root eviction
          // we need to preserve options
-         InvocationContext ctx = getInvocationContext();
+         InvocationContext ctx = spi.getInvocationContext();
          Option o = ctx.getOptionOverrides();
          for (Object childName : _getChildrenNames(fqn))
          {
@@ -1893,7 +1901,7 @@
    {
       int modeToUse = mode;
       int preferredMode;
-      if ((preferredMode = getInvocationContext().getOptionOverrides().getGroupRequestMode()) > -1)
+      if ((preferredMode = spi.getInvocationContext().getOptionOverrides().getGroupRequestMode()) > -1)
          modeToUse = preferredMode;
 
       RspList rsps = null;
@@ -2146,7 +2154,7 @@
       {
          log.trace("_put(" + tx + ", \"" + fqn + "\", " + data + " undo=" + create_undo_ops + " erase=" + erase_contents + ")");
       }
-      InvocationContext ctx = getInvocationContext();
+      InvocationContext ctx = spi.getInvocationContext();
       boolean isRollback = checkIsRollingBack(ctx.getTransaction());
       NodeSPI n = findNodeCheck(tx, fqn, isRollback);
       Map rawData = n.getDataDirect();
@@ -2211,7 +2219,7 @@
       }
 
 
-      InvocationContext ctx = getInvocationContext();
+      InvocationContext ctx = spi.getInvocationContext();
       // if this is a rollback then don't fire notifications.
       boolean isRollback = checkIsRollingBack(ctx.getTransaction());
 
@@ -2308,7 +2316,7 @@
       {
          log.trace("_remove(" + tx + ", \"" + fqn + "\", undo=" + create_undo_ops + ")");
       }
-      InvocationContext ctx = getInvocationContext();
+      InvocationContext ctx = spi.getInvocationContext();
       // check if this is triggered by a rollback operation ...
       boolean isRollback = checkIsRollingBack(ctx.getTransaction());
       if (tx != null)
@@ -2438,7 +2446,7 @@
          log.warn("node " + fqn + " not found");
          return null;
       }
-      InvocationContext ctx = getInvocationContext();
+      InvocationContext ctx = spi.getInvocationContext();
       boolean isRollback = checkIsRollingBack(ctx.getTransaction());
       if (!isRollback)
          notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.REMOVE_DATA, n.getDataDirect(), ctx);
@@ -2520,7 +2528,7 @@
       }
 
       Map data = n.getDataDirect();
-      InvocationContext ctx = getInvocationContext();
+      InvocationContext ctx = spi.getInvocationContext();
       boolean isRollback = checkIsRollingBack(ctx.getTransaction());
       // create a compensating method call (reverting the effect of
       // this modification) and put it into the TX's undo list.
@@ -2670,7 +2678,7 @@
             log.trace("Node doesn't exist; creating a tombstone");
             // create the node we need.
             Map m = Collections.emptyMap();
-            InvocationContext ic = getInvocationContext();
+            InvocationContext ic = spi.getInvocationContext();
             boolean origCacheModeLocal = ic.getOptionOverrides().isCacheModeLocal();
             ic.getOptionOverrides().setCacheModeLocal(true);
             // if we are in a tx this call should happen outside of any tx
@@ -2748,7 +2756,7 @@
          log.warn("node " + parent_fqn + " not found");
          return;
       }
-      InvocationContext ctx = getInvocationContext();
+      InvocationContext ctx = spi.getInvocationContext();
       boolean isRollback = checkIsRollingBack(ctx.getTransaction());
       Fqn fqn = new Fqn(parent_fqn, child_name);
       if (!isRollback) notifier.notifyNodeCreated(fqn, true, ctx);
@@ -2873,7 +2881,7 @@
       // we need to get the state for this Fqn and its sub-nodes.
 
       // for now, perform a very simple series of getData calls.
-      InvocationContext ctx = getInvocationContext();
+      InvocationContext ctx = spi.getInvocationContext();
       if (log.isTraceEnabled()) log.trace("Caller is asking for " + fqn);
 
       try
@@ -3163,22 +3171,6 @@
       return notifier;
    }
 
-   public InvocationContext getInvocationContext()
-   {
-      InvocationContext ctx = invocationContextContainer.get();
-      if (ctx == null)
-      {
-         ctx = new InvocationContext();
-         invocationContextContainer.set(ctx);
-      }
-      return ctx;
-   }
-
-   public void setInvocationContext(InvocationContext ctx)
-   {
-      invocationContextContainer.set(ctx);
-   }
-
    /**
     * New API to efficiently relocate a node
     *
@@ -3221,7 +3213,7 @@
       // first correct the pointers at the pruning point
       oldParent.removeChildDirect(nodeName);
       newParent.addChild(nodeName, node);
-      InvocationContext ctx = getInvocationContext();
+      InvocationContext ctx = spi.getInvocationContext();
       // parent pointer is calculated on the fly using Fqns.
       boolean isRollback = checkIsRollingBack(ctx.getTransaction());
 
@@ -3323,7 +3315,7 @@
             // now notify listeners - *after* updating the coordinator. - JBCACHE-662
             if (needNotification && notifier != null)
             {
-               InvocationContext ctx = getInvocationContext();
+               InvocationContext ctx = spi.getInvocationContext();
                notifier.notifyViewChange(new_view, ctx);
             }
 
@@ -3346,17 +3338,11 @@
       public void block()
       {
          flushBlockGate.close();
-         if (log.isDebugEnabled())
-         {
-            log.debug("Block received at " + getLocalAddress());
-         }
-         MethodCall m = MethodCallFactory.create(MethodDeclarations.blockChannelLocal);
-         getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true);
-         invokeMethod(m, true);
-         if (log.isDebugEnabled())
-         {
-            log.debug("Block processed at " + getLocalAddress());
-         }
+         if (log.isDebugEnabled()) log.debug("Block received at " + getLocalAddress());
+
+         remoteDelegate.block();
+
+         if (log.isDebugEnabled()) log.debug("Block processed at " + getLocalAddress());
       }
 
       /**
@@ -3364,17 +3350,11 @@
        */
       public void unblock()
       {
-         if (log.isDebugEnabled())
-         {
-            log.debug("UnBlock received at " + getLocalAddress());
-         }
-         MethodCall m = MethodCallFactory.create(MethodDeclarations.unblockChannelLocal);
-         getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true);
-         invokeMethod(m, true);
-         if (log.isDebugEnabled())
-         {
-            log.debug("UnBlock processed at " + getLocalAddress());
-         }
+         if (log.isDebugEnabled()) log.debug("UnBlock received at " + getLocalAddress());
+
+         remoteDelegate.unblock();
+
+         if (log.isDebugEnabled()) log.debug("UnBlock processed at " + getLocalAddress());
          flushBlockGate.open();
       }
 
@@ -3682,14 +3662,14 @@
       return toReturn;
    }
 
-   private void initialiseCacheLoaderManager() throws CacheException
-   {
-      if (cacheLoaderManager == null)
-      {
-         cacheLoaderManager = new CacheLoaderManager();
-      }
-      cacheLoaderManager.setConfig(configuration.getCacheLoaderConfig(), spi);
-   }
+//   private void initialiseCacheLoaderManager() throws CacheException
+//   {
+//      if (cacheLoaderManager == null)
+//      {
+//         cacheLoaderManager = new CacheLoaderManager();
+//      }
+//      cacheLoaderManager.setConfig(configuration.getCacheLoaderConfig(), spi);
+//   }
 
    /**
     * Sets the CacheLoader to use.
@@ -3698,22 +3678,22 @@
     * @param loader
     * @deprecated only provided for backward compat
     */
-   @Deprecated
-   public void setCacheLoader(CacheLoader loader)
-   {
-      log.warn("Using deprecated config method setCacheLoader.  This element will be removed in future, please use CacheLoaderConfiguration instead.");
+//   @Deprecated
+//   public void setCacheLoader(CacheLoader loader)
+//   {
+//      log.warn("Using deprecated config method setCacheLoader.  This element will be removed in future, please use CacheLoaderConfiguration instead.");
+//
+//      try
+//      {
+//         if (cacheLoaderManager == null) initialiseCacheLoaderManager();
+//      }
+//      catch (Exception e)
+//      {
+//         log.warn("Problem setting cache loader.  Perhaps your cache loader config has not been set yet?");
+//      }
+//      cacheLoaderManager.setCacheLoader(loader);
+//   }
 
-      try
-      {
-         if (cacheLoaderManager == null) initialiseCacheLoaderManager();
-      }
-      catch (Exception e)
-      {
-         log.warn("Problem setting cache loader.  Perhaps your cache loader config has not been set yet?");
-      }
-      cacheLoaderManager.setCacheLoader(loader);
-   }
-
    /**
     * Purges the contents of all configured {@link CacheLoader}s
     */
@@ -3777,7 +3757,7 @@
 
       // always use the InactiveRegionAwareRpcDispatcher - exceptions due to regions not being active should not propagate to remote
       // nodes as errors. - Manik
-      disp = new InactiveRegionAwareRpcDispatcher(channel, messageListener, new MembershipListenerAdaptor(), this);
+      disp = new InactiveRegionAwareRpcDispatcher(channel, messageListener, new MembershipListenerAdaptor(), remoteDelegate);
       //            disp = new RpcDispatcher(channel, ml, this, this);
 
       disp.setRequestMarshaller(marshaller);
@@ -3930,7 +3910,7 @@
       // if the node exists then this should be a no-op.
       if (!exists(fqn))
       {
-         getInvocationContext().getOptionOverrides().setFailSilently(true);
+         spi.getInvocationContext().getOptionOverrides().setFailSilently(true);
          GlobalTransaction tx = getCurrentTransaction();
          MethodCall m = MethodCallFactory.create(MethodDeclarations.putForExternalReadMethodLocal, tx, fqn, key, value);
          invokeMethod(m, true);

Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -8,6 +8,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.lock.IdentityLock;
 import org.jboss.cache.marshall.MethodCall;
 import org.jboss.cache.marshall.MethodCallFactory;
@@ -109,6 +110,13 @@
       this.delegate = delegate;
    }
 
+   @Inject
+   private void injectDependencies(CacheSPI spi, CacheImpl impl)
+   {
+      this.cache = spi;
+      this.cacheImpl = impl;
+   }
+
    /**
     * Initializes with a name and FQN and cache.
     */

Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -9,6 +9,7 @@
 import org.jboss.cache.factories.annotations.ComponentName;
 import org.jboss.cache.factories.annotations.DefaultFactoryFor;
 import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.interceptors.Interceptor;
 import org.jboss.cache.util.BeanUtils;
 
 import java.lang.annotation.Annotation;
@@ -248,6 +249,17 @@
       for (Object component : components)
       {
          wireDependencies(component);
+         if (component instanceof Interceptor)
+         {
+            // special behaviour - need to wire for all chained interceptors
+            Interceptor i = (Interceptor) component;
+            Interceptor next = i.getNext();
+            if (next != null)
+            {
+               wireDependencies(next);
+               next = next.getNext();
+            }
+         }
       }
    }
 
@@ -404,7 +416,8 @@
    {
       if (defaultFactories == null) scanDefaultFactories();
       Class<? extends ComponentFactory> cfClass = defaultFactories.get(componentClass);
-
+      if (cfClass == null)
+         throw new ConfigurationException("No registered default factory for component " + componentClass + " found!");
       // a component factory is a component too!  See if one has been created and exists in the registry
       ComponentFactory cf = getComponent(cfClass);
       if (cf == null)
@@ -499,4 +512,11 @@
       return instance;
    }
 
+   /**
+    * Wipes everything in the registry.  Use with care.
+    */
+   public void reset()
+   {
+      registry.clear();
+   }
 }

Modified: core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -3,6 +3,7 @@
 import org.jboss.cache.RegionManager;
 import org.jboss.cache.config.ConfigurationException;
 import org.jboss.cache.factories.annotations.DefaultFactoryFor;
+import org.jboss.cache.invocation.RemoteCacheInvocationDelegate;
 import org.jboss.cache.loader.CacheLoaderManager;
 import org.jboss.cache.notifications.Notifier;
 import org.jboss.cache.remoting.jgroups.CacheMessageListener;
@@ -15,7 +16,7 @@
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
  * @since 2.1.0
  */
- at DefaultFactoryFor(classes = {StateTransferManager.class, TransactionTable.class, RegionManager.class, Notifier.class, CacheMessageListener.class, CacheLoaderManager.class})
+ at DefaultFactoryFor(classes = {StateTransferManager.class, TransactionTable.class, RegionManager.class, Notifier.class, CacheMessageListener.class, CacheLoaderManager.class, RemoteCacheInvocationDelegate.class})
 public class EmptyConstructorFactory extends ComponentFactory
 {
    @Override

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -8,6 +8,7 @@
 import org.jboss.cache.buddyreplication.BuddyManager;
 import org.jboss.cache.config.Configuration.CacheMode;
 import org.jboss.cache.config.Option;
+import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.marshall.MethodCall;
 import org.jboss.cache.marshall.MethodCallFactory;
 import org.jboss.cache.marshall.MethodDeclarations;
@@ -31,6 +32,7 @@
    private boolean usingBuddyReplication;
    protected boolean defaultSynchronous;
 
+   @Inject
    public void setCache(CacheSPI cache)
    {
       super.setCache(cache);

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -1,8 +1,8 @@
 package org.jboss.cache.interceptors;
 
-import org.jboss.cache.CacheSPI;
 import org.jboss.cache.InvocationContext;
 import org.jboss.cache.config.Option;
+import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.transaction.GlobalTransaction;
 import org.jboss.cache.transaction.TransactionEntry;
 import org.jboss.cache.transaction.TransactionTable;
@@ -22,11 +22,11 @@
    protected TransactionTable txTable;
    protected TransactionManager txManager;
 
-   public void setCache(CacheSPI cache)
+   @Inject
+   private void injectDependencies(TransactionTable txTable, TransactionManager txManager)
    {
-      super.setCache(cache);
-      txManager = cache.getTransactionManager();
-      txTable = cache.getTransactionTable();
+      this.txManager = txManager;
+      this.txTable = txTable;
    }
 
    protected void copyInvocationScopeOptionsToTxScope(InvocationContext ctx)

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -6,10 +6,12 @@
  */
 package org.jboss.cache.interceptors;
 
+import org.apache.commons.logging.Log;
 import org.jboss.cache.CacheSPI;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.InvocationContext;
 import org.jboss.cache.config.Option;
+import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.marshall.MethodCall;
 import org.jboss.cache.marshall.MethodCallFactory;
 import org.jboss.cache.marshall.MethodDeclarations;
@@ -21,7 +23,6 @@
 import org.jboss.cache.transaction.OptimisticTransactionEntry;
 import org.jboss.cache.transaction.TransactionEntry;
 import org.jboss.cache.transaction.TransactionTable;
-import org.apache.commons.logging.Log;
 import org.jgroups.Address;
 
 import javax.transaction.SystemException;
@@ -56,11 +57,17 @@
    public void setCache(CacheSPI cache)
    {
       super.setCache(cache);
-      txTable = cache.getTransactionTable();
-      optimistic=cache.getConfiguration().isNodeLockingOptimistic();
+//      txTable = cache.getTransactionTable();
+      optimistic = configuration.isNodeLockingOptimistic();
       if (optimistic) txMods = new ConcurrentHashMap<GlobalTransaction, List<MethodCall>>();
    }
 
+   @Inject
+   private void injectDependencies(TransactionTable txTable)
+   {
+      this.txTable = txTable;
+   }
+
    protected Log getLog()
    {
       return log;
@@ -68,9 +75,9 @@
 
    protected boolean skipMethodCall(InvocationContext ctx)
    {
-     Option optionOverride = ctx.getOptionOverrides();
+      Option optionOverride = ctx.getOptionOverrides();
       if (optionOverride != null && optionOverride.isCacheModeLocal() && (ctx.getTransaction() == null ||
-         MethodDeclarations.isTransactionLifecycleMethod(ctx.getMethodCall().getMethodId())))
+            MethodDeclarations.isTransactionLifecycleMethod(ctx.getMethodCall().getMethodId())))
       {
          // skip replication!!
          return true;
@@ -116,7 +123,7 @@
 
    protected Object handleRemoveKeyMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, Object key, boolean createUndoOps) throws Throwable
    {
-      return handleCrudMethod(ctx,fqn, null);
+      return handleCrudMethod(ctx, fqn, null);
    }
 
    protected Object handleRemoveDataMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, boolean createUndoOps) throws Throwable
@@ -146,7 +153,7 @@
 
    protected Object handleRemoveDataVersionedMethod(InvocationContext ctx, GlobalTransaction gtx, Fqn fqn, boolean createUndoOps, DataVersion dv) throws Throwable
    {
-      return handleCrudMethod(ctx,fqn, null);
+      return handleCrudMethod(ctx, fqn, null);
    }
 
    protected Object handlePrepareMethod(InvocationContext ctx, GlobalTransaction gtx, List modification, Address coordinator, boolean onePhaseCommit) throws Throwable
@@ -196,7 +203,7 @@
    {
       Object retval = nextInterceptor(ctx);
       Transaction tx = ctx.getTransaction();
-      if (tx !=null && optimistic)
+      if (tx != null && optimistic)
       {
          GlobalTransaction gtx = ctx.getGlobalTransaction();
          List modifications = txMods.remove(gtx);
@@ -210,7 +217,7 @@
    {
       Object retval = nextInterceptor(ctx);
       Transaction tx = ctx.getTransaction();
-      if (tx !=null && optimistic)
+      if (tx != null && optimistic)
       {
          GlobalTransaction gtx = ctx.getGlobalTransaction();
          txMods.remove(gtx);
@@ -223,7 +230,7 @@
     * @param from is only present for move operations, else pass it in as null
     */
    private Object handleCrudMethod(InvocationContext ctx, Fqn targetFqn, Fqn from)
-      throws Throwable
+         throws Throwable
    {
       Object retval = nextInterceptor(ctx);
       Transaction tx = ctx.getTransaction();
@@ -282,7 +289,7 @@
    private boolean containsPutForExternalRead(List<MethodCall> l)
    {
       if (l == null) return false;
-      
+
       for (MethodCall m : l)
          if (m.getMethodId() == MethodDeclarations.putForExternalReadMethodLocal_id || m.getMethodId() == MethodDeclarations.putForExternalReadVersionedMethodLocal_id)
             return true;

Modified: core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -67,11 +67,24 @@
     */
    protected Object invoke(MethodCall call) throws CacheException
    {
+      return invoke(call, false);
+   }
+
+   /**
+    * Passes a method call up the interceptor chain, optionally allowing you to skip cache status checks.
+    *
+    * @param call methodcall to pass
+    * @return an Object, the generic return type for the interceptors.
+    * @throws Throwable in the event of problems
+    */
+   protected Object invoke(MethodCall call, boolean skipCacheStatusCheck) throws CacheException
+   {
       // never create a new one directly; always let the container do this if needed.
       InvocationContext ctx = invocationContextContainer.get();
 
       // BR methods should NOT block on the cache being started, since the cache depends on these completing to start.
-      if (!MethodDeclarations.isBuddyGroupOrganisationMethod(call.getMethodId()) && !cache.getCacheStatus().allowInvocations() && !ctx.getOptionOverrides().isSkipCacheStatusCheck())
+      if (!MethodDeclarations.isBuddyGroupOrganisationMethod(call.getMethodId()) &&
+            !cache.getCacheStatus().allowInvocations() && !skipCacheStatusCheck)
       {
          // only throw an exception if this is a locally originating call - JBCACHE-1179
          if (originLocal)

Modified: core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -347,13 +347,14 @@
    public void putAll(Map<K, V> data)
    {
       assertValid();
-      cache.put(getFqn(), data);
+      spi.put(getFqn(), data);
    }
 
    public void replaceAll(Map<K, V> data)
    {
       assertValid();
-      cache.put(getFqn(), data, true);
+      spi.clearData(getFqn());
+      spi.put(getFqn(), data);
    }
 
    public V get(K key)

Modified: core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -1,6 +1,7 @@
 package org.jboss.cache.invocation;
 
 import org.jboss.cache.marshall.MethodCall;
+import org.jboss.cache.marshall.MethodCallFactory;
 import org.jboss.cache.marshall.MethodDeclarations;
 
 import java.util.List;
@@ -55,4 +56,15 @@
       for (MethodCall methodCall : methodCalls) _replicate(methodCall);
    }
 
+   public void block()
+   {
+      MethodCall m = MethodCallFactory.create(MethodDeclarations.blockChannelLocal);
+      invoke(m, true);
+   }
+
+   public void unblock()
+   {
+      MethodCall m = MethodCallFactory.create(MethodDeclarations.unblockChannelLocal);
+      invoke(m, true);
+   }
 }

Modified: core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -13,6 +13,7 @@
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Node;
 import org.jboss.cache.buddyreplication.BuddyGroup;
+import org.jboss.cache.invocation.RemoteCacheInvocationDelegate;
 import org.jboss.cache.lock.NodeLock;
 import org.jboss.cache.optimistic.DataVersion;
 import org.jboss.cache.transaction.GlobalTransaction;
@@ -258,8 +259,8 @@
          getNodeMethodLocal = CacheImpl.class.getDeclaredMethod("_get", Fqn.class);
          getKeysMethodLocal = CacheImpl.class.getDeclaredMethod("_getKeys", Fqn.class);
          getChildrenNamesMethodLocal = CacheImpl.class.getDeclaredMethod("_getChildrenNames", Fqn.class);
-         replicateMethod = CacheImpl.class.getDeclaredMethod("_replicate", MethodCall.class);
-         replicateAllMethod = CacheImpl.class.getDeclaredMethod("_replicate", List.class);
+         replicateMethod = RemoteCacheInvocationDelegate.class.getDeclaredMethod("_replicate", MethodCall.class);
+         replicateAllMethod = RemoteCacheInvocationDelegate.class.getDeclaredMethod("_replicate", List.class);
          releaseAllLocksMethodLocal = CacheImpl.class.getDeclaredMethod("_releaseAllLocks", Fqn.class);
          printMethodLocal = CacheImpl.class.getDeclaredMethod("_print", Fqn.class);
          lockMethodLocal = CacheImpl.class.getDeclaredMethod("_lock", Fqn.class, NodeLock.LockType.class, boolean.class);
@@ -449,7 +450,7 @@
    public static boolean isGetMethod(int methodId)
    {
       return methodId == getChildrenNamesMethodLocal_id || methodId == getDataMapMethodLocal_id || methodId == existsMethod_id
-              || methodId == getKeysMethodLocal_id || methodId == getKeyValueMethodLocal_id || methodId == getNodeMethodLocal_id;
+            || methodId == getKeysMethodLocal_id || methodId == getKeyValueMethodLocal_id || methodId == getNodeMethodLocal_id;
    }
 
    public static boolean isBlockUnblockMethod(int id)

Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -122,7 +122,8 @@
    {
 
       CacheLoaderManager loaderManager = cache.getCacheLoaderManager();
-      if (loaderManager == null)
+      CacheLoader loader = loaderManager == null ? null : loaderManager.getCacheLoader();
+      if (loader == null)
       {
          if (log.isTraceEnabled())
          {
@@ -131,7 +132,7 @@
       }
       else
       {
-         CacheLoader loader = loaderManager.getCacheLoader();
+
          if (log.isTraceEnabled())
          {
             log.trace("integrating persistent state using " + loader.getClass().getName());

Modified: core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/InvalidatedOptNodeValidityTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/InvalidatedOptNodeValidityTest.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/InvalidatedOptNodeValidityTest.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -1,12 +1,11 @@
 package org.jboss.cache.api.nodevalidity;
 
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
 import org.jboss.cache.NodeSPI;
 import org.jboss.cache.optimistic.DefaultDataVersion;
 import org.testng.annotations.Test;
 
 /**
- *
  * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
  * @since 2.1.0
  */
@@ -43,8 +42,8 @@
 
    public void testTombstoneVersioningFailure() throws Exception
    {
-      CacheImpl modifierImpl = (CacheImpl) modifier;
-      CacheImpl observerImpl = (CacheImpl) observer;
+      CacheSPI modifierImpl = (CacheSPI) modifier;
+      CacheSPI observerImpl = (CacheSPI) observer;
 
       modifier.put(parent, K, V);
 

Modified: core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/InvalidatedPessNodeValidityTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/InvalidatedPessNodeValidityTest.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/InvalidatedPessNodeValidityTest.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -2,7 +2,7 @@
 
 import org.jboss.cache.Cache;
 import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
 import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.config.CacheLoaderConfig;
 import org.jboss.cache.config.Configuration;
@@ -12,7 +12,6 @@
 import org.testng.annotations.Test;
 
 /**
- *
  * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
  * @since 2.1.0
  */
@@ -58,8 +57,10 @@
 
       cache.start();
 
-      loader = (DummyInMemoryCacheLoader) ((CacheImpl) cache).getCacheLoader();
+      CacheSPI spi = (CacheSPI) cache;
 
+      loader = (DummyInMemoryCacheLoader) spi.getCacheLoaderManager().getCacheLoader();
+
       return cache;
    }
 }

Modified: core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/NodeValidityTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/NodeValidityTestBase.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/test/java/org/jboss/cache/api/nodevalidity/NodeValidityTestBase.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -1,7 +1,7 @@
 package org.jboss.cache.api.nodevalidity;
 
 import org.jboss.cache.Cache;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Node;
 import org.jboss.cache.NodeNotValidException;
@@ -37,9 +37,10 @@
    protected Cache<String, String> modifier;
    protected Fqn parent = Fqn.fromString("/parent");
    protected Fqn child = Fqn.fromString("/parent/child");
-   protected String K="k", V="v";
+   protected String K = "k", V = "v";
 
    protected abstract Cache<String, String> createObserver();
+
    protected abstract Cache<String, String> createModifier();
 
    protected void optimisticConfiguration(Configuration c)
@@ -115,7 +116,7 @@
       assert obsNode.isValid() : "Node should be valid";
 
       // new parent needs to exist first.
-      modifier.getRoot().addChild(newParent);      
+      modifier.getRoot().addChild(newParent);
       modifier.move(parent, newParent.getParent());
 
       // the old node is only marked as invalid if we use opt locking
@@ -289,8 +290,8 @@
 
    public void testExistenceOfTombstones()
    {
-      CacheImpl modifierImpl = (CacheImpl) modifier;
-      CacheImpl observerImpl = (CacheImpl) observer;
+      CacheSPI modifierImpl = (CacheSPI) modifier;
+      CacheSPI observerImpl = (CacheSPI) observer;
 
       modifier.put(parent, K, V);
       modifier.removeNode(parent);
@@ -321,8 +322,8 @@
 
    public void testExistenceOfTombstonesWithChildren()
    {
-      CacheImpl modifierImpl = (CacheImpl) modifier;
-      CacheImpl observerImpl = (CacheImpl) observer;
+      CacheSPI modifierImpl = (CacheSPI) modifier;
+      CacheSPI observerImpl = (CacheSPI) observer;
 
       modifier.put(child, K, V);
       modifier.removeNode(parent);

Modified: core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -9,6 +9,7 @@
 import org.jboss.cache.buddyreplication.NextMemberBuddyLocator;
 import org.jboss.cache.config.BuddyReplicationConfig;
 import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.invocation.CacheInvocationDelegate;
 import org.jboss.cache.marshall.CacheMarshaller200;
 import org.jboss.cache.marshall.CacheMarshaller210;
@@ -168,4 +169,54 @@
       Configuration cfg = (Configuration) TestingUtil.extractField(bm, "configuration");
       assert cfg == configuration;
    }
+
+   public void testInjectionOrder()
+   {
+      // injection should only occur after dependent components have been fully wired.
+
+      // E.g. Test1 depends on Test2 and Test2 depends on Test3.
+      //cr.reset();
+
+      // DefaultFactoryFor annotation won't work since tests are compiled into a separate classpath
+      cr.defaultFactories.put(Test1.class, EmptyConstructorFactory.class);
+      cr.defaultFactories.put(Test2.class, EmptyConstructorFactory.class);
+      cr.defaultFactories.put(Test3.class, EmptyConstructorFactory.class);
+
+      Test1 t1 = cr.getOrCreateComponent(null, Test1.class);
+
+      assert t1 != null;
+      assert t1.test2 != null;
+      assert t1.test2.test3 != null;
+      assert t1.someValue == t1.test2.test3.someValue;
+   }
+
+   public static class Test1
+   {
+      private Test2 test2;
+      private boolean someValue = false;
+
+      @Inject
+      public void setTest2(Test2 test2)
+      {
+         this.test2 = test2;
+         someValue = test2.test3.someValue;
+      }
+   }
+
+   public static class Test2
+   {
+      private Test3 test3;
+
+      @Inject
+      public void setTest3(Test3 test3)
+      {
+         this.test3 = test3;
+      }
+   }
+
+   public static class Test3
+   {
+      private boolean someValue = true;
+   }
 }
+

Modified: core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -16,6 +16,8 @@
 import org.jboss.cache.factories.InterceptorChainFactory;
 import org.jboss.cache.interceptors.Interceptor;
 import org.jboss.cache.invocation.RemoteCacheInvocationDelegate;
+import org.jboss.cache.loader.CacheLoader;
+import org.jboss.cache.loader.CacheLoaderManager;
 import org.jboss.cache.util.CachePrinter;
 
 import java.io.File;
@@ -414,12 +416,12 @@
       {
          if (c != null && c.getCacheStatus() == CacheStatus.STARTED)
          {
-            CacheImpl ci = (CacheImpl) c;
-            if (ci.getTransactionManager() != null)
+            CacheSPI spi = (CacheSPI) c;
+            if (spi.getTransactionManager() != null)
             {
                try
                {
-                  ci.getTransactionManager().rollback();
+                  spi.getTransactionManager().rollback();
                }
                catch (Exception e)
                {
@@ -427,11 +429,13 @@
                }
             }
 
-            if (ci.getCacheLoader() != null)
+            CacheLoaderManager clm = spi.getCacheLoaderManager();
+            CacheLoader cl = clm == null ? null : clm.getCacheLoader();
+            if (cl != null)
             {
                try
                {
-                  ci.getCacheLoader().remove(Fqn.ROOT);
+                  cl.remove(Fqn.ROOT);
                }
                catch (Exception e)
                {
@@ -439,8 +443,8 @@
                }
             }
 
-            ci.stop();
-            ci.destroy();
+            spi.stop();
+            spi.destroy();
          }
       }
    }

Modified: core/trunk/src/test/java/org/jboss/cache/options/FailSilentlyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/FailSilentlyTest.java	2007-12-11 18:17:24 UTC (rev 4841)
+++ core/trunk/src/test/java/org/jboss/cache/options/FailSilentlyTest.java	2007-12-12 14:41:07 UTC (rev 4842)
@@ -7,7 +7,7 @@
 package org.jboss.cache.options;
 
 import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
 import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.config.Configuration;
@@ -29,7 +29,7 @@
 @Test(groups = {"functional"})
 public class FailSilentlyTest
 {
-   private CacheImpl cache;
+   private CacheSPI cache;
    private TransactionManager manager;
    private Transaction tx;
    private Fqn<String> fqn = Fqn.fromString("/a");
@@ -41,7 +41,7 @@
       if (cache != null)
          tearDown();
       CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
-      cache = (CacheImpl) instance.createCache(false);
+      cache = (CacheSPI) instance.createCache(false);
       // very short acquisition timeout
       cache.getConfiguration().setLockAcquisitionTimeout(100);
       cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
@@ -100,7 +100,7 @@
       cache.get(fqn, key);
       tx = manager.suspend();
       cache.getInvocationContext().getOptionOverrides().setFailSilently(true);
-      cache.remove(fqn);
+      cache.removeNode(fqn);
    }
 
    public void testRemoveKey() throws Exception
@@ -122,7 +122,7 @@
       cache.put(fqn, key, "value2");
       tx = manager.suspend();
       cache.getInvocationContext().getOptionOverrides().setFailSilently(true);
-      cache.get(fqn);
+      cache.getNode(fqn);
    }
 
    public void testGetKey() throws Exception




More information about the jbosscache-commits mailing list