public override int GetHashCode()
 {
     unchecked
     {
         return((Name.GetHashCode() * 397) ^ LockId.GetHashCode());
     }
 }
예제 #2
0
 public async Task<string> Confirm(LockId lockId)
 {
     if (!IsConnected(_client))
         await TryConnect();
     
     return await ExecCommand(
         lockId.GetConfirmCommand,
         res => res != null && res.Equals("1"));
 }
예제 #3
0
        public async Task<string> Confirm(LockId lockId)
        {
            if (!IsConnected(_stackExchangeClient))
                await TryConnect();

            return ExecResultedConfirmOrReleaseScript(
                lockId.GetConfirmScript,
                lockId.GetConfirmScriptParameters
            );
        }
 public bool Equals(DbDistributedMutexLock other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(string.Equals(Name, other.Name) && LockId.Equals(other.LockId));
 }
예제 #5
0
        public async Task<string> Release(LockId lockId)
        {
            if (!IsConnected(_client))
                await TryConnect();

            _logger.ToDebugLog(
                string.Format(
                    "Trying to release the lock on {0}:{1} set to {2}...",
                    _node.Host,
                    _node.Port,
                    lockId.SessionId));

            return await ExecCommand(
                lockId.GetReleaseCommand,
                res => res != null && res.Equals("1"));
        }
예제 #6
0
        public async Task<string> Set(LockId lockId)
        {
            if (!IsConnected(_client))
                await TryConnect();

            _logger.ToDebugLog(
                string.Format(
                    "Trying to set the lock on {0}:{1} to {2}...",
                    _node.Host,
                    _node.Port,
                    lockId.SessionId));

            return await ExecCommand(
                lockId.GetSetCommand,
                res => res != null && res.Equals("OK", StringComparison.InvariantCultureIgnoreCase));
        }
예제 #7
0
        public async Task<string> Release(LockId lockId)
        {
            if (!IsConnected(_stackExchangeClient))
                await TryConnect();

            _logger.ToDebugLog(
                string.Format(
                    "Trying to release the lock on {0}:{1} set to {2}...",
                    _node.Host,
                    _node.Port,
                    lockId.SessionId));

            return ExecResultedConfirmOrReleaseScript(
                lockId.GetReleaseScript,
                lockId.GetReleaseScriptParameters
            );
        }
 public async Task<bool> ReleaseLock(LockType lockType, string instanceId)
 {
     var lockId = new LockId(lockType, InstanceName);
     Log.Trace($"Releasing lock {lockId} on {instanceId}");
     var result =
         await Collection.DeleteOneAsync(
             FilterBuilder.Where(@lock => @lock.Id == lockId && @lock.InstanceId == instanceId)).ConfigureAwait(false);
     if (result.DeletedCount > 0)
     {
         Log.Trace($"Released lock {lockId} on {instanceId}");
         return true;
     }
     else
     {
         Log.Warn($"Failed to release lock {lockId} on {instanceId}. You do not own the lock.");
         return false;
     }
 }
예제 #9
0
        public bool ReleaseLock(LockType lockType, string instanceId)
        {
            var lockId = new LockId(lockType, InstanceName);

            Log.Trace($"Releasing lock {lockId} on {instanceId}");
            var result =
                Collection.DeleteOne(
                    FilterBuilder.Where(@lock => @lock.Id == lockId && @lock.InstanceId == instanceId));

            if (result.DeletedCount > 0)
            {
                Log.Trace($"Released lock {lockId} on {instanceId}");
                return(true);
            }
            else
            {
                Log.Warn($"Failed to release lock {lockId} on {instanceId}. You do not own the lock.");
                return(false);
            }
        }
 public async Task<bool> TryAcquireLock(LockType lockType, string instanceId)
 {
     var lockId = new LockId(lockType, InstanceName);
     Log.Trace($"Trying to acquire lock {lockId} on {instanceId}");
     try
     {
         await Collection.InsertOneAsync(new Lock
         {
             Id = lockId,
             InstanceId = instanceId,
             AquiredAt = DateTime.Now
         }).ConfigureAwait(false);
         Log.Trace($"Acquired lock {lockId} on {instanceId}");
         return true;
     }
     catch (MongoWriteException)
     {
         Log.Trace($"Failed to acquire lock {lockId} on {instanceId}");
         return false;
     }
 }
예제 #11
0
        public bool TryAcquireLock(LockType lockType, string instanceId)
        {
            var lockId = new LockId(lockType, InstanceName);

            Log.Trace($"Trying to acquire lock {lockId} on {instanceId}");
            try
            {
                Collection.InsertOne(new Lock
                {
                    Id         = lockId,
                    InstanceId = instanceId,
                    AquiredAt  = DateTime.Now
                });
                Log.Trace($"Acquired lock {lockId} on {instanceId}");
                return(true);
            }
            catch (MongoWriteException)
            {
                Log.Trace($"Failed to acquire lock {lockId} on {instanceId}");
                return(false);
            }
        }
예제 #12
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     // ReSharper disable once NonReadonlyMemberInGetHashCode
     return(LockId.GetHashCode());
 }