Obtains a lock on the H2 database.

@throws H2DBLockException thrown if a lock could not be obtained
4428
public void lock() throws H2DBLockException {
        try {
            final File dir = settings.getDataDirectory();
            lockFile = new File(dir, "odc.update.lock");
            checkState();
            int ctr = 0;
            do {
                try {
                    if (!lockFile.exists() && lockFile.createNewFile()) {
                        file = new RandomAccessFile(lockFile, "rw");
                        lock = file.getChannel().lock();
                        file.writeBytes(magic);
                        file.getChannel().force(true);
                        Thread.sleep(20);
                        file.seek(0);
                        final String current = file.readLine();
                        if (current != null && !current.equals(magic)) {
                            lock.close();
                            lock = null;
                            LOGGER.debug("Another process obtained a lock first ({})", Thread.currentThread().getName());
                        } else {
                            addShutdownHook();
                            final Timestamp timestamp = new Timestamp(System.currentTimeMillis());
                            LOGGER.debug("Lock file created ({}) {} @ {}", Thread.currentThread().getName(), magic, timestamp.toString());
                        }
                    }
                } catch (IOException | InterruptedException ex) {
                    LOGGER.trace("Expected error as another thread has likely locked the file", ex);
                } finally {
                    if (lock == null && file != null) {
                        try {
                            file.close();
                            file = null;
                        } catch (IOException ex) {
                            LOGGER.trace("Unable to close the lock file", ex);
                        }
                    }
                }
                if (lock == null || !lock.isValid()) {
                    try {
                        final Timestamp timestamp = new Timestamp(System.currentTimeMillis());
                        LOGGER.debug("Sleeping thread {} ({}) for {} seconds because an exclusive lock on the database could not be obtained ({})",
                                Thread.currentThread().getName(), magic, SLEEP_DURATION / 1000, timestamp.toString());
                        Thread.sleep(SLEEP_DURATION);
                    } catch (InterruptedException ex) {
                        LOGGER.debug("sleep was interrupted.", ex);
                        Thread.currentThread().interrupt();
                    }
                }
            } while (++ctr < MAX_SLEEP_COUNT && (lock == null || !lock.isValid()));
            if (lock == null || !lock.isValid()) {
                throw new H2DBLockException("Unable to obtain the update lock, skipping the database update. Skippinig the database update.");
            }
        } catch (IOException ex) {
            throw new H2DBLockException(ex.getMessage(), ex);
        }
    }
434856
public Lock getLock(String lockName, LockType type, String comment) {
		return new SQLLock(lockName,type,comment, getSleepTime(), this);
	}
964613
public final long getLockID()
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
        {
            SibTr.entry(this, tc, "getLockID");
            SibTr.exit(this, tc, "getLockID", Long.valueOf(_lockID));
        }
        return _lockID;
    }
181161
public function lock()
    {
        $result = null;

        $context = $this->getContext();
        $context->table = $this->getBase();

        if ($this->invokeCommand('before.lock', $context) !== false)
        {
            if ($this->isConnected()) {
                $context->result = $this->getDriver()->lock($this->getBase());
            }

            $this->invokeCommand('after.lock', $context);
        }

        return $context->result;
    }
109698
public synchronized void unlock()
  {
    if (tc.isEntryEnabled())
      SibTr.entry(tc, "unlock", this);

    // If the subscription locks are down to zero then notify the threads waiting
    // for the subscriptionTable lock.
    synchronized (iMutex)
    {
      // If we are exclusively locked, then just return, as long as
      // the thread that is calling is the thread that holds the
      // exclusive lock.
      if (iExclusivelyLocked && iExclusiveLockHolder == Thread.currentThread())
      {
        if (tc.isEntryEnabled())
          SibTr.exit(tc, "unlock");
        return;
      }

      // Decrement the lock count and notify the other threads if no 
      // one holds the lock any more.
      if (--iLockCount == 0)
        notifyAll();
        
      if (iLockCount < 0)
      {      
        if (tc.isEntryEnabled()) 
          SibTr.exit(tc, "unlock", "SIErrorException");
        
        SibTr.error(tc, "INTERNAL_MESSAGING_ERROR_CWSIP0001",
          new Object[] {
            "com.ibm.ws.sib.processor.utils.LockManager",
            "1:196:1.19" });
          
        throw new SIErrorException(
          nls.getFormattedMessage(
            "INTERNAL_MESSAGING_ERROR_CWSIP0001",
            new Object[] {
              "com.ibm.ws.sib.processor.utils.LockManager",
              "1:203:1.19" },
            null));
      }        
    }

    if (tc.isEntryEnabled())
      SibTr.exit(tc, "unlock");
  }
1016911
public CmsLock getLock(CmsRequestContext context, CmsResource resource) throws CmsException {

        CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
        CmsLock result = null;
        try {
            result = m_driverManager.getLock(dbc, resource);
        } catch (Exception e) {
            dbc.report(null, Messages.get().container(Messages.ERR_GET_LOCK_1, context.getSitePath(resource)), e);
        } finally {
            dbc.clear();
        }
        return result;
    }
950933
private boolean addStoredBlock(Block block,
                               DatanodeDescriptor node,
                               DatanodeDescriptor delNodeHint) throws IOException {
    return addStoredBlockInternal(block, node, delNodeHint, false, null);
  }
52174
protected boolean isLockedException ( SQLiteException maybeLocked ) {
    try {
      if (Class.forName("android.database.sqlite.SQLiteDatabaseLockedException", false, getClass().getClassLoader()).isAssignableFrom(maybeLocked.getClass()) ) {
        return true;
      }
    } catch (ClassNotFoundException e) {
      // no android.database.sqlite.SQLiteDatabaseLockedException
    }
    return false;
  }
563580
private void lock(Object obtainer) throws PSQLException {
    if (lockedFor == obtainer) {
      throw new PSQLException(GT.tr("Tried to obtain lock while already holding it"),
          PSQLState.OBJECT_NOT_IN_STATE);

    }
    waitOnLock();
    lockedFor = obtainer;
  }
1223401
private function matchingLock($lockID, array $next, Connection $db)
    {
        // Then go back and double check that we successfully locked it
        $qb = $db->createQueryBuilder();

        $select = $qb
            ->select('*')
            ->from($this->table, 't')
            // Match the lock ID we just tried to set
            ->where($qb->expr()->eq($this->lockColumn, $qb->expr()->literal($lockID)));

        // Build additional predicates from already known values
        $predicates = array_map(function ($value, $key) use ($qb) {
            return $qb->expr()->eq($key, $qb->expr()->literal($value));
        }, $next, array_keys($next));

        call_user_func_array([$select, 'andWhere'], $predicates);

        // Get the result and validate it
        if ($result = $select->setMaxResults(1)->execute()->fetch()) {
            return $result;
        }

        return false;
    }
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;
    }
144217
private Object retrieveLock(String key)
   {
      Object lock = this.lockMap.get(key);
      if(lock == null)
      {
         lock = key;
         this.lockMap.put(key, lock);
      }
      return lock;
   }
854316
private ClientRWLock getBlockLock(long blockId) {
    // Loop until we either find the block lock in the mLocks map, or successfully acquire a new
    // block lock from the lock pool.
    while (true) {
      ClientRWLock blockLock;
      // Check whether a lock has already been allocated for the block id.
      synchronized (mSharedMapsLock) {
        blockLock = mLocks.get(blockId);
        if (blockLock != null) {
          blockLock.addReference();
          return blockLock;
        }
      }
      // Since a block lock hasn't already been allocated, try to acquire a new one from the pool.
      // Acquire the lock outside the synchronized section because #acquire might need to block.
      // We shouldn't wait indefinitely in acquire because the another lock for this block could be
      // allocated to another thread, in which case we could just use that lock.
      blockLock = mLockPool.acquire(1, TimeUnit.SECONDS);
      if (blockLock != null) {
        synchronized (mSharedMapsLock) {
          // Check if someone else acquired a block lock for blockId while we were acquiring one.
          if (mLocks.containsKey(blockId)) {
            mLockPool.release(blockLock);
            blockLock = mLocks.get(blockId);
          } else {
            mLocks.put(blockId, blockLock);
          }
          blockLock.addReference();
          return blockLock;
        }
      }
    }
  }
1253264
def get_lock(key, value=None, expiry_time=60):
    """"""
    from uliweb.utils.common import get_uuid

    redis = get_redis()
    value = value or get_uuid()
    return redis.set(key, value, ex=expiry_time, nx=True)
332689
@Override
    public void update(IEntityLock lock, Date newExpiration, Integer newLockType)
            throws LockingException {
        Connection conn = null;
        try {
            conn = RDBMServices.getConnection();
            if (newLockType != null) {
                primDeleteExpired(new Date(), lock.getEntityType(), lock.getEntityKey(), conn);
            }
            primUpdate(lock, newExpiration, newLockType, conn);
        } catch (SQLException sqle) {
            throw new LockingException("Problem updating " + lock, sqle);
        } finally {
            RDBMServices.releaseConnection(conn);
        }
    }
310742
public static Lock toLock(Entity entity) {
		return new Lock(entity.getKey().getName(), 
				(String) entity.getProperty(TRANSACTION_PROPERTY), 
				(Date) entity.getProperty(TIMESTAMP_PROPERTY));
	}
34234
protected function lock()
    {
        $this->tables->execute();
        $table = array();

        while ($a = $this->tables->fetch(\PDO::FETCH_ASSOC)) {
            $table[] = current($a);
        }

        return !$table || $this->pdo->exec('LOCK TABLES `'.implode('` WRITE, `', $table).'` WRITE');
    }