Java Code Examples for org.apache.atlas.AtlasErrorCode#FAILED_TO_OBTAIN_TYPE_UPDATE_LOCK

The following examples show how to use org.apache.atlas.AtlasErrorCode#FAILED_TO_OBTAIN_TYPE_UPDATE_LOCK . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AtlasTypeRegistry.java    From atlas with Apache License 2.0 5 votes vote down vote up
AtlasTransientTypeRegistry lockTypeRegistryForUpdate(int lockMaxWaitTimeInSeconds) throws AtlasBaseException {
    LOG.debug("==> lockTypeRegistryForUpdate()");

    boolean alreadyLockedByCurrentThread = typeRegistryUpdateLock.isHeldByCurrentThread();

    if (!alreadyLockedByCurrentThread) {
        if (lockedByThread != null) {
            LOG.info("lockTypeRegistryForUpdate(): waiting for lock to be released by thread {}", lockedByThread);
        }
    } else {
        LOG.warn("lockTypeRegistryForUpdate(): already locked. currentLockCount={}",
                typeRegistryUpdateLock.getHoldCount());
    }

    try {
        boolean isLocked = typeRegistryUpdateLock.tryLock(lockMaxWaitTimeInSeconds, TimeUnit.SECONDS);

        if (!isLocked) {
            throw new AtlasBaseException(AtlasErrorCode.FAILED_TO_OBTAIN_TYPE_UPDATE_LOCK);
        }
    } catch (InterruptedException excp) {
        throw new AtlasBaseException(AtlasErrorCode.FAILED_TO_OBTAIN_TYPE_UPDATE_LOCK, excp);
    }

    if (!alreadyLockedByCurrentThread) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("lockTypeRegistryForUpdate(): wait over..got the lock");
        }

        typeRegistryUnderUpdate = new AtlasTransientTypeRegistry(typeRegistry);
        lockedByThread          = Thread.currentThread().getName();
    }

    LOG.debug("<== lockTypeRegistryForUpdate()");

    return typeRegistryUnderUpdate;
}
 
Example 2
Source File: AtlasTypeRegistry.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
AtlasTransientTypeRegistry lockTypeRegistryForUpdate(int lockMaxWaitTimeInSeconds) throws AtlasBaseException {
    LOG.debug("==> lockTypeRegistryForUpdate()");

    boolean alreadyLockedByCurrentThread = typeRegistryUpdateLock.isHeldByCurrentThread();

    if (!alreadyLockedByCurrentThread) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("lockTypeRegistryForUpdate(): waiting for lock to be released by thread {}", lockedByThread);
        }
    } else {
        LOG.warn("lockTypeRegistryForUpdate(): already locked. currentLockCount={}",
                typeRegistryUpdateLock.getHoldCount());
    }

    try {
        boolean isLocked = typeRegistryUpdateLock.tryLock(lockMaxWaitTimeInSeconds, TimeUnit.SECONDS);

        if (!isLocked) {
            throw new AtlasBaseException(AtlasErrorCode.FAILED_TO_OBTAIN_TYPE_UPDATE_LOCK);
        }
    } catch (InterruptedException excp) {
        throw new AtlasBaseException(AtlasErrorCode.FAILED_TO_OBTAIN_TYPE_UPDATE_LOCK, excp);
    }

    if (!alreadyLockedByCurrentThread) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("lockTypeRegistryForUpdate(): wait over..got the lock");
        }

        typeRegistryUnderUpdate = new AtlasTransientTypeRegistry(typeRegistry);
        lockedByThread          = Thread.currentThread().getName();
    }

    LOG.debug("<== lockTypeRegistryForUpdate()");

    return typeRegistryUnderUpdate;
}