ozeigermann    2004/07/01 05:34:50

  Modified:    src/share/org/apache/slide/store ExtendedStore.java
  Log:
  Added real suspension
  
  Revision  Changes    Path
  1.12      +65 -32    
jakarta-slide/src/share/org/apache/slide/store/ExtendedStore.java
  
  Index: ExtendedStore.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/store/ExtendedStore.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ExtendedStore.java        21 Jun 2004 15:58:49 -0000      1.11
  +++ ExtendedStore.java        1 Jul 2004 12:34:50 -0000       1.12
  @@ -24,9 +24,11 @@
   package org.apache.slide.store;
   
   import java.util.Enumeration;
  +import java.util.HashMap;
   import java.util.HashSet;
   import java.util.Hashtable;
   import java.util.Iterator;
  +import java.util.Map;
   import java.util.Vector;
   
   import org.apache.slide.common.ServiceAccessException;
  @@ -132,6 +134,7 @@
   
       protected boolean globalCacheOff;
   
  +    private Map suspendedLocks = new HashMap();
   
       public ExtendedStore() {
           lockManager = new GenericLockManager(1, new StoreLogger(getLogger(), 
LOG_CHANNEL));
  @@ -372,33 +375,42 @@
               noGlobalCacheInTx);
       }
   
  -    public void exclusiveTransientLock(String uri) throws ServiceAccessException {
  -        Xid txId = (Xid) activeTransactionBranch.get();
  -        try {
  -            GenericLock lock = (GenericLock) lockManager.atomicGetOrCreateLock(uri);
  -            if (lock.getLockLevel(txId) != 1) {
  -                Object owner = lock.getOwner();
  -                getLogger().log(
  -                    "Try lock: "
  -                        + txId
  -                        + " tries "
  -                        + uri
  -                        + (owner != null ? " ---> " + owner.toString() + " has it" 
: ""),
  -                    LOG_CHANNEL,
  -                    Logger.DEBUG);
  -                if (!lock.acquire(txId, 1, true, true, timeout)) {
  -                    throw new ServiceAccessException(this, new 
ConflictException(uri));
  -                }
  -                ((HashSet)locks.get()).add(lock);
  -                getLogger().log("Has lock: " + txId + " locks " + uri, LOG_CHANNEL, 
Logger.DEBUG);
  -            }
  -        } catch (InterruptedException e) {
  -            throw new ServiceAccessException(this, new ConflictException(uri));
  -        }
  -    }
  +    public void exclusiveTransientLock(String uri)
  +                     throws ServiceAccessException {
  +             Xid txId = (Xid) activeTransactionBranch.get();
  +             if (txId != null) {
  +                     try {
  +                             GenericLock lock = (GenericLock) lockManager
  +                                             .atomicGetOrCreateLock(uri);
  +                             if (lock.getLockLevel(txId) != 1) {
  +                                     Object owner = lock.getOwner();
  +                                     getLogger()
  +                                                     .log(
  +                                                                     "Try lock: "
  +                                                                                    
 + txId
  +                                                                                    
 + " tries "
  +                                                                                    
 + uri
  +                                                                                    
 + (owner != null ? " ---> "
  +                                                                                    
                 + owner.toString()
  +                                                                                    
                 + " has it" : ""),
  +                                                                     LOG_CHANNEL, 
Logger.DEBUG);
  +                                     if (!lock.acquire(txId, 1, true, true, 
timeout)) {
  +                                             throw new ServiceAccessException(this,
  +                                                             new 
ConflictException(uri));
  +                                     }
  +                                     ((HashSet) locks.get()).add(lock);
  +                                     getLogger().log("Has lock: " + txId + " locks 
" + uri,
  +                                                     LOG_CHANNEL, Logger.DEBUG);
  +                             }
  +                     } catch (InterruptedException e) {
  +                             throw new ServiceAccessException(this, new 
ConflictException(
  +                                             uri));
  +                     }
  +             }
  +     }
   
       //
  -    // overloaded content methods with caching 
  +    // overloaded content methods with caching
       //
   
       public NodeRevisionContent retrieveRevisionContent(Uri uri, 
NodeRevisionDescriptor revisionDescriptor)
  @@ -931,10 +943,16 @@
   
       // FIXME needs suspend and resume here as well!
       public void start(Xid xid, int flags) throws XAException {
  -        // XXX we do not suspend, so we do not resume
  +        System.out.println(
  +                "Thread "
  +                    + Thread.currentThread()
  +                    + (flags == TMNOFLAGS ? " starts" : flags == TMJOIN ? " joins" 
: " resumes")
  +                    + " work on behalf of transaction branch "
  +                    + xid);
  +        
  +        Xid txId = (Xid) XidWrapper.wrap(xid);
  +        activeTransactionBranch.set(txId);
           if (flags == TMNOFLAGS || flags == TMJOIN) {
  -            Xid txId = (Xid) XidWrapper.wrap(xid);
  -            activeTransactionBranch.set(txId);
   
               locks.set(new HashSet());
   
  @@ -945,10 +963,25 @@
               descriptorCache.getTxCache().start(txId);
               if (contentCache != null)
                   contentCache.getTxCache().start(txId);
  +        } else {
  +             locks.set(suspendedLocks.remove(txId));
           }
       }
   
       public void end(Xid xid, int flags) throws XAException {
  +        System.out.println(
  +                "Thread "
  +                    + Thread.currentThread()
  +                    + (flags == TMSUSPEND ? " suspends" : flags == TMFAIL ? " 
fails" : " ends")
  +                    + " work on behalf of transaction branch "
  +                    + xid);
  +
  +        if (flags == TMSUSPEND) {
  +            Xid txId = (Xid) XidWrapper.wrap(xid);
  +             suspendedLocks.put(txId, locks.get());
  +        }
  +        locks.set(null);
  +        activeTransactionBranch.set(null);
       }
   
       //
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to