Search in sources :

Example 1 with TryLockOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockOutput in project netvirt by opendaylight.

the class FibUtil method lockCluster.

public static boolean lockCluster(LockManagerService lockManager, String lockName, long tryLockPeriod) {
    TryLockInput input = new TryLockInputBuilder().setLockName(lockName).setTime(tryLockPeriod).setTimeUnit(TimeUnits.Milliseconds).build();
    Future<RpcResult<TryLockOutput>> result = lockManager.tryLock(input);
    boolean lockAcquired;
    try {
        if (result != null && result.get().isSuccessful()) {
            LOG.debug("lockCluster: Acquired lock for {}", lockName);
            lockAcquired = true;
        } else {
            LOG.error("lockCluster: Unable to getLock for {}", lockName);
            lockAcquired = false;
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("lockCluster: Exception while trying to getLock for {}", lockName, e);
        lockAcquired = false;
    }
    return lockAcquired;
}
Also used : TryLockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) TryLockInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInputBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with TryLockOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockOutput in project netvirt by opendaylight.

the class VpnUtil method lockSubnet.

void lockSubnet(String subnetId) {
    // We set the total wait time for lock to be obtained at 9 seconds since GC pauses can be upto 8 seconds
    // in scale setups.
    TryLockInput input = new TryLockInputBuilder().setLockName(subnetId).setTime(9000L).setTimeUnit(TimeUnits.Milliseconds).build();
    Future<RpcResult<TryLockOutput>> result = lockManager.tryLock(input);
    try {
        if (result != null && result.get().isSuccessful()) {
            LOG.debug("lockSubnet: Acquired lock for {}", subnetId);
        } else {
            LOG.error("Unable to get lock for subnet {}", subnetId);
            throw new RuntimeException("Unable to get lock for subnet " + subnetId);
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Unable to get lock for subnet {}", subnetId, e);
        throw new RuntimeException("Unable to get lock for subnet " + subnetId, e);
    }
}
Also used : TryLockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) TryLockInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInputBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)2 TryLockInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInput)2 TryLockInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.TryLockInputBuilder)2 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2