[jboss-cvs] JBossCache/src/org/jboss/cache/transaction ...

Elias Ross genman at noderunner.net
Tue Nov 21 03:57:02 EST 2006


  User: genman  
  Date: 06/11/21 03:57:02

  Modified:    src/org/jboss/cache/transaction  DummyTransaction.java
  Log:
  source code tidy and taking advatage of JDK1.5
  
  Revision  Changes    Path
  1.9       +93 -84    JBossCache/src/org/jboss/cache/transaction/DummyTransaction.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DummyTransaction.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/transaction/DummyTransaction.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- DummyTransaction.java	12 Apr 2006 15:16:14 -0000	1.8
  +++ DummyTransaction.java	21 Nov 2006 08:57:02 -0000	1.9
  @@ -6,28 +6,29 @@
   import javax.transaction.*;
   import javax.transaction.xa.XAResource;
   import java.util.Iterator;
  -import java.util.LinkedList;
  -import java.util.List;
  +import java.util.Set;
  +import java.util.concurrent.CopyOnWriteArraySet;
   
   /**
    * @author bela
  - * @version $Revision: 1.8 $
  + * @version $Revision: 1.9 $
    *          Date: May 15, 2003
    *          Time: 4:20:17 PM
    */
  -public class DummyTransaction implements Transaction {
  -   int status=Status.STATUS_UNKNOWN;
  -   static final Log log=LogFactory.getLog(DummyTransaction.class);
  +public class DummyTransaction implements Transaction
  +{
  +   int status = Status.STATUS_UNKNOWN;
  +
  +   static final Log log = LogFactory.getLog(DummyTransaction.class);
  +
      DummyBaseTransactionManager tm_;
   
  -   /**
  -    * List<Synchronization>
  -    */
  -   final List participants=new LinkedList();
  +   final Set<Synchronization> participants = new CopyOnWriteArraySet<Synchronization>();
   
  -   public DummyTransaction(DummyBaseTransactionManager tm) {
  -      tm_=tm;
  -      status=Status.STATUS_ACTIVE;
  +   public DummyTransaction(DummyBaseTransactionManager tm)
  +   {
  +      tm_ = tm;
  +      status = Status.STATUS_ACTIVE;
      }
   
      /**
  @@ -46,27 +47,33 @@
       * @throws SecurityException          If the caller is not allowed to commit this
       *                                    transaction.
       */
  -   public void commit() throws RollbackException, HeuristicMixedException,
  -                               HeuristicRollbackException, SecurityException, SystemException {
  +   public void commit()
  +	  	throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
  +        SecurityException, SystemException
  +   {
         boolean doCommit;
  -      status=Status.STATUS_PREPARING;
  -      try {
  -         boolean outcome=notifyBeforeCompletion();
  +      status = Status.STATUS_PREPARING;
  +      try
  +      {
  +         boolean outcome = notifyBeforeCompletion();
            // status=Status.STATUS_PREPARED;
  -         if(outcome == true && status != Status.STATUS_MARKED_ROLLBACK) {
  -            status=Status.STATUS_COMMITTING;
  -            doCommit=true;
  -         }
  -         else {
  -            status=Status.STATUS_ROLLING_BACK;
  -            doCommit=false;
  -         }
  -         notifyAfterCompletion(doCommit? Status.STATUS_COMMITTED : Status.STATUS_MARKED_ROLLBACK);
  -         status=doCommit? Status.STATUS_COMMITTED : Status.STATUS_MARKED_ROLLBACK;
  -         if(doCommit == false)
  -            throw new RollbackException("outcome is "+ outcome + " status: " +status);
  +         if (outcome == true && status != Status.STATUS_MARKED_ROLLBACK)
  +         {
  +            status = Status.STATUS_COMMITTING;
  +            doCommit = true;
  +         }
  +         else
  +         {
  +            status = Status.STATUS_ROLLING_BACK;
  +            doCommit = false;
  +         }
  +         notifyAfterCompletion(doCommit ? Status.STATUS_COMMITTED : Status.STATUS_MARKED_ROLLBACK);
  +         status = doCommit ? Status.STATUS_COMMITTED : Status.STATUS_MARKED_ROLLBACK;
  +         if (doCommit == false)
  +            throw new RollbackException("outcome is " + outcome + " status: " + status);
         }
  -      finally {
  +      finally
  +      {
            // Disassociate tx from thread.
            tm_.setTransaction(null);
         }
  @@ -82,18 +89,21 @@
       * @throws SystemException       If the transaction service fails in an
       *                               unexpected way.
       */
  -   public void rollback() throws IllegalStateException, SystemException {
  -      try {
  +   public void rollback() throws IllegalStateException, SystemException
  +   {
  +      try
  +      {
            // JBCACHE-360 -- to match JBossTM (and presumable the spec) a 
            // rollback transaction should have status ROLLEDBACK before 
            // calling afterCompletion().
            //status=Status.STATUS_ROLLING_BACK;
  -         status=Status.STATUS_ROLLEDBACK;
  +         status = Status.STATUS_ROLLEDBACK;
            notifyAfterCompletion(Status.STATUS_ROLLEDBACK);
         }
  -      catch(Throwable t) {
  +      catch (Throwable t)
  +      {
         }
  -      status=Status.STATUS_ROLLEDBACK;
  +      status = Status.STATUS_ROLLEDBACK;
   
         // Disassociate tx from thread.
         tm_.setTransaction(null);
  @@ -107,8 +117,9 @@
       * @throws SystemException       If the transaction service fails in an
       *                               unexpected way.
       */
  -   public void setRollbackOnly() throws IllegalStateException, SystemException {
  -      status=Status.STATUS_MARKED_ROLLBACK;
  +   public void setRollbackOnly() throws IllegalStateException, SystemException
  +   {
  +      status = Status.STATUS_MARKED_ROLLBACK;
      }
   
      /**
  @@ -119,7 +130,8 @@
       * @throws SystemException If the transaction service fails in an
       *                         unexpected way.
       */
  -   public int getStatus() throws SystemException {
  +   public int getStatus() throws SystemException
  +   {
         return status;
      }
   
  @@ -133,7 +145,8 @@
       * @throws SystemException If the transaction service fails in an
       *                         unexpected way.
       */
  -   public void setTransactionTimeout(int seconds) throws SystemException {
  +   public void setTransactionTimeout(int seconds) throws SystemException
  +   {
         throw new SystemException("not supported");
      }
   
  @@ -152,7 +165,8 @@
       *                               unexpected way.
       */
      public boolean enlistResource(XAResource xaRes)
  -           throws RollbackException, IllegalStateException, SystemException {
  +	     throws RollbackException, IllegalStateException, SystemException
  +   {
         throw new SystemException("not supported");
      }
   
  @@ -168,7 +182,8 @@
       *                               unexpected way.
       */
      public boolean delistResource(XAResource xaRes, int flag)
  -           throws IllegalStateException, SystemException {
  +	     throws IllegalStateException, SystemException
  +   {
         throw new SystemException("not supported");
      }
   
  @@ -186,11 +201,13 @@
       *                               unexpected way.
       */
      public void registerSynchronization(Synchronization sync)
  -           throws RollbackException, IllegalStateException, SystemException {
  -      if(sync == null)
  +	     throws RollbackException, IllegalStateException, SystemException
  +   {
  +      if (sync == null)
            throw new IllegalArgumentException("null synchronization " + this);
   
  -      switch(status) {
  +      switch (status)
  +      {
            case Status.STATUS_ACTIVE:
            case Status.STATUS_PREPARING:
               break;
  @@ -214,68 +231,60 @@
               throw new IllegalStateException("illegal status: " + status + " tx=" + this);
         }
   
  -      synchronized(participants) {
  -         if(!participants.contains(sync)) {
  -             if (log.isDebugEnabled()) {
  +      if (log.isDebugEnabled())
  +      {
                    log.debug("registering synchronization handler " + sync);
                }
               participants.add(sync);
  -         }
  -      }
  -   }
   
  -
  -   void setStatus(int new_status) {
  -      status=new_status;
      }
   
  -
  -   boolean notifyBeforeCompletion() {
  -      boolean retval=true;
  -      List tmp;
  -
  -      synchronized(participants) {
  -         tmp=new LinkedList(participants);
  +   void setStatus(int new_status)
  +   {
  +      status = new_status;
         }
   
  -      for(Iterator it=tmp.iterator(); it.hasNext();) {
  -         Synchronization s=(Synchronization)it.next();
  -         if (log.isDebugEnabled()) {
  +   boolean notifyBeforeCompletion()
  +   {
  +      boolean retval = true;
  +
  +      for (Synchronization s : participants)
  +      {
  +         if (log.isDebugEnabled())
  +         {
                log.debug("processing beforeCompletion for " + s);
            }
  -         try {
  +         try
  +         {
               s.beforeCompletion();
            }
  -         catch(Throwable t) {
  -            retval=false;
  +         catch (Throwable t)
  +         {
  +            retval = false;
               log.error("beforeCompletion() failed for " + s, t);
            }
         }
         return retval;
      }
   
  -   void notifyAfterCompletion(int status) {
  -      List tmp;
  -
  -      synchronized(participants) {
  -         tmp=new LinkedList(participants);
  -      }
  -
  -      for(Iterator it=tmp.iterator(); it.hasNext();) {
  -         Synchronization s=(Synchronization)it.next();
  -         if (log.isDebugEnabled()) {
  +   void notifyAfterCompletion(int status)
  +   {
  +      for (Synchronization s : participants)
  +      {
  +         if (log.isDebugEnabled())
  +         {
                log.debug("processing afterCompletion for " + s);
            }
  -         try {
  +         try
  +         {
               s.afterCompletion(status);
            }
  -         catch(Throwable t) {
  +         catch (Throwable t)
  +         {
               log.error("afterCompletion() failed for " + s, t);
            }
         }
  -      synchronized(participants) {
            participants.clear();
         }
  -   }
   
   }
  
  
  



More information about the jboss-cvs-commits mailing list