[jboss-cvs] JBossCache/src-50/org/jboss/cache/pojo/interceptors ...

Ben Wang bwang at jboss.com
Thu Jul 27 10:25:27 EDT 2006


  User: bwang   
  Date: 06/07/27 10:25:27

  Modified:    src-50/org/jboss/cache/pojo/interceptors    
                        CheckIdInterceptor.java
                        CheckNonSerializableInterceptor.java
                        PojoTxInterceptor.java PojoTxLockInterceptor.java
  Log:
  Moved the interceptor annotation and also now lock parent node for Collection.
  
  Revision  Changes    Path
  1.5       +5 -6      JBossCache/src-50/org/jboss/cache/pojo/interceptors/CheckIdInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CheckIdInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/interceptors/CheckIdInterceptor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- CheckIdInterceptor.java	13 Jul 2006 16:53:13 -0000	1.4
  +++ CheckIdInterceptor.java	27 Jul 2006 14:25:27 -0000	1.5
  @@ -13,7 +13,7 @@
   import org.jboss.cache.pojo.InternalConstant;
   
   /** Interceptor (done via aop advice) to check the validity of the id specified by the user.
  - * @version $Id: CheckIdInterceptor.java,v 1.4 2006/07/13 16:53:13 bwang Exp $
  + * @version $Id: CheckIdInterceptor.java,v 1.5 2006/07/27 14:25:27 bwang Exp $
    */
   public class CheckIdInterceptor extends AbstractInterceptor
   {
  @@ -27,20 +27,19 @@
         MethodInvocation invocation = (MethodInvocation)in;
         invocation.getAdvisor();
         try {
  -         checkFqnValidity((String)invocation.getArguments()[0]);
  +         checkFqnValidity((Fqn)invocation.getArguments()[0]);
            return invocation.invokeNext(); // proceed to next advice or actual call
         } finally {
         }
      }
   
   
  -   private static void checkFqnValidity(String id)
  +   private static void checkFqnValidity(Fqn id)
      {
         // throws exception is fqn is JBossInternal
  -      Fqn fqn = Fqn.fromString(id);
  -      if (fqn.equals(InternalConstant.JBOSS_INTERNAL))
  +      if (id.equals(InternalConstant.JBOSS_INTERNAL))
         {
  -         throw new IllegalArgumentException("CheckIdIntercepto.checkFqnValidity(): fqn is not valid: " + fqn);
  +         throw new IllegalArgumentException("CheckIdIntercepto.checkFqnValidity(): fqn is not valid: " + id);
         }
      }
   }
  
  
  
  1.3       +4 -3      JBossCache/src-50/org/jboss/cache/pojo/interceptors/CheckNonSerializableInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CheckNonSerializableInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/interceptors/CheckNonSerializableInterceptor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- CheckNonSerializableInterceptor.java	13 Jul 2006 15:56:12 -0000	1.2
  +++ CheckNonSerializableInterceptor.java	27 Jul 2006 14:25:27 -0000	1.3
  @@ -10,9 +10,10 @@
   import org.jboss.aop.joinpoint.Invocation;
   import org.jboss.aop.joinpoint.MethodInvocation;
   import org.jboss.cache.pojo.util.AopUtil;
  +import org.jboss.cache.Fqn;
   
   /** Interceptor (done via aop advice) to check the validity of the id specified by the user.
  - * @version $Id: CheckNonSerializableInterceptor.java,v 1.2 2006/07/13 15:56:12 bwang Exp $
  + * @version $Id: CheckNonSerializableInterceptor.java,v 1.3 2006/07/27 14:25:27 bwang Exp $
    */
   public class CheckNonSerializableInterceptor extends AbstractInterceptor
   {
  @@ -26,7 +27,7 @@
         }
   
         MethodInvocation invocation = (MethodInvocation)in;
  -      String id = (String) invocation.getArguments()[0];
  +      Fqn id = (Fqn) invocation.getArguments()[0];
         Object obj = invocation.getArguments()[1];
         if (!marshallNonSerializable_)
         {
  @@ -34,7 +35,7 @@
         } else
         {
            log.debug("invoke(): marshallNonSerializable is set to true. We will skip object type checking for id:"
  -         + id);
  +         + id.toString());
         }
   
         try {
  
  
  
  1.2       +6 -5      JBossCache/src-50/org/jboss/cache/pojo/interceptors/PojoTxInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PojoTxInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/interceptors/PojoTxInterceptor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- PojoTxInterceptor.java	6 Jul 2006 02:42:35 -0000	1.1
  +++ PojoTxInterceptor.java	27 Jul 2006 14:25:27 -0000	1.2
  @@ -11,6 +11,7 @@
   import org.jboss.aop.joinpoint.MethodInvocation;
   import org.jboss.cache.pojo.PojoCacheException;
   import org.jboss.cache.transaction.BatchModeTransactionManager;
  +import org.jboss.cache.Fqn;
   
   import javax.transaction.RollbackException;
   import javax.transaction.Status;
  @@ -21,7 +22,7 @@
    * Interceptor (done via aop advice) for transaction
    *
    * @author Ben Wang
  - * @version $Id: PojoTxInterceptor.java,v 1.1 2006/07/06 02:42:35 bwang Exp $
  + * @version $Id: PojoTxInterceptor.java,v 1.2 2006/07/27 14:25:27 bwang Exp $
    */
   public class PojoTxInterceptor extends AbstractInterceptor
   {
  @@ -41,13 +42,13 @@
         Transaction tx = getCache(invocation).getTransaction();
         boolean needTx = false;
         if (tx == null) needTx = true;
  -      String id = null;
  +      Fqn id = null;
         try
         {
            if (needTx)
            {
  -            id = (String) invocation.getArguments()[0];
  -            log.debug("Initiating a local transaction for batch processing with id: " +id);
  +            id = (Fqn) invocation.getArguments()[0];
  +            log.debug("Initiating a local transaction for batch processing with id: " +id.toString());
               // Start one of our own as batch processing.
               try
               {
  @@ -88,7 +89,7 @@
         }
      }
   
  -   private void endTransaction(String id)
  +   private void endTransaction(Fqn id)
      {
         if (localTm_ == null)
         {
  
  
  
  1.4       +22 -7     JBossCache/src-50/org/jboss/cache/pojo/interceptors/PojoTxLockInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PojoTxLockInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/interceptors/PojoTxLockInterceptor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- PojoTxLockInterceptor.java	7 Jul 2006 09:34:41 -0000	1.3
  +++ PojoTxLockInterceptor.java	27 Jul 2006 14:25:27 -0000	1.4
  @@ -11,13 +11,15 @@
   import org.jboss.aop.joinpoint.MethodInvocation;
   import org.jboss.cache.pojo.PojoCacheException;
   import org.jboss.cache.pojo.PojoTreeCache;
  +import org.jboss.cache.pojo.InternalConstant;
   import org.jboss.cache.lock.UpgradeException;
   import org.jboss.cache.CacheException;
  +import org.jboss.cache.Fqn;
   
   /** Interceptor that handles the parent node lock associated with transaction.
    *
    * @author Ben Wang
  - * @version $Id: PojoTxLockInterceptor.java,v 1.3 2006/07/07 09:34:41 bwang Exp $
  + * @version $Id: PojoTxLockInterceptor.java,v 1.4 2006/07/27 14:25:27 bwang Exp $
    */
   public class PojoTxLockInterceptor extends AbstractInterceptor
   {
  @@ -32,13 +34,13 @@
            handleLock(invocation);
            return invocation.invokeNext(); // proceed to next advice or actual call
         } finally {
  -         // No need to release now.
  +//         handleUnLock(invocation);
         }
      }
   
      private void handleLock(MethodInvocation invocation) throws Throwable
      {
  -      String id = (String)invocation.getArguments()[0];
  +      Fqn id = (Fqn)invocation.getArguments()[0];
         PojoTreeCache cache = getCache(invocation);
         Object owner = cache.getLockOwner();
         if (!lockPojo(owner, id, cache))
  @@ -47,7 +49,7 @@
         }
      }
   
  -   private boolean lockPojo(Object owner, String id, PojoTreeCache cache) throws CacheException
  +   private boolean lockPojo(Object owner, Fqn id, PojoTreeCache cache) throws CacheException
      {
         if (log.isDebugEnabled())
         {
  @@ -56,17 +58,30 @@
   
         boolean isNeeded = true;
         int retry = 0;
  +      // If this is an internal id and also it has three levels, we are saying this is
  +      // Collection, and we need to lock the parent as well.
  +      // TODO Still a bit ad hoc.
  +      Fqn realId = id;
  +      if(id.isChildOrEquals(InternalConstant.JBOSS_INTERNAL) && id.size() > 2)
  +      {
  +         realId = id.getParent();
  +         if (log.isDebugEnabled())
  +         {
  +            log.debug("lockPojo(): will lock parent id instead:" + realId);
  +         }
  +      }
  +
         while (isNeeded)
         {
            try
            {
  -            cache.put(id, LOCK, "LOCK");
  +            cache.put(realId, LOCK, "LOCK");
               isNeeded = false;
            } catch (UpgradeException upe)
            {
  -            log.warn("lockPojo(): can't upgrade the lock during lockPojo. Will re-try. id: " + id
  +            log.warn("lockPojo(): can't upgrade the lock during lockPojo. Will re-try. id: " + realId
                       + " retry times: " + retry);
  -            cache.get(id).release(owner);
  +            cache.get(realId).release(owner);
               if (retry++ > RETRY)
               {
                  return false;
  
  
  



More information about the jboss-cvs-commits mailing list