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

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


        }
    }

    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


            return allocateNew(capacity, direct);
        }
    }

    private Object get(boolean direct, int index, Object key) {
        Lock lock = direct ? directLocks[index] : heapLocks[index];
        lock.lock();
        try {
            TreeMap pool = getPool(direct ? directPools[index]
                    : heapPools[index]);
            if (pool != null) {
                for (Iterator iter = pool.tailMap(key).values().iterator(); iter
                        .hasNext();) {
                    Entry first = (Entry) iter.next();
                    Entry next = first.next;
                    if (next != null) {
                        first.next = next.next;
                        next.next = null;
                        return next.obj;
                    } else {
                        iter.remove();
                        return first.obj;
                    }
                }
            }
        } finally {
            lock.unlock();
        }
        return null;
    }
View Full Code Here

        }

        protected void _release() {
            int index = indexFor(content.length);
            if (index >= 0) {
                Lock lock = heapLocks[index];
                Integer key = new Integer(content.length);
                Entry value = new Entry(content);

                lock.lock();
                try {
                    value.next = (Entry) createPool(heapPools, index).put(key,
                            value);
                } finally {
                    lock.unlock();
                }
            }
            content = null;
            super._release();
        }
View Full Code Here

        }

        protected void _release() {
            int index = indexFor(content.capacity());
            if (index >= 0) {
                Lock lock = directLocks[index];
                Integer key = new Integer(content.capacity());
                Entry value = new Entry(content);

                lock.lock();
                try {
                    value.next = (Entry) createPool(directPools, index).put(
                            key, value);
                } finally {
                    lock.unlock();
                }
            }
            content = null;
            super._release();
        }
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 synchronized Lock getLock(int key) {
        return this.getLock(String.valueOf(key));
    }

    public synchronized Lock getLock(String key) {
        Lock lock = (Lock)this.locks.get(key);
        if (lock == null) {
            lock = new ReentrantLock(true);
            this.locks.put(key, lock);
        }
        return lock;
View Full Code Here

                                     String coschedid)

                throws WorkspaceDatabaseException,
                       ResourceRequestDeniedException {

        final Lock lock = this.lockManager.getLock(coschedid);

        try {
            lock.lockInterruptibly();
        } catch (InterruptedException e) {
            throw new WorkspaceDatabaseException(
                        new LockAcquisitionFailure(e));
        }

        try {

            if (this.db.isCoschedDone(coschedid)) {
                throw new ResourceRequestDeniedException(
                        "co-scheduling group " + Lager.ensembleid(coschedid) +
                        "has already had a successful done operation " +
                        "invocation.  No additions may be made.");
            }

            this.db.addNodeRequest(req, coschedid);

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

        if (!this.valid) {
            throw new SchedulingException("scheduler was instantiated " +
                    "incorrectly"); // note for future IoC muckers
        }

        final Lock lock = lockManager.getLock(coschedid);

        try {
            lock.lockInterruptibly();
        } catch (InterruptedException e) {
            throw new SchedulingException(
                        new LockAcquisitionFailure(e));
        }

        try {
            this.proceedCoscheduleImpl(coschedid);
        } catch (WorkspaceDatabaseException e) {
            throw new SchedulingException(e.getMessage(), e);
        } finally {
            lock.unlock();
        }
    }
View Full Code Here

            throw new IllegalArgumentException("idStr may not be null");
        }

        final InstanceResource resource;

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

        try {

            final Element el = this.cache.get(idStr);
            if (el == null) {
                resource = this.newEmptyResource();
                this.cache.put(new Element(idStr, resource));
            } else {
                throw new CreationException(
                        "ID collision, ID '" + idStr + "' already in cache");
            }

        } finally {
            lock.unlock();
        }

        return resource;
    }
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.