Package net.sf.ehcache.concurrent

Examples of net.sf.ehcache.concurrent.Sync


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


            Element element = backingCache.get(key);

            if (element == null) {
                element = super.get(key);
            } else {
                Sync lock = getLockForKey(key);
                try {
                    lock.lock(LockType.WRITE);
                    update(key);
                } finally {
                    lock.unlock(LockType.WRITE);
                }
            }
            return element;
        } catch (final Throwable throwable) {
            // Could not fetch - Ditch the entry from the cache and rethrow
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public boolean containsKey(Object key) {
        Sync s = sync.getSyncForKey(key);
        s.lock(LockType.READ);
        try {
            if (key instanceof Serializable && (disk !=  null)) {
                return disk.containsKey(key) || memory.containsKey(key);
            } else {
                return memory.containsKey(key);
            }
        } finally {
            s.unlock(LockType.READ);
        }
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public boolean containsKeyInMemory(Object key) {
        Sync s = sync.getSyncForKey(key);
        s.lock(LockType.READ);
        try {
            return memory.containsKey(key);
        } finally {
            s.unlock(LockType.READ);
        }
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public boolean containsKeyOnDisk(Object key) {
        Sync s = sync.getSyncForKey(key);
        s.lock(LockType.READ);
        try {
            if (disk != null) {
                return disk.containsKey(key);
            } else {
                return false;
            }
        } finally {
            s.unlock(LockType.READ);
        }
    }
View Full Code Here

     * {@inheritDoc}
     */
    public void expireElements() {
    
        for (Object key : memory.getKeys()) {
            Sync s = sync.getSyncForKey(key);
            s.lock(LockType.WRITE);
            try {
                Element element = memory.getQuiet(key);
                if (element != null) {
                    if (element.isExpired(config)) {
                        Element e = remove(key);
                        if (e != null) {
                            eventListeners.notifyElementExpiry(e, false);
                        }
                    }
                }
            } finally {
                s.unlock(LockType.WRITE);
            }
        }

        //This is called regularly by the expiry thread, but call it here synchronously
        if (disk != null) {
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public Element get(Object key) {
        Sync s = sync.getSyncForKey(key);
        s.lock(LockType.READ);
        try {
            Element e = memory.get(key);
            if (e == null && disk != null) {
                e = disk.get(key);
                if (e != null) {
                    memory.put(e);
                }
            }
            return e;
        } finally {
            s.unlock(LockType.READ);
        }
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public Element getQuiet(Object key) {
        Sync s = sync.getSyncForKey(key);
        s.lock(LockType.READ);
        try {
            Element e = memory.getQuiet(key);
            if (e == null && disk != null) {
                e = disk.getQuiet(key);
                if (e != null) {
                    memory.put(e);
                }
            }
            return e;
        } finally {
            s.unlock(LockType.READ);
        }
    }
View Full Code Here

    public boolean put(Element element) throws CacheException {
        if (element == null) {
            return false;
        }
       
        Sync s = sync.getSyncForKey(element.getObjectKey());
        s.lock(LockType.WRITE);
        try {
            boolean notOnDisk = !containsKeyOnDisk(element.getObjectKey());
            return memory.put(element) && notOnDisk;
        } finally {
            s.unlock(LockType.WRITE);
        }
    }
View Full Code Here

    public boolean putWithWriter(Element element, CacheWriterManager writerManager) throws CacheException {
        if (element == null) {
            return false;
        }
       
        Sync s = sync.getSyncForKey(element.getObjectKey());
        s.lock(LockType.WRITE);
        try {
            boolean notOnDisk = !containsKey(element.getObjectKey());
            return memory.putWithWriter(element, writerManager) && notOnDisk;
        } finally {
            s.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.