protected void acquireLock( @Nonnull final String sessionId, final long retryInterval, final long maxRetryInterval, final long timeout, final long start ) throws InterruptedException, ExecutionException, TimeoutException { final Future<Boolean> result = _storage.add( _sessionIdFormat.createLockName( sessionId ), _manager.getLockExpiration(), LOCK_VALUE ); if ( result.get().booleanValue() ) { if ( _log.isDebugEnabled() ) { _log.debug( "Locked session " + sessionId ); } return; } else { checkTimeoutAndWait( sessionId, retryInterval, timeout, start ); acquireLock( sessionId, min( retryInterval * 2, maxRetryInterval ), maxRetryInterval, timeout, start ); } }
protected LockStatus lock( final String sessionId, final long timeout, final TimeUnit timeUnit ) { if ( _log.isDebugEnabled() ) { _log.debug( "Locking session " + sessionId ); } final long start = System.currentTimeMillis(); try { acquireLock( sessionId, LOCK_RETRY_INTERVAL, LOCK_MAX_RETRY_INTERVAL, timeUnit.toMillis( timeout ), System.currentTimeMillis() ); _stats.registerSince( ACQUIRE_LOCK, start ); if ( _log.isDebugEnabled() ) { _log.debug( "Locked session " + sessionId ); } return LockStatus.LOCKED; } catch ( final TimeoutException e ) { _log.warn( "Reached timeout when trying to aquire lock for session " + sessionId + ". Will use this session without this lock." ); _stats.registerSince( ACQUIRE_LOCK_FAILURE, start ); return LockStatus.COULD_NOT_AQUIRE_LOCK; } catch ( final InterruptedException e ) { Thread.currentThread().interrupt(); throw new RuntimeException( "Got interrupted while trying to lock session.", e ); } catch ( final ExecutionException e ) { _log.warn( "An exception occurred when trying to aquire lock for session " + sessionId ); _stats.registerSince( ACQUIRE_LOCK_FAILURE, start ); return LockStatus.COULD_NOT_AQUIRE_LOCK; } }
protected void acquireLock( @Nonnull final String sessionId, final long retryInterval, final long maxRetryInterval, final long timeout, final long start ) throws InterruptedException, ExecutionException, TimeoutException { final Future<Boolean> result = _storage.add( _sessionIdFormat.createLockName( sessionId ), _manager.getLockExpiration(), LOCK_VALUE ); if ( result.get().booleanValue() ) { if ( _log.isDebugEnabled() ) { _log.debug( "Locked session " + sessionId ); } return; } else { checkTimeoutAndWait( sessionId, retryInterval, timeout, start ); acquireLock( sessionId, min( retryInterval * 2, maxRetryInterval ), maxRetryInterval, timeout, start ); } }
protected LockStatus lock( final String sessionId, final long timeout, final TimeUnit timeUnit ) { if ( _log.isDebugEnabled() ) { _log.debug( "Locking session " + sessionId ); } final long start = System.currentTimeMillis(); try { acquireLock( sessionId, LOCK_RETRY_INTERVAL, LOCK_MAX_RETRY_INTERVAL, timeUnit.toMillis( timeout ), System.currentTimeMillis() ); _stats.registerSince( ACQUIRE_LOCK, start ); if ( _log.isDebugEnabled() ) { _log.debug( "Locked session " + sessionId ); } return LockStatus.LOCKED; } catch ( final TimeoutException e ) { _log.warn( "Reached timeout when trying to aquire lock for session " + sessionId + ". Will use this session without this lock." ); _stats.registerSince( ACQUIRE_LOCK_FAILURE, start ); return LockStatus.COULD_NOT_AQUIRE_LOCK; } catch ( final InterruptedException e ) { Thread.currentThread().interrupt(); throw new RuntimeException( "Got interrupted while trying to lock session.", e ); } catch ( final ExecutionException e ) { _log.warn( "An exception occurred when trying to aquire lock for session " + sessionId ); _stats.registerSince( ACQUIRE_LOCK_FAILURE, start ); return LockStatus.COULD_NOT_AQUIRE_LOCK; } }