/* (non-Javadoc)
@see com.aldous.locking.LockFactory#getLock(java.lang.String, com.aldous.locking.LockFactory.LockType)
168389
public Lock getLock(String lockName, LockType type, String comment) {
		Lock lock = new SimpleLock(lockName,type,comment, getSleepTime(), this);
		return lock;
	}
1078294
protected CmsLockInfo getLock(CmsUUID structureId) throws CmsException {

        CmsResource res = getCmsObject().readResource(structureId, CmsResourceFilter.IGNORE_EXPIRATION);
        return getLock(getCmsObject().getSitePath(res));
    }
846574
public final FileLock lock(final int tryLockMax, final long tryWaitMillis) throws LockingFailedException {

        return Utils4J.lockRandomAccessFile(file, tryLockMax, tryWaitMillis);

    }
328158
private File getWriteLock() {
        File[] lckFiles = this.lockPath.listFiles(lockFilter);
        for (final File lckFile : lckFiles) {
            if (lockFilter.isWriterLockFile(lckFile)) {
                return lckFile;
            }
        }

        return null;
    }
344634
public IEntityLock find(IEntityLock lock) throws LockingException {
        IEntityLock foundLock = null;
        Map m = getLockCache(lock.getEntityType());
        foundLock = getLockFromCache(getCacheKey(lock), m);

        if (foundLock != null) {
            if (lock.getLockType() != foundLock.getLockType()
                    || !lock.getExpirationTime().equals(foundLock.getExpirationTime())) {
                foundLock = null;
            }
        }

        return foundLock;
    }
751563
private boolean getLockInformation( final ITransaction transaction, final WebdavRequest req, final WebdavResponse resp )
        throws WebdavException, IOException
    {

        Node lockInfoNode = null;
        DocumentBuilder documentBuilder = null;

        documentBuilder = getDocumentBuilder();
        try
        {
            final Document document = documentBuilder.parse( new InputSource( req.getInputStream() ) );

            // Get the root element of the document
            final Element rootElement = document.getDocumentElement();

            lockInfoNode = rootElement;

            if ( lockInfoNode != null )
            {
                NodeList childList = lockInfoNode.getChildNodes();
                Node lockScopeNode = null;
                Node lockTypeNode = null;
                Node lockOwnerNode = null;

                Node currentNode = null;
                String nodeName = null;

                for ( int i = 0; i < childList.getLength(); i++ )
                {
                    currentNode = childList.item( i );

                    if ( currentNode.getNodeType() == Node.ELEMENT_NODE || currentNode.getNodeType() == Node.TEXT_NODE )
                    {

                        nodeName = currentNode.getNodeName();

                        if ( nodeName.endsWith( "locktype" ) )
                        {
                            lockTypeNode = currentNode;
                        }
                        if ( nodeName.endsWith( "lockscope" ) )
                        {
                            lockScopeNode = currentNode;
                        }
                        if ( nodeName.endsWith( "owner" ) )
                        {
                            lockOwnerNode = currentNode;
                        }
                    }
                    else
                    {
                        return false;
                    }
                }

                if ( lockScopeNode != null )
                {
                    String scope = null;
                    childList = lockScopeNode.getChildNodes();
                    for ( int i = 0; i < childList.getLength(); i++ )
                    {
                        currentNode = childList.item( i );

                        if ( currentNode.getNodeType() == Node.ELEMENT_NODE )
                        {
                            scope = currentNode.getNodeName();

                            if ( scope.endsWith( "exclusive" ) )
                            {
                                _exclusive = true;
                            }
                            else if ( scope.equals( "shared" ) )
                            {
                                _exclusive = false;
                            }
                        }
                    }
                    if ( scope == null )
                    {
                        return false;
                    }

                }
                else
                {
                    return false;
                }

                if ( lockTypeNode != null )
                {
                    childList = lockTypeNode.getChildNodes();
                    for ( int i = 0; i < childList.getLength(); i++ )
                    {
                        currentNode = childList.item( i );

                        if ( currentNode.getNodeType() == Node.ELEMENT_NODE )
                        {
                            _type = currentNode.getNodeName();

                            if ( _type.endsWith( "write" ) )
                            {
                                _type = "write";
                            }
                            else if ( _type.equals( "read" ) )
                            {
                                _type = "read";
                            }
                        }
                    }
                    if ( _type == null )
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }

                if ( lockOwnerNode != null )
                {
                    childList = lockOwnerNode.getChildNodes();
                    for ( int i = 0; i < childList.getLength(); i++ )
                    {
                        currentNode = childList.item( i );

                        if ( currentNode.getNodeType() == Node.ELEMENT_NODE || currentNode.getNodeType() == Node.TEXT_NODE )
                        {
                            _lockOwner = currentNode.getTextContent();
                        }
                    }
                }
                if ( _lockOwner == null )
                {
                    return false;
                }
            }
            else
            {
                return false;
            }

        }
        catch ( final DOMException e )
        {
            resp.sendError( SC_INTERNAL_SERVER_ERROR );
            e.printStackTrace();
            return false;
        }
        catch ( final SAXException e )
        {
            resp.sendError( SC_INTERNAL_SERVER_ERROR );
            e.printStackTrace();
            return false;
        }

        return true;
    }
997889
@Override
    public void lock(Object entity, LockModeType lockMode)
    {
        ivEm.lock(entity, lockMode);
    }
54013
public static FileLocker getLock(File lockFile) {
        lockFile.getParentFile().mkdirs();
        if (!lockFile.exists()) {
            try {
                IOHelper.write(lockFile, "I have the lock!");
                lockFile.deleteOnExit();
                return new FileLocker(lockFile);
            } catch (IOException e) {
                // Ignore
            }
        }
        return null;

    }
381049
@Override
    public void unlock(EJSContainer c, Object lockName, Locker locker)
    {
        c.getLockManager().unlock(lockName, locker);
    }
607442
public SessionLockManager getSessionLockManager(String sessionId, SessionDataManager transientManager)
   {
      CacheableSessionLockManager sessionManager = new CacheableSessionLockManager(sessionId, this, transientManager);
      sessionLockManagers.put(sessionId, sessionManager);
      return sessionManager;
   }
327633
@Override
  public void lock() throws JobLockException {
    try {
      this.lock.acquire();
    } catch (Exception e) {
      throw new JobLockException("Failed to acquire lock " + this.lockPath, e);
    }
  }
170490
public LockSet getFactAtLocation(Location location) throws DataflowAnalysisException {
        if (lockDataflow != null) {
            return lockDataflow.getFactAtLocation(location);
        } else {
            LockSet lockSet = cache.get(location);
            if (lockSet == null) {
                lockSet = new LockSet();
                lockSet.setDefaultLockCount(0);
                if (method.isSynchronized() && !method.isStatic()) {
                    // LockSet contains just the "this" reference
                    ValueNumber instance = vnaDataflow.getAnalysis().getThisValue();
                    lockSet.setLockCount(instance.getNumber(), 1);
                } else {
                    // LockSet is completely empty - nothing to do
                }
                cache.put(location, lockSet);
            }
            return lockSet;
        }
    }
596112
private IEntityLock[] retrieveLocks(Class entityType, String entityKey, Integer lockType)
            throws LockingException {
        Date expiration =
                (multiServer)
                        ? new Date(System.currentTimeMillis() - getLockToleranceMillis())
                        : new Date();

        return getLockStore().findUnexpired(expiration, entityType, entityKey, lockType, null);
    }
488191
public com.google.api.ads.admanager.axis.v201902.LockedOrientation getLockedOrientation() {
        return lockedOrientation;
    }
257612
private Map<String, String> readExistingLocks(HLock lock) {
    // logger.debug("Started reading all columns");
    SliceQuery<String, String, String> sliceQuery = HFactory
        .createSliceQuery(keyspace, StringSerializer.get(), StringSerializer.get(), StringSerializer.get())
        .setColumnFamily(lockManagerConfigurator.getLockManagerCF()).setKey(lock.getPath());

    //we only care about the first 2 locks, anything else is simply queued.  Select 10 just to be safe if the clients aren't ordered properly
    sliceQuery.setRange(null, null, false, maxSelectSize);

    QueryResult<ColumnSlice<String, String>> queryResult = sliceQuery.execute();

    // logger.debug("Finished reading all columns");
    return getResults(queryResult);
  }
52941
@Nullable
    public final PrintJobStatusExtImpl get(final String id, final boolean lock) {
        final CriteriaBuilder builder = getSession().getCriteriaBuilder();
        final CriteriaQuery<PrintJobStatusExtImpl> criteria =
                builder.createQuery(PrintJobStatusExtImpl.class);
        final Root<PrintJobStatusExtImpl> root = criteria.from(PrintJobStatusExtImpl.class);
        root.alias("pj");
        root.fetch("result", JoinType.LEFT);
        criteria.where(builder.equal(root.get("referenceId"), id));
        final Query<PrintJobStatusExtImpl> query = getSession().createQuery(criteria);
        if (lock) {
            //LOCK means SELECT FOR UPDATE which prevents these records to be pulled by different
            // instances
            query.setLockMode("pj", LockMode.PESSIMISTIC_READ);
        } else {
            query.setReadOnly(true);  // make sure the object is not updated if there is no lock
        }
        return query.uniqueResult();
    }
451089
private String getLockInfo(CmsResource resource) throws CmsException {

        CmsObject cms = getCmsObject();
        CmsResourceUtil resourceUtil = new CmsResourceUtil(cms, resource);
        CmsLock lock = resourceUtil.getLock();
        String lockInfo = null;
        if (!lock.isLockableBy(cms.getRequestContext().getCurrentUser())) {
            if (lock.getType() == CmsLockType.PUBLISH) {
                lockInfo = Messages.get().getBundle(OpenCms.getWorkplaceManager().getWorkplaceLocale(cms)).key(
                    Messages.GUI_LOCKED_FOR_PUBLISH_0);
            } else {
                CmsUser lockOwner = cms.readUser(lock.getUserId());
                lockInfo = Messages.get().getBundle(OpenCms.getWorkplaceManager().getWorkplaceLocale(cms)).key(
                    Messages.GUI_LOCKED_BY_1,
                    lockOwner.getFullName());
            }
        }
        return lockInfo;
    }