Search in sources :

Example 1 with ResourceLockKeyProvider

use of org.eclipse.che.multiuser.resource.api.ResourceLockKeyProvider in project che-server by eclipse-che.

the class ResourcesLocks method lock.

/**
 * Acquire resources lock for specified account.
 *
 * @param accountId account id to lock resources
 * @return lock for unlocking resources when resources operation finishes
 * @throws NotFoundException when account with specified {@code account id} was not found
 * @throws ServerException when any other error occurs
 */
public Unlocker lock(String accountId) throws NotFoundException, ServerException {
    final Account account = accountManager.getById(accountId);
    final ResourceLockKeyProvider resourceLockKeyProvider = accountTypeToLockProvider.get(account.getType());
    String lockKey;
    if (resourceLockKeyProvider == null) {
        // this account type doesn't have custom lock provider.
        // Lock resources by current account
        lockKey = accountId;
    } else {
        lockKey = resourceLockKeyProvider.getLockKey(accountId);
    }
    return stripedLocks.writeLock(lockKey);
}
Also used : Account(org.eclipse.che.account.shared.model.Account) ResourceLockKeyProvider(org.eclipse.che.multiuser.resource.api.ResourceLockKeyProvider)

Example 2 with ResourceLockKeyProvider

use of org.eclipse.che.multiuser.resource.api.ResourceLockKeyProvider in project devspaces-images by redhat-developer.

the class ResourcesLocks method lock.

/**
 * Acquire resources lock for specified account.
 *
 * @param accountId account id to lock resources
 * @return lock for unlocking resources when resources operation finishes
 * @throws NotFoundException when account with specified {@code account id} was not found
 * @throws ServerException when any other error occurs
 */
public Unlocker lock(String accountId) throws NotFoundException, ServerException {
    final Account account = accountManager.getById(accountId);
    final ResourceLockKeyProvider resourceLockKeyProvider = accountTypeToLockProvider.get(account.getType());
    String lockKey;
    if (resourceLockKeyProvider == null) {
        // this account type doesn't have custom lock provider.
        // Lock resources by current account
        lockKey = accountId;
    } else {
        lockKey = resourceLockKeyProvider.getLockKey(accountId);
    }
    return stripedLocks.writeLock(lockKey);
}
Also used : Account(org.eclipse.che.account.shared.model.Account) ResourceLockKeyProvider(org.eclipse.che.multiuser.resource.api.ResourceLockKeyProvider)

Aggregations

Account (org.eclipse.che.account.shared.model.Account)2 ResourceLockKeyProvider (org.eclipse.che.multiuser.resource.api.ResourceLockKeyProvider)2