Package net.sf.ehcache.concurrent

Examples of net.sf.ehcache.concurrent.Sync


        }
        return element;
    }

    private void tryRemoveImmediately(final Object key, final boolean notifyListeners) {
        Sync syncForKey = ((CacheLockProvider)getInternalContext()).getSyncForKey(key);
        boolean writeLocked = false;
        try {
            writeLocked = syncForKey.tryLock(LockType.WRITE, 0);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } catch (Error e) {
            if (!(e.getClass().getName().equals("com.tc.exception.TCLockUpgradeNotSupportedError"))) {
               throw e;
            }
        }
        if (writeLocked) {
            try {
                removeInternal(key, true, notifyListeners, false, false);
            } finally {
                syncForKey.unlock(LockType.WRITE);
            }
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug(configuration.getName() + " cache: element " + key + " expired, but couldn't be inline evicted");
            }
View Full Code Here


    protected Sync getLockForKey(final Object key) {
        return lockProvider.getSyncForKey(key);
    }

    private void acquireLockOnKey(Object key, LockType lockType) {
        Sync s = getLockForKey(key);
        s.lock(lockType);
    }
View Full Code Here

        Sync s = getLockForKey(key);
        s.lock(lockType);
    }

    private void releaseLockOnKey(Object key, LockType lockType) {
        Sync s = getLockForKey(key);
        s.unlock(lockType);
    }
View Full Code Here

     * @param timeout - millis until giveup on getting the lock
     * @return whether the lock was awarded
     * @throws InterruptedException
     */
    public boolean tryReadLockOnKey(Object key, long timeout) throws InterruptedException {
        Sync s = getLockForKey(key);
        return s.tryLock(LockType.READ, timeout);
    }
View Full Code Here

     * @param timeout - millis until giveup on getting the lock
     * @return whether the lock was awarded
     * @throws InterruptedException
     */
    public boolean tryWriteLockOnKey(Object key, long timeout) throws InterruptedException {
        Sync s = getLockForKey(key);
        return s.tryLock(LockType.WRITE, timeout);
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public Element remove(Object key) {
        Sync s = sync.getSyncForKey(key);
        s.lock(LockType.WRITE);
        try {
            Element m = memory.remove(key);
            if (disk != null && key instanceof Serializable) {
                Element d = disk.remove(key);
                if (m == null) {
                    return d;
                }
            }
            return m;
        } finally {
            s.unlock(LockType.WRITE);
        }
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public Element removeWithWriter(Object key, CacheWriterManager writerManager) throws CacheException {
        Sync s = sync.getSyncForKey(key);
        s.lock(LockType.WRITE);
        try {
            Element m = memory.removeWithWriter(key, writerManager);
            if (disk != null && key instanceof Serializable) {
                Element d = disk.removeWithWriter(key, writerManager);
                if (m == null) {
                    return d;
                }
            }
            return m;
        } finally {
            s.unlock(LockType.WRITE);
        }
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public Element putIfAbsent(Element element) throws NullPointerException {
        Sync lock = sync.getSyncForKey(element.getObjectKey());
       
        lock.lock(LockType.WRITE);
        try {
            Element e = getQuiet(element.getObjectKey());
            if (e == null) {
                put(element);
            }
            return e;
        } finally {
            lock.unlock(LockType.WRITE);
        }
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public Element removeElement(Element element, ElementValueComparator comparator) throws NullPointerException {
        Sync lock = sync.getSyncForKey(element.getObjectKey());
       
        lock.lock(LockType.WRITE);
        try {
            Element current = getQuiet(element.getObjectKey());
            if (comparator.equals(element, current)) {
                return remove(current.getObjectKey());
            } else {
                return null;
            }
        } finally {
            lock.unlock(LockType.WRITE);
        }
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public boolean replace(Element old, Element element, ElementValueComparator comparator)
            throws NullPointerException, IllegalArgumentException {
        Sync lock = sync.getSyncForKey(old.getObjectKey());
       
        lock.lock(LockType.WRITE);
        try {
            Element current = getQuiet(old.getObjectKey());
            if (comparator.equals(old, current)) {
                put(element);
                return true;
            } else {
                return false;
            }
        } finally {
            lock.unlock(LockType.WRITE);
        }
    }
View Full Code Here

TOP

Related Classes of net.sf.ehcache.concurrent.Sync

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.