List of usage examples for org.springframework.dao CannotAcquireLockException CannotAcquireLockException
public CannotAcquireLockException(String msg)
From source file:org.grails.datastore.mapping.jcr.JcrSession.java
@Override public void lock(Object o) { LockableEntityPersister ep = (LockableEntityPersister) getPersister(o); if (ep == null) { throw new CannotAcquireLockException( "Cannot lock object [" + o + "]. It is not a persistent instance!"); }/* w ww.ja va 2s . c o m*/ Serializable id = ep.getObjectIdentifier(o); if (id == null) { throw new CannotAcquireLockException("Cannot lock transient instance [" + o + "]"); } ep.lock(id); }
From source file:org.grails.datastore.mapping.jcr.JcrSession.java
@Override public Object lock(Class type, Serializable key) { LockableEntityPersister ep = (LockableEntityPersister) getPersister(type); if (ep == null) { throw new CannotAcquireLockException("Cannot lock key [" + key + "]. It is not a persistent instance!"); }//from w w w . j a v a 2 s . co m final Object lockedObject = ep.lock(key); if (lockedObject != null) { cacheObject(key, lockedObject); lockedObjects.add(lockedObject); } return lockedObject; }
From source file:org.grails.datastore.mapping.redis.engine.RedisEntityPersister.java
@Override protected void lockEntry(PersistentEntity persistentEntity, @SuppressWarnings("hiding") String entityFamily, Serializable id, int timeout) { String redisKey = getRedisKey(entityFamily, id); final TimeUnit milliUnit = TimeUnit.MILLISECONDS; final long waitTime = TimeUnit.SECONDS.toMillis(timeout); final String lockName = lockName(redisKey); int sleepTime = 0; while (true) { if (redisTemplate.setnx(lockName, System.currentTimeMillis()) && redisTemplate.expire(lockName, timeout)) { break; }//from www .j a v a2 s . c o m if (redisTemplate.ttl(lockName) > 0) { try { if (sleepTime > waitTime) { throw new CannotAcquireLockException( "Failed to acquire lock on key [" + redisKey + "]. Wait time exceeded timeout."); } // wait for previous lock to expire sleepTime += 500; milliUnit.sleep(500); } catch (InterruptedException e) { throw new CannotAcquireLockException( "Failed to acquire lock on key [" + redisKey + "]: " + e.getMessage(), e); } } else { if (redisTemplate.getset(lockName, System.currentTimeMillis()) != null && redisTemplate.expire(lockName, timeout)) { break; } } } }
From source file:org.grails.datastore.mapping.gemfire.engine.GemfireEntityPersister.java
@Override public Object lock(final Serializable id, final int timeout) throws CannotAcquireLockException { final GemfireTemplate template = gemfireDatastore.getTemplate(getPersistentEntity()); return template.execute(new GemfireCallback() { public Object doInGemfire(Region region) throws GemFireCheckedException, GemFireException { final Lock lock = region.getDistributedLock(id); try { if (lock.tryLock(timeout, TimeUnit.SECONDS)) { final Object o = region.get(id); distributedLocksHeld.put(o, lock); return o; }// www . j ava 2 s . com throw new CannotAcquireLockException("Timeout acquiring Gemfire lock on object type [" + getPersistentEntity() + "] with identifier [" + id + "]"); } catch (InterruptedException e) { throw new CannotAcquireLockException("Cannot acquire Gemfire lock on object type [" + getPersistentEntity() + "] with identifier [" + id + "]: " + e.getMessage(), e); } } }); }
From source file:at.ac.univie.isc.asio.platform.FileSystemConfigStore.java
private void lock() { try {/*from www . j a v a 2s . c om*/ if (!lock.tryLock(timeout.getAs(TimeUnit.MILLISECONDS, 0L), TimeUnit.MILLISECONDS)) { throw new CannotAcquireLockException("failed to acquire store lock in " + timeout); } } catch (InterruptedException e) { throw new CannotAcquireLockException("interrupted while acquiring config store lock", e); } }
From source file:com.turbospaces.core.SpaceUtility.java
/** * raise new {@link CannotAcquireLockException} exception for given identifier and timeout. ALso you need to pass * write or exclusive read type as last method parameter in order to format proper error message. * /* w w w . ja v a2 s . c o m*/ * @param uniqueIdentifier * primary key * @param timeout * lock acquire timeout * @param write * exclusive write or exclusive read lock * @see SpaceErrors#UNABLE_TO_ACQUIRE_LOCK */ public static void raiseCannotAcquireLockException(final Object uniqueIdentifier, final long timeout, final boolean write) { String type = write ? "write" : "exclusive read"; throw new CannotAcquireLockException( String.format(SpaceErrors.UNABLE_TO_ACQUIRE_LOCK, type, uniqueIdentifier, timeout)); }
From source file:org.springframework.integration.cluster.redis.DistributedLockHandler.java
public void acquireLock(String key, String owner) { int n = 0;/* w ww.j ava 2 s . co m*/ while (this.lockTemplate.opsForValue().setIfAbsent(key + ".lock", getLockValue(owner)) == false) { if (++n > this.timeout / 100) { throw new CannotAcquireLockException("Failed to procure cluster lock for application " + key); } try { Thread.sleep(100); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new DataRetrievalFailureException("Interrupted while procuring lock", e); } } this.acquiredThreadLocal.set(new Date()); if (logger.isDebugEnabled()) { logger.debug("Lock acquiredThreadLocal for " + key + " by " + owner); } this.lockTemplate.opsForValue().getOperations().expire(key + ".lock", timeout * 2, TimeUnit.MILLISECONDS); }