Package net.sf.ehcache.concurrent

Examples of net.sf.ehcache.concurrent.Sync.lock()


        return lockProvider.getSyncForKey(key);
    }

    private void acquireLockOnKey(Object key, LockType lockType) {
        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


        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

    /**
     * {@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) {
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) {
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);
            }
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 {
View Full Code Here

     */
    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;
View Full Code Here

     * {@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);
            }
View Full Code Here

            if (element == null) {
                element = super.get(key);
            } else {
                Sync lock = getLockForKey(key);
                try {
                    lock.lock(LockType.WRITE);
                    update(key);
                } finally {
                    lock.unlock(LockType.WRITE);
                }
            }
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);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.