Package edu.emory.mathcs.backport.java.util.concurrent.locks

Examples of edu.emory.mathcs.backport.java.util.concurrent.locks.Lock


            throw new ManageException("groupid may not be null");
        }

        final GroupResource resource;

        final Lock lock = this.lockManager.getLock(groupid);
        try {
            lock.lockInterruptibly();
        } catch (InterruptedException e) {
            throw new ManageException(e.getMessage(), e);
        }

        try {

            final Element el = this.cache.get(groupid);
            if (el == null) {
                resource = this.newEmptyResource();
                // throws DoesNotExistException if not in db
                this.persistence.loadGroup(groupid, resource);

            } else {
                resource = (GroupResource) el.getObjectValue();
            }

        } finally {
            lock.unlock();
        }

        return resource;
    }
View Full Code Here


       
        if (groupid == null) {
            throw new ManageException("groupid may not be null");
        }

        final Lock lock = this.lockManager.getLock(groupid);
        try {
            lock.lockInterruptibly();
        } catch (InterruptedException e) {
            throw new ManageException(e.getMessage(), e);
        }

        try {
            final GroupResource resource = this.find(groupid);
            resource.remove();
            this.cache.remove(groupid);

        } finally {
            lock.unlock();
        }
    }
View Full Code Here

            AuthorizationException {

        String creatorID = caller.getIdentity();
        final String clientToken = req.getClientToken();
        IdempotentReservation res;
        final Lock idemLock = idemManager.getLock(creatorID, clientToken);

        try {
            idemLock.lockInterruptibly();
        } catch (InterruptedException e) {
            throw new CreationException(e.getMessage(), e);
        }

        try {

            res = this.idemManager.getReservation(creatorID, clientToken);
            if (res != null) {

                if (logger.isDebugEnabled()) {
                    logger.debug("Found existing idempotent reservation: " +
                            res.toString());
                }

                // the reservation already exists. check its validity
                return resolveIdempotentReservation(res, req);

            } else {

                final InstanceResource[] resources =
                        this.doCreation(req, caller, bound);

                this.idemManager.addReservation(creatorID, clientToken,
                        Arrays.asList(resources));
                return resources;
            }

        } catch (ManageException e) {
            throw new CreationException(e.getMessage(), e);
        } finally {
            idemLock.unlock();
        }
    }
View Full Code Here

        if (logger.isDebugEnabled()) {
            logger.debug("Scheduling file " + file + " for processing");
        }
        getExecutor().execute(new Runnable() {
            public void run() {
                final Lock lock = lockManager.getLock(file);
                if (lock.tryLock()) {
                    boolean unlock = true;
                    try {
                        unlock = processFileAndDelete(file);
                    }
                    finally {
                        if (unlock) {
                            lock.unlock();
                        }
                    }
                }
            }
        });
View Full Code Here

                final String correlationId = getCorrelationID(exchange, in);
                if (correlationId == null || correlationId.length() == 0) {
                    throw new IllegalArgumentException("Could not retrieve correlation id for incoming exchange");
                }
                // Load existing aggregation
                Lock lock = getLockManager().getLock(correlationId);
                lock.lock();
                try {
                    Object aggregation = store.load(correlationId);
                    Date timeout = null;
                    // Create a new aggregate
                    if (aggregation == null) {
                        if (isAggregationClosed(correlationId)) {
                            // TODO: should we return an error here ?
                        } else {
                            aggregation = createAggregation(correlationId);
                            timeout = getTimeout(aggregation);
                        }
                    } else if (isRescheduleTimeouts()) {
                        timeout = getTimeout(aggregation);
                    }
                    // If the aggregation is not closed
                    if (aggregation != null) {
                        if (addMessage(aggregation, in, exchange)) {
                            sendAggregate(correlationId, aggregation, false);
                        } else {
                            store.store(correlationId, aggregation);
                            if (timeout != null) {
                                if (log.isDebugEnabled()) {
                                    log.debug("Scheduling timeout at " + timeout + " for aggregate " + correlationId);
                                }
                                getTimerManager().schedule(new TimerListener() {
                                    public void timerExpired(Timer timer) {
                                        AbstractAggregator.this.onTimeout(correlationId);
                                    }
                                }, timeout);
                            }
                        }
                    }
                    done(exchange);
                } finally {
                    lock.unlock();
                }
            }
        // Handle an ACTIVE exchange as a CONSUMER
        } else if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
            done(exchange);
View Full Code Here

    protected void onTimeout(String correlationId) {
        if (log.isDebugEnabled()) {
            log.debug("Timeout expired for aggregate " + correlationId);
        }
        Lock lock = getLockManager().getLock(correlationId);
        lock.lock();
        try {
            Object aggregation = store.load(correlationId);
            if (aggregation != null) {
                sendAggregate(correlationId, aggregation, true);
            } else if (!isAggregationClosed(correlationId)) {
                throw new IllegalStateException("Aggregation is not closed, but can not be retrieved from the store");
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Aggregate " + correlationId + " is closed");
                }
            }
        } catch (Exception e) {
            log.info("Caught exception while processing timeout aggregation", e);
        } finally {
            lock.unlock();
        }
    }
View Full Code Here

public class SimpleLockManager implements LockManager {

    private ConcurrentMap locks = new ConcurrentHashMap();
   
    public Lock getLock(String id) {
        Lock lock = (Lock) locks.get(id);
        if (lock == null) {
            lock = new ReentrantLock();
            Lock oldLock = (Lock) locks.putIfAbsent(id, lock);
            if (oldLock != null) {
                lock = oldLock;
            }
        }
        return lock;
View Full Code Here

            logger.debug("Scheduling file " + aFile + " for processing");
        }
        getExecutor().execute(new Runnable() {
            public void run() {
                String uri = file.toURI().relativize(aFile.toURI()).toString();
                Lock lock = lockManager.getLock(uri);
                if (lock.tryLock()) {
                    boolean unlock = true;
                    try {
                        unlock = processFileAndDelete(aFile);
                    }
                    finally {
                        if (unlock) {
                            lock.unlock();
                        }
                    }
                } else {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Unable to acquire lock on " + aFile);
View Full Code Here

        }
    }

    public ConstraintInfo[] get_constraints(int[] ids) throws ConstraintNotFound
    {
        final Lock _lock = constraintsLock_.readLock();

        _lock.lock();
        try
        {
            final ConstraintInfo[] _constraintInfo = new ConstraintInfo[ids.length];

            for (int _x = 0; _x < ids.length; ++_x)
            {
                Integer _key = new Integer(ids[_x]);

                if (constraints_.containsKey(_key))
                {
                    _constraintInfo[_x] = ((ConstraintEntry) constraints_.get(_key))
                            .getConstraintInfo();
                }
                else
                {
                    throw new ConstraintNotFound(ids[_x]);
                }
            }

            return _constraintInfo;
        } finally
        {
            _lock.unlock();
        }
    }
View Full Code Here

        }
    }

    public ConstraintInfo[] get_constraints(int[] ids) throws ConstraintNotFound
    {
        final Lock _lock = constraintsLock_.readLock();

        _lock.lock();
        try
        {
            final ConstraintInfo[] _constraintInfo = new ConstraintInfo[ids.length];

            for (int _x = 0; _x < ids.length; ++_x)
            {
                Integer _key = new Integer(ids[_x]);

                if (constraints_.containsKey(_key))
                {
                    _constraintInfo[_x] = ((ConstraintEntry) constraints_.get(_key))
                            .getConstraintInfo();
                }
                else
                {
                    throw new ConstraintNotFound(ids[_x]);
                }
            }

            return _constraintInfo;
        } finally
        {
            _lock.unlock();
        }
    }
View Full Code Here

TOP

Related Classes of edu.emory.mathcs.backport.java.util.concurrent.locks.Lock

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.