/* (non-Javadoc)
@see org.apache.lucene.store.Directory#makeLock(java.lang.String)
179642
public Lock makeLock(final String name) {
    return new Lock() {
      public boolean obtain() {
        return true;
      }

      public void release() {
      }

      public boolean isLocked() {
        throw new UnsupportedOperationException();
      }

      public String toString() {
        return "Lock@" + new Path(directory, name);
      }
    };
  }
759965
@Override
   public void forceUnlock(String lockName) {
      Cache<Object, Integer> lockCache = getDistLockCache().getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE, Flag.SKIP_CACHE_LOAD);
      FileCacheKey fileCacheKey = new FileCacheKey(indexName, lockName, affinitySegmentId);
      Object previousValue = lockCache.remove(fileCacheKey);
      if (previousValue!=null && trace) {
         log.tracef("Lock forcibly removed for index: %s", indexName);
      }
   }
933540
@Nonnull
    public String createLockName( @Nonnull final String sessionId ) {
        if ( sessionId == null ) {
            throw new IllegalArgumentException( "The sessionId must not be null." );
        }
        return "lock:" + _storageKeyFormat.format(sessionId);
    }
1020623
void lock(String serverId) {
        Assert.notNull(serverId);
        if (this.locked) {
            throw new IllegalStateException("Cannot lock already locked mutex: " + this);
        }
        this.locked = true;
        this.lockStart = new Date();
        this.lastUpdate = this.lockStart;
        this.serverId = serverId;
    }
652513
public LockedInodePath lockFullInodePath(long id, LockPattern lockPattern)
      throws FileDoesNotExistException {
    LockedInodePath inodePath = lockInodePathById(id, lockPattern);
    if (!inodePath.fullPathExists()) {
      inodePath.close();
      throw new FileDoesNotExistException(ExceptionMessage.INODE_DOES_NOT_EXIST.getMessage(id));
    }
    return inodePath;
  }
130105
@Override
    public synchronized Lock obtainReadLock() {
        File writeLock = getWriteLock();

        if (writeLock != null && writeLock.exists()) {
            return null;
        }

        return createLock(false);
    }
721180
public void setLockTimeout(int timeout, TimeUnit unit) {
        if (timeout < 0 || unit == null) {
            throw new IllegalArgumentException();
        }
        mLockTimeout = timeout;
        mLockTimeoutUnit = unit;
    }
1286009
public void checkLock(Session session, String path, List<String> tokens) throws LockException
   {
      String repoPath = session.getRepository().hashCode() + "/" + session.getWorkspace().getName() + "/" + path;

      String currentToken = nullResourceLocks.get(repoPath);

      if (currentToken == null)
      {
         return;
      }

      if (tokens != null)
      {
         for (String token : tokens)
         {
            if (token.equals(currentToken))
            {
               return;
            }
         }
      }

      throw new LockException("Resource already locked " + repoPath);
   }
19162
public void writeLock(EntityKey key, int timeout) {
		ReadWriteLock lock = getLock( key );
		Lock writeLock = lock.writeLock();
		acquireLock( key, timeout, writeLock );
	}
1134402
protected Lock tryLockForWrite(long time, TimeUnit unit) throws InterruptedException {
        if (time < 0 || unit == null) {
            return tryLockForWrite();
        }
        Lock lock = writeLock();
        return lock.tryLock(time, unit) ? lock : null;
    }
616903
public static function deEscalateReadLock(Zend_Search_Lucene_Storage_Directory $lockDirectory)
    {
        $lock = $lockDirectory->getFileObject(self::READ_LOCK_FILE);
        $lock->lock(LOCK_SH);
    }
520015
public void lock(String key, String request) throws InterruptedException {
        //get connection
        Object connection = getConnection();
        String result ;
        for (; ;) {
            if (connection instanceof Jedis){
                result = ((Jedis)connection).set(lockPrefix + key, request, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME, 10 * TIME);
                if (LOCK_MSG.equals(result)){
                    ((Jedis) connection).close();
                }
            }else {
                result = ((JedisCluster)connection).set(lockPrefix + key, request, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME, 10 * TIME);
            }

            if (LOCK_MSG.equals(result)) {
                break;
            }

            Thread.sleep(sleepTime);
        }

    }
795001
public void lock(boolean shouldLock) {
        String lastAlias = getLastAlias();

        if (shouldLock) {
            if (lastAlias != null) {
                criteria.setLockMode(lastAlias, LockMode.PESSIMISTIC_WRITE);
            }
            else {
                criteria.setLockMode(LockMode.PESSIMISTIC_WRITE);
            }
        }
        else {
            if (lastAlias != null) {
                criteria.setLockMode(lastAlias, LockMode.NONE);
            }
            else {
                criteria.setLockMode(LockMode.NONE);
            }
        }
    }
434856
public Lock getLock(String lockName, LockType type, String comment) {
		return new SQLLock(lockName,type,comment, getSleepTime(), this);
	}
43380
@Nonnull
  public ESuccess writeLockedAtomic (@Nonnull final IThrowingRunnable <IOException> aRunnable) throws IOException
  {
    m_aRWLock.writeLock ().lock ();
    try
    {
      if (isClosing ())
      {
        LOGGER.info ("Cannot executed something write locked, because Lucene is shutting down");
        return ESuccess.FAILURE;
      }
      aRunnable.run ();
    }
    finally
    {
      m_aRWLock.writeLock ().unlock ();
    }
    return ESuccess.SUCCESS;
  }
893451
public static LockRecord lockFile(File f)
	{
		LockRecord rec = new LockRecord();

		try
		{
			rec.fos = new FileOutputStream(f);

			rec.channel = rec.fos.getChannel();
			rec.flock = rec.channel.lock();
		}
		catch (IOException e)
		{
			log.error("[FileHelper] {lockFile} Error while locking " + f + ". Error: " + e.getMessage(), e);
			if (rec != null)
			{
				rec.release();
			}

			return null;
		}

		return rec;
	}
446232
@Override
    public synchronized void releaseWriteLock(final Lock lock) {
        if (lock == null || lock.name == null || lock.name.isEmpty()) {
            throw new InvalidArgument("lock is invalid");
        }

        locks.remove(lock.name);

        final File writeLock = getWriteLock();
        if (!writeLock.delete()) {
            throw new IllegalStateException(
                    "write lock could not be deleted");
        }
    }