private void decrementLock(Object key, Lock lock) { lock.unlock(cache.nextTimestamp()); cache.update(key, lock); }
private void handleLockExpiry(Object key) { long ts = cache.nextTimestamp() + cache.getTimeout(); // create new lock that times out immediately Lock lock = new Lock(ts, uuid, nextLockId.getAndIncrement(), null); lock.unlock(ts); cache.update(key, lock); }
/** * {@inheritDoc} */ public boolean afterInsert(Object key, Object value, Object version) throws CacheException { writeLock(key); try { Lockable item = (Lockable) cache.get(key); if (item == null) { cache.update(key, new Item(value, version, cache.nextTimestamp())); return true; } else { return false; } } finally { writeUnlock(key); } }
/** * {@inheritDoc} */ public boolean put(Object key, Object value, long txTimestamp, Object version, Comparator versionComparator, boolean minimalPut) throws CacheException { writeLock(key); try { Lockable item = (Lockable) cache.get(key); boolean writeable = item == null || item.isWriteable(txTimestamp, version, versionComparator); if (writeable) { cache.put(key, new Item(value, version, cache.nextTimestamp())); return true; } else { return false; } } finally { writeUnlock(key); } }
/** * Soft-locks the associated mapping prior to updating/inserting a new value. */ public SoftLock lock(Object key, Object version) throws CacheException { writeLock(key); try { Lockable item = (Lockable) cache.get(key); long timeout = cache.nextTimestamp() + cache.getTimeout(); final Lock lock = (item == null) ? new Lock(timeout, uuid, nextLockId(), version) : item.lock(timeout, uuid, nextLockId()); cache.update(key, lock); return lock; } finally { writeUnlock(key); } }
/** * {@inheritDoc} */ public boolean afterUpdate(Object key, Object value, Object version, SoftLock softlock) throws CacheException { writeLock(key); try { Lockable item = (Lockable) cache.get(key); if (item != null && item.isUnlockable(softlock)) { Lock lock = (Lock) item; if (lock.wasLockedConcurrently()) { decrementLock(key, lock); return false; } else { cache.update(key, new Item(value, version, cache.nextTimestamp())); return true; } } else { handleLockExpiry(key); return false; } } finally { writeUnlock(key); } }
private void decrementLock(Object key, Lock lock) { lock.unlock(cache.nextTimestamp()); cache.update(key, lock); }
private void decrementLock(Object key, Lock lock) { lock.unlock(cache.nextTimestamp()); cache.update(key, lock); }
private void decrementLock(Object key, Lock lock) { lock.unlock(cache.nextTimestamp()); cache.update(key, lock); }
private void handleLockExpiry(Object key) { long ts = cache.nextTimestamp() + cache.getTimeout(); // create new lock that times out immediately Lock lock = new Lock(ts, uuid, nextLockId.getAndIncrement(), null); lock.unlock(ts); cache.update(key, lock); }
private void handleLockExpiry(Object key) { long ts = cache.nextTimestamp() + cache.getTimeout(); // create new lock that times out immediately Lock lock = new Lock(ts, uuid, nextLockId.getAndIncrement(), null); lock.unlock(ts); cache.update(key, lock); }
private void handleLockExpiry(Object key) { long ts = cache.nextTimestamp() + cache.getTimeout(); // create new lock that times out immediately Lock lock = new Lock(ts, uuid, nextLockId.getAndIncrement(), null); lock.unlock(ts); cache.update(key, lock); }
/** * {@inheritDoc} */ public boolean afterInsert(Object key, Object value, Object version) throws CacheException { writeLock(key); try { Lockable item = (Lockable) cache.get(key); if (item == null) { cache.update(key, new Item(value, version, cache.nextTimestamp())); return true; } else { return false; } } finally { writeUnlock(key); } }
/** * {@inheritDoc} */ public boolean afterInsert(Object key, Object value, Object version) throws CacheException { writeLock(key); try { Lockable item = (Lockable) cache.get(key); if (item == null) { cache.update(key, new Item(value, version, cache.nextTimestamp())); return true; } else { return false; } } finally { writeUnlock(key); } }
/** * {@inheritDoc} */ public boolean afterInsert(Object key, Object value, Object version) throws CacheException { writeLock(key); try { Lockable item = (Lockable) cache.get(key); if (item == null) { cache.update(key, new Item(value, version, cache.nextTimestamp())); return true; } else { return false; } } finally { writeUnlock(key); } }
/** * {@inheritDoc} */ public boolean put(Object key, Object value, long txTimestamp, Object version, Comparator versionComparator, boolean minimalPut) throws CacheException { writeLock(key); try { Lockable item = (Lockable) cache.get(key); boolean writeable = item == null || item.isWriteable(txTimestamp, version, versionComparator); if (writeable) { cache.put(key, new Item(value, version, cache.nextTimestamp())); return true; } else { return false; } } finally { writeUnlock(key); } }
/** * Soft-locks the associated mapping prior to updating/inserting a new value. */ public SoftLock lock(Object key, Object version) throws CacheException { writeLock(key); try { Lockable item = (Lockable) cache.get(key); long timeout = cache.nextTimestamp() + cache.getTimeout(); final Lock lock = (item == null) ? new Lock(timeout, uuid, nextLockId(), version) : item.lock(timeout, uuid, nextLockId()); cache.update(key, lock); return lock; } finally { writeUnlock(key); } }
/** * {@inheritDoc} */ public boolean afterUpdate(Object key, Object value, Object version, SoftLock softlock) throws CacheException { writeLock(key); try { Lockable item = (Lockable) cache.get(key); if (item != null && item.isUnlockable(softlock)) { Lock lock = (Lock) item; if (lock.wasLockedConcurrently()) { decrementLock(key, lock); return false; } else { cache.update(key, new Item(value, version, cache.nextTimestamp())); return true; } } else { handleLockExpiry(key); return false; } } finally { writeUnlock(key); } }
/** * Soft-locks the associated mapping prior to updating/inserting a new value. */ public SoftLock lock(Object key, Object version) throws CacheException { writeLock(key); try { Lockable item = (Lockable) cache.get(key); long timeout = cache.nextTimestamp() + cache.getTimeout(); final Lock lock = (item == null) ? new Lock(timeout, uuid, nextLockId(), version) : item.lock(timeout, uuid, nextLockId()); cache.update(key, lock); return lock; } finally { writeUnlock(key); } }
/** * Soft-locks the associated mapping prior to updating/inserting a new value. */ public SoftLock lock(Object key, Object version) throws CacheException { writeLock(key); try { Lockable item = (Lockable) cache.get(key); long timeout = cache.nextTimestamp() + cache.getTimeout(); final Lock lock = (item == null) ? new Lock(timeout, uuid, nextLockId(), version) : item.lock(timeout, uuid, nextLockId()); cache.update(key, lock); return lock; } finally { writeUnlock(key); } }