Package org.apache.commons.transaction.locking

Examples of org.apache.commons.transaction.locking.GenericLock


        // no need to implement suspend and resume here as tlocks will not be used with external transactions
        if (locks.get() == null) return;

        Xid txId = (Xid) activeTransactionBranch.get();
        for (Iterator it = ((HashSet)locks.get()).iterator(); it.hasNext();) {
            GenericLock lock = (GenericLock) it.next();
            lock.release(txId);
            getLogger().log(
                "Release lock: " + txId + " released " + lock.getResourceId().toString(),
                LOG_CHANNEL,
                Logger.DEBUG);
        }
    }
View Full Code Here


    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,
View Full Code Here

     * @param setFactory factory for temporary sets
     */
    public PessimisticMapWrapper(Map wrapped, MapFactory mapFactory, SetFactory setFactory, LoggerFacade logger) {
        super(wrapped, mapFactory, setFactory);
        lockManager = new GenericLockManager(WRITE, logger);
        globalLock = new GenericLock(GLOBAL_LOCK_NAME, WRITE, logger);
    }
View Full Code Here

     */
    public void lock(Object ownerId, Object resourceId, int targetLockLevel, int compatibility,
                     boolean preferred, long timeoutMSecs, Object isolationId) throws LockException
    {
        timeoutCheck(ownerId);
        GenericLock lock = atomicGetOrCreateLock(resourceId, isolationId);
        super.doLock(lock, ownerId, resourceId, targetLockLevel, compatibility, preferred, timeoutMSecs);
    }
View Full Code Here

    {
        synchronized(globalLocks)
        {
            if(isolationId != null)
            {
                GenericLock lock = createIsolationLevel(resourceId, isolationId, logger);
                globalLocks.put(resourceId, lock);
                return lock;
            }
            else
            {
                GenericLock lock = new GenericLock(resourceId, maxLockLevel, logger);
                globalLocks.put(resourceId, lock);
                return lock;
            }
        }
    }
View Full Code Here

     */
    public void lock(Object ownerId, Object resourceId, int targetLockLevel, int compatibility,
                     boolean preferred, long timeoutMSecs, Object isolationId) throws LockException
    {
        timeoutCheck(ownerId);
        GenericLock lock = (GenericLock) atomicGetOrCreateLock(resourceId, isolationId);
        super.doLock(lock, ownerId, resourceId, targetLockLevel, compatibility, preferred, timeoutMSecs);
    }
View Full Code Here

    {
        synchronized(globalLocks)
        {
            if(isolationId != null)
            {
                GenericLock lock = createIsolationLevel(resourceId, isolationId, logger);
                globalLocks.put(resourceId, lock);
                return lock;
            }
            else
            {
                GenericLock lock = new GenericLock(resourceId, maxLockLevel, logger);
                globalLocks.put(resourceId, lock);
                return lock;
            }
        }
    }
View Full Code Here

            freeLocks();
        }

        public synchronized void upgradeLockToCommit() throws ResourceManagerException {
            for (Iterator it =  lockManager.getAll(txId).iterator(); it.hasNext();) {
                GenericLock lock = (GenericLock) it.next();
                // only upgrade if we had write access
                if (lock.getLockLevel(txId) == LOCK_EXCLUSIVE) {
                    try {
                        // in case of deadlocks, make failure of non-committing tx more likely
                        if (!lock
                            .acquire(
                                txId,
                                LOCK_COMMIT,
                                true,
                                true,
                                getDefaultTransactionTimeout() * DEFAULT_COMMIT_TIMEOUT_FACTOR)) {
                            throw new ResourceManagerException(
                                "Could not upgrade to commit lock for resource at '"
                                    + lock.getResourceId().toString()
                                    + "'",
                                ERR_NO_LOCK,
                                txId);
                        }
                    } catch (InterruptedException e) {
View Full Code Here

            buf.append(Long.toString(startTime)).append('\n');
            if (debug) {
                buf.append("----- Lock Debug Info -----\n");
               
                for (Iterator it = lockManager.getAll(txId).iterator(); it.hasNext();) {
                    GenericLock lock = (GenericLock) it.next();
                    buf.append(lock.toString()+"\n");
                }
               
            }
            return buf.toString();
        }
View Full Code Here

            freeLocks();
        }

        public synchronized void upgradeLockToCommit() throws ResourceManagerException {
            for (Iterator it =  lockManager.getAll(txId).iterator(); it.hasNext();) {
                GenericLock lock = (GenericLock) it.next();
                // only upgrade if we had write access
                if (lock.getLockLevel(txId) == LOCK_EXCLUSIVE) {
                    try {
                        // in case of deadlocks, make failure of non-committing tx more likely
                        if (!lock
                            .acquire(
                                txId,
                                LOCK_COMMIT,
                                true,
                                true,
                                getDefaultTransactionTimeout() * DEFAULT_COMMIT_TIMEOUT_FACTOR)) {
                            throw new ResourceManagerException(
                                "Could not upgrade to commit lock for resource at '"
                                    + lock.getResourceId().toString()
                                    + "'",
                                ERR_NO_LOCK,
                                txId);
                        }
                    } catch (InterruptedException e) {
View Full Code Here

TOP

Related Classes of org.apache.commons.transaction.locking.GenericLock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.