commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From luetzkend...@apache.org
Subject cvs commit: jakarta-commons/transaction/src/java/org/apache/commons/transaction/util RendezvousBarrier.java
Date Mon, 29 Nov 2004 18:28:17 GMT
luetzkendorf    2004/11/29 10:28:17

  Modified:    transaction/src/java/org/apache/commons/transaction/util/xa
                        AbstractXAResource.java XidWrapper.java
               transaction/src/java/org/apache/commons/transaction/file
                        FileResourceManager.java
               transaction/src/java/org/apache/commons/transaction/locking
                        GenericLock.java
               transaction/src/java/org/apache/commons/transaction/util
                        RendezvousBarrier.java
  Log:
  logging now tests for appropriate logging level as early as possible
  
  Revision  Changes    Path
  1.2       +30 -20    jakarta-commons/transaction/src/java/org/apache/commons/transaction/util/xa/AbstractXAResource.java
  
  Index: AbstractXAResource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/transaction/src/java/org/apache/commons/transaction/util/xa/AbstractXAResource.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractXAResource.java	18 Nov 2004 23:27:19 -0000	1.1
  +++ AbstractXAResource.java	29 Nov 2004 18:28:17 -0000	1.2
  @@ -53,7 +53,9 @@
       protected abstract boolean includeBranchInXid();
       
       public void forget(Xid xid) throws XAException {
  -        getLoggerFacade().logFine("Forgetting transaction branch " + xid);
  +        if (getLoggerFacade().isFineEnabled()) {
  +            getLoggerFacade().logFine("Forgetting transaction branch " + xid);
  +        }
           TransactionalResource ts = getTransactionalResource(xid);
           if (ts == null) {
               throw new XAException(XAException.XAER_NOTA);
  @@ -69,7 +71,9 @@
               throw new XAException(XAException.XAER_NOTA);
           }
   
  -        getLoggerFacade().logFine("Committing transaction branch " + ts);
  +        if (getLoggerFacade().isFineEnabled()) {
  +            getLoggerFacade().logFine("Committing transaction branch " + ts);
  +        }
   
           if (ts.getStatus() == STATUS_MARKED_ROLLBACK) {
               throw new XAException(XAException.XA_RBROLLBACK);
  @@ -94,7 +98,9 @@
               throw new XAException(XAException.XAER_NOTA);
           }
   
  -        getLoggerFacade().logFine("Rolling back transaction branch " + ts);
  +        if (getLoggerFacade().isFineEnabled()) {
  +            getLoggerFacade().logFine("Rolling back transaction branch " + ts);
  +        }
   
           ts.rollback();
           setCurrentlyActiveTransactionalResource(null);
  @@ -108,7 +114,9 @@
               throw new XAException(XAException.XAER_NOTA);
           }
   
  -        getLoggerFacade().logFine("Preparing transaction branch " + ts);
  +        if (getLoggerFacade().isFineEnabled()) {
  +            getLoggerFacade().logFine("Preparing transaction branch " + ts);
  +        }
   
           if (ts.getStatus() == STATUS_MARKED_ROLLBACK) {
               throw new XAException(XAException.XA_RBROLLBACK);
  @@ -127,12 +135,13 @@
           if (getCurrentlyActiveTransactionalResource() == null) {
               throw new XAException(XAException.XAER_INVAL);
           }
  -        getLoggerFacade().logFine(
  -            "Thread "
  -                + Thread.currentThread()
  -                + (flags == TMSUSPEND ? " suspends" : flags == TMFAIL ? " fails" : " ends")
  -                + " work on behalf of transaction branch "
  -                + ts);
  +        if (getLoggerFacade().isFineEnabled()) {
  +	        getLoggerFacade().logFine(new StringBuffer(128)
  +	            .append("Thread ").append(Thread.currentThread())
  +	            .append(flags == TMSUSPEND ? " suspends" : flags == TMFAIL ? " fails" : "
ends")
  +	            .append(" work on behalf of transaction branch ")
  +	            .append(ts).toString());
  +        }
   
           switch (flags) {
               case TMSUSPEND :
  @@ -153,13 +162,14 @@
           if (getCurrentlyActiveTransactionalResource() != null) {
               throw new XAException(XAException.XAER_INVAL);
           }
  -        getLoggerFacade().logFine(
  -            "Thread "
  -                + Thread.currentThread()
  -                + (flags == TMNOFLAGS ? " starts" : flags == TMJOIN ? " joins" : " resumes")
  -                + " work on behalf of transaction branch "
  -                + xid);
  -
  +        if (getLoggerFacade().isFineEnabled()) {
  +            getLoggerFacade().logFine(new StringBuffer(128)
  +                    .append("Thread ").append(Thread.currentThread())
  +                    .append(flags == TMNOFLAGS ? " starts" : flags == TMJOIN ? " joins"
: " resumes")
  +                    .append(" work on behalf of transaction branch ")
  +                    .append(xid).toString());
  +        }
  +        
           TransactionalResource ts;
           switch (flags) {
               // a new transaction
  
  
  
  1.2       +8 -5      jakarta-commons/transaction/src/java/org/apache/commons/transaction/util/xa/XidWrapper.java
  
  Index: XidWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/transaction/src/java/org/apache/commons/transaction/util/xa/XidWrapper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XidWrapper.java	18 Nov 2004 23:27:19 -0000	1.1
  +++ XidWrapper.java	29 Nov 2004 18:28:17 -0000	1.2
  @@ -52,10 +52,13 @@
       private XidWrapper(Xid xid, boolean includeBranch) {
           this.xid = xid;
           // do calculations once for performance
  -        asString =
  -            new String(xid.getGlobalTransactionId())
  -                + (includeBranch ? "-" + new String(xid.getBranchQualifier()) : "");
  +        StringBuffer b = new StringBuffer(64);
  +        b.append(xid.getGlobalTransactionId());
  +        if (includeBranch) {
  +            b.append("-").append(xid.getBranchQualifier());
  +        }
   
  +        asString = b.toString();
           hashCode = asString.hashCode();
       }
   
  
  
  
  1.2       +36 -29    jakarta-commons/transaction/src/java/org/apache/commons/transaction/file/FileResourceManager.java
  
  Index: FileResourceManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/transaction/src/java/org/apache/commons/transaction/file/FileResourceManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileResourceManager.java	18 Nov 2004 23:27:19 -0000	1.1
  +++ FileResourceManager.java	29 Nov 2004 18:28:17 -0000	1.2
  @@ -342,7 +342,7 @@
           if (context == null) {
               msecs = getDefaultTransactionTimeout();
           } else {
  -            msecs = ((TransactionContext) context).timeoutMSecs;
  +            msecs = context.timeoutMSecs;
           }
           return msecs;
       }
  @@ -351,7 +351,7 @@
           assureRMReady();
           TransactionContext context = getContext(txId);
           if (context != null) {
  -            ((TransactionContext) context).timeoutMSecs = mSecs;
  +            context.timeoutMSecs = mSecs;
           } else {
               throw new ResourceManagerException(ERR_NO_TX, txId);
           }
  @@ -372,7 +372,7 @@
           TransactionContext context = getContext(txId);
           if (context != null) {
               if (level != ISOLATION_LEVEL_READ_COMMITTED || level != ISOLATION_LEVEL_REPEATABLE_READ)
{
  -                ((TransactionContext) context).isolationLevel = level;
  +                context.isolationLevel = level;
               } else {
                   throw new ResourceManagerException(ERR_ISOLATION_LEVEL_UNSUPPORTED, txId);
               }
  @@ -462,7 +462,7 @@
   
       public void startTransaction(Object txId) throws ResourceManagerException {
   
  -        logger.logFine("Starting Tx " + txId);
  +        if (logger.isFineEnabled()) logger.logFine("Starting Tx " + txId);
   
           assureStarted(); // can only start a new transaction when not already stopping
           if (txId == null || txId.toString().length() == 0) {
  @@ -526,7 +526,7 @@
                   return PREPARE_FAILURE;
               }
   
  -            logger.logFine("Preparing Tx " + txId);
  +            if (logger.isFineEnabled()) logger.logFine("Preparing Tx " + txId);
   
               int prepareStatus = PREPARE_FAILURE;
   
  @@ -549,7 +549,7 @@
               }
               context.status = STATUS_PREPARED;
               context.saveState();
  -            logger.logFine("Prepared Tx " + txId);
  +            if (logger.isFineEnabled()) logger.logFine("Prepared Tx " + txId);
   
               return prepareStatus;
           }
  @@ -562,7 +562,7 @@
           synchronized (context) {
               try {
   
  -                logger.logFine("Rolling back Tx " + txId);
  +                if (logger.isFineEnabled()) logger.logFine("Rolling back Tx " + txId);
   
                   context.status = STATUS_ROLLING_BACK;
                   context.saveState();
  @@ -572,7 +572,7 @@
                   globalTransactions.remove(txId);
                   context.cleanUp();
   
  -                logger.logFine("Rolled back Tx " + txId);
  +                if (logger.isFineEnabled()) logger.logFine("Rolled back Tx " + txId);
   
                   // any system or runtime exceptions or errors thrown in rollback means
we are in deep trouble, set the dirty flag
               } catch (Error e) {
  @@ -601,7 +601,7 @@
           synchronized (context) {
               try {
   
  -                logger.logFine("Committing Tx " + txId);
  +                if (logger.isFineEnabled()) logger.logFine("Committing Tx " + txId);
   
                   context.status = STATUS_COMMITTING;
                   context.saveState();
  @@ -611,7 +611,7 @@
                   globalTransactions.remove(txId);
                   context.cleanUp();
   
  -                logger.logFine("Committed Tx " + txId);
  +                if (logger.isFineEnabled()) logger.logFine("Committed Tx " + txId);
   
                   // any system or runtime exceptions or errors thrown in rollback means
we are in deep trouble, set the dirty flag
               } catch (Error e) {
  @@ -641,7 +641,8 @@
           TransactionContext context;
           synchronized (globalTransactions) {
               txId = generatedUniqueTxId();
  -            logger.logFiner("Creating temporary light weight tx " + txId + " to check for
exists");
  +            if (logger.isFinerEnabled())
  +                logger.logFiner("Creating temporary light weight tx " + txId + " to check
for exists");
               context = new TransactionContext(txId);
               context.isLightWeight = true;
               // XXX higher isolation might be needed to make sure upgrade to commit lock
always works
  @@ -654,7 +655,8 @@
   
           context.freeLocks();
           globalTransactions.remove(txId);
  -        logger.logFiner("Removing temporary light weight tx " + txId);
  +        if (logger.isFinerEnabled())
  +            logger.logFiner("Removing temporary light weight tx " + txId);
   
           return exists;
       }
  @@ -670,7 +672,7 @@
   
       public void deleteResource(Object txId, Object resourceId, boolean assureOnly) throws
ResourceManagerException {
   
  -        logger.logFine(txId + " deleting " + resourceId);
  +        if (logger.isFineEnabled()) logger.logFine(txId + " deleting " + resourceId);
   
           assureLock(resourceId, txId, false);
   
  @@ -707,7 +709,7 @@
   
       public void createResource(Object txId, Object resourceId, boolean assureOnly) throws
ResourceManagerException {
   
  -        logger.logFine(txId + " creating " + resourceId);
  +        if (logger.isFineEnabled()) logger.logFine(txId + " creating " + resourceId);
   
           assureLock(resourceId, txId, false);
   
  @@ -749,7 +751,8 @@
           Object txId;
           synchronized (globalTransactions) {
               txId = generatedUniqueTxId();
  -            logger.logFiner("Creating temporary light weight tx " + txId + " for reading");
  +            if (logger.isFinerEnabled())
  +                logger.logFiner("Creating temporary light weight tx " + txId + " for reading");
               TransactionContext context = new TransactionContext(txId);
               context.isLightWeight = true;
               // XXX higher isolation might be needed to make sure upgrade to commit lock
always works
  @@ -764,7 +767,7 @@
   
       public InputStream readResource(Object txId, Object resourceId) throws ResourceManagerException
{
   
  -        logger.logFine(txId + " reading " + resourceId);
  +        if (logger.isFineEnabled()) logger.logFine(txId + " reading " + resourceId);
   
           assureLock(resourceId, txId, true);
   
  @@ -785,7 +788,7 @@
   
       public OutputStream writeResource(Object txId, Object resourceId) throws ResourceManagerException
{
   
  -        logger.logFine(txId + " writing " + resourceId);
  +        if (logger.isFineEnabled()) logger.logFine(txId + " writing " + resourceId);
   
           assureLock(resourceId, txId, false);
   
  @@ -1097,7 +1100,8 @@
        */
   
       protected void registerOpenResource(Object openResource) {
  -        logger.logFiner("Registering open resource " + openResource);
  +        if (logger.isFinerEnabled())
  +            logger.logFiner("Registering open resource " + openResource);
           globalOpenResources.add(openResource);
       }
   
  @@ -1114,7 +1118,7 @@
       }
   
       protected void closeOpenResource(Object openResource) {
  -        logger.logFiner("Releasing resource " + openResource);
  +        if (logger.isFinerEnabled()) logger.logFiner("Releasing resource " + openResource);
           globalOpenResources.remove(openResource);
           if (openResource instanceof InputStream) {
               InputStream is = (InputStream) openResource;
  @@ -1556,18 +1560,21 @@
                   }
                   synchronized (context) {
                       if (context.isLightWeight) {
  -                        logger.logFiner("Upon close of resource removing temporary light
weight tx " + txId);
  +                        if (logger.isFinerEnabled())
  +                            logger.logFiner("Upon close of resource removing temporary
light weight tx " + txId);
                           context.freeLocks();
                           globalTransactions.remove(txId);
                       } else {
                           // release access lock in order to allow other transactions to
commit
                           MultiLevelLock lock = lockManager.atomicGetOrCreateLock(resourceId);
                           if (lock.getLockLevel(txId) == LOCK_ACCESS) {
  -                            logger.logFiner(
  -                                "Upon close of resource releasing access lock for tx "
  -                                    + txId
  -                                    + " on resource at "
  -                                    + resourceId);
  +                            if (logger.isFinerEnabled()) {
  +	                            logger.logFiner(
  +	                                "Upon close of resource releasing access lock for tx "
  +	                                    + txId
  +	                                    + " on resource at "
  +	                                    + resourceId);
  +                            }
                               lock.release(txId);
                           }
                       }
  
  
  
  1.2       +69 -55    jakarta-commons/transaction/src/java/org/apache/commons/transaction/locking/GenericLock.java
  
  Index: GenericLock.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/transaction/src/java/org/apache/commons/transaction/locking/GenericLock.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GenericLock.java	18 Nov 2004 23:27:17 -0000	1.1
  +++ GenericLock.java	29 Nov 2004 18:28:17 -0000	1.2
  @@ -195,23 +195,27 @@
           long timeoutMSecs)
           throws InterruptedException {
   
  -        logger.logFiner(
  -            ownerId.toString()
  -                + " trying to acquire lock for "
  -                + resourceId.toString()
  -                + " at level "
  -                + targetLockLevel
  -                + " at "
  -                + System.currentTimeMillis());
  +        if (logger.isFinerEnabled()) {
  +	        logger.logFiner(
  +	            ownerId.toString()
  +	                + " trying to acquire lock for "
  +	                + resourceId.toString()
  +	                + " at level "
  +	                + targetLockLevel
  +	                + " at "
  +	                + System.currentTimeMillis());
  +        }
   
           if (tryLock(ownerId, targetLockLevel, compatibility)) {
  -
  -            logger.logFiner(
  -                ownerId.toString()
  -                    + " actually acquired lock for "
  -                    + resourceId.toString()
  -                    + " at "
  -                    + System.currentTimeMillis());
  +            
  +            if (logger.isFinerEnabled()) {
  +	            logger.logFiner(
  +	                ownerId.toString()
  +	                    + " actually acquired lock for "
  +	                    + resourceId.toString()
  +	                    + " at "
  +	                    + System.currentTimeMillis());
  +            }
   
               return true;
           } else {
  @@ -223,24 +227,28 @@
                       remaining > 0;
                       remaining = timeoutMSecs - (System.currentTimeMillis() - started))
{
   
  -                    logger.logFiner(
  -                        ownerId.toString()
  -                            + " waiting on "
  -                            + resourceId.toString()
  -                            + " for msecs "
  -                            + timeoutMSecs
  -                            + " at "
  -                            + System.currentTimeMillis());
  +                    if (logger.isFinerEnabled()) {
  +	                    logger.logFiner(
  +	                        ownerId.toString()
  +	                            + " waiting on "
  +	                            + resourceId.toString()
  +	                            + " for msecs "
  +	                            + timeoutMSecs
  +	                            + " at "
  +	                            + System.currentTimeMillis());
  +                    }
   
                       wait(remaining);
                       if (tryLock(ownerId, targetLockLevel, compatibility)) {
   
  -                        logger.logFiner(
  -                            ownerId.toString()
  -                                + " waiting on "
  -                                + resourceId.toString()
  -                                + " eventually got the lock at "
  -                                + System.currentTimeMillis());
  +                        if (logger.isFinerEnabled()) {
  +	                        logger.logFiner(
  +	                            ownerId.toString()
  +	                                + " waiting on "
  +	                                + resourceId.toString()
  +	                                + " eventually got the lock at "
  +	                                + System.currentTimeMillis());
  +                        }
   
                           return true;
                       }
  @@ -255,12 +263,14 @@
        */
       public synchronized void release(Object ownerId) {
           if (owners.remove(ownerId) != null) {
  -            logger.logFiner(
  -                ownerId.toString()
  -                    + " releasing lock for "
  -                    + resourceId.toString()
  -                    + " at "
  -                    + System.currentTimeMillis());
  +            if (logger.isFinerEnabled()) {
  +	            logger.logFiner(
  +	                ownerId.toString()
  +	                    + " releasing lock for "
  +	                    + resourceId.toString()
  +	                    + " at "
  +	                    + System.currentTimeMillis());
  +            }
               notifyAll();
           }
       }
  @@ -351,26 +361,30 @@
           // be sure there exists at most one lock per owner
           if (lock != null) {
   
  -            logger.logFinest(
  -                ownerId.toString()
  -                    + " upgrading lock for "
  -                    + resourceId.toString()
  -                    + " to level "
  -                    + targetLockLevel
  -                    + " at "
  -                    + System.currentTimeMillis());
  +            if (logger.isFinestEnabled()) {
  +	            logger.logFinest(
  +	                ownerId.toString()
  +	                    + " upgrading lock for "
  +	                    + resourceId.toString()
  +	                    + " to level "
  +	                    + targetLockLevel
  +	                    + " at "
  +	                    + System.currentTimeMillis());
  +            }
   
               lock.lockLevel = targetLockLevel;
           } else {
   
  -            logger.logFinest(
  -                ownerId.toString()
  -                    + " getting new lock for "
  -                    + resourceId.toString()
  -                    + " at level "
  -                    + targetLockLevel
  -                    + " at "
  -                    + System.currentTimeMillis());
  +            if (logger.isFinestEnabled()) {
  +	            logger.logFinest(
  +	                ownerId.toString()
  +	                    + " getting new lock for "
  +	                    + resourceId.toString()
  +	                    + " at level "
  +	                    + targetLockLevel
  +	                    + " at "
  +	                    + System.currentTimeMillis());
  +            }
   
               owners.put(ownerId, new LockOwner(ownerId, targetLockLevel));
           }
  
  
  
  1.2       +25 -19    jakarta-commons/transaction/src/java/org/apache/commons/transaction/util/RendezvousBarrier.java
  
  Index: RendezvousBarrier.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/transaction/src/java/org/apache/commons/transaction/util/RendezvousBarrier.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RendezvousBarrier.java	18 Nov 2004 23:27:18 -0000	1.1
  +++ RendezvousBarrier.java	29 Nov 2004 18:28:17 -0000	1.2
  @@ -61,7 +61,8 @@
       public synchronized void call() {
           count++;
           if (count >= parties) {
  -            logger.logFine("Thread " + Thread.currentThread().getName() + " by CALL COMPLETING
barrier " + name);
  +            if (logger.isFineEnabled()) 
  +                logger.logFine("Thread " + Thread.currentThread().getName() + " by CALL
COMPLETING barrier " + name);
               notifyAll();
           }
       }
  @@ -76,26 +77,31 @@
       public synchronized void meet() throws InterruptedException {
           count++;
           if (count >= parties) {
  -            logger.logFine("Thread " + Thread.currentThread().getName() + " by MEET COMPLETING
barrier " + name);
  +            if (logger.isFineEnabled()) 
  +                logger.logFine("Thread " + Thread.currentThread().getName() + " by MEET
COMPLETING barrier " + name);
               notifyAll();
           } else {
  -            logger.logFine(
  -                "At barrier "
  -                    + name
  -                    + " thread "
  -                    + Thread.currentThread().getName()
  -                    + " WAITING for "
  -                    + (parties - count)
  -                    + " of "
  -                    + parties
  -                    + " parties");
  +            if (logger.isFineEnabled()) {
  +	            logger.logFine(
  +	                "At barrier "
  +	                    + name
  +	                    + " thread "
  +	                    + Thread.currentThread().getName()
  +	                    + " WAITING for "
  +	                    + (parties - count)
  +	                    + " of "
  +	                    + parties
  +	                    + " parties");
  +            }
               wait(timeout);
               if (count == 0) {
                   // means the barrier has been reset
               } else if (count >= parties) {
  -                logger.logFine("Thread " + Thread.currentThread().getName() + " CONTINUING
at barrier " + name);
  +                if (logger.isFineEnabled()) 
  +                    logger.logFine("Thread " + Thread.currentThread().getName() + " CONTINUING
at barrier " + name);
               } else {
  -                logger.logFine("Thread " + Thread.currentThread().getName() + " FAILING
at barrier " + name);
  +                if (logger.isFineEnabled()) 
  +                    logger.logFine("Thread " + Thread.currentThread().getName() + " FAILING
at barrier " + name);
                   notifyAll();
               }
           }
  @@ -105,7 +111,7 @@
        * Releases all waiting threads and resets the number of parties already arrived. 
        */
       public synchronized void reset() {
  -        logger.logFine("Resetting barrier " + name);
  +        if (logger.isFineEnabled()) logger.logFine("Resetting barrier " + name);
           count = 0;
           notifyAll();
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message