Exemplo n.º 1
0
 private void Remove()
 {
     mLokers.Dequeue();
     while (mLokers.Count > 0)
     {
         LockInfo locked = mLokers.Peek();
         if (Node.GetRuntime() - locked.Time > TimeOut)
         {
             Node.Loger.Process(LogType.DEBUG, "{0}/{1} lock timeout!", locked.Owner, locked.Key);
             mLokers.Dequeue();
         }
         else
         {
             Protocols.LockResult result = new Protocols.LockResult();
             result.Success = true;
             locked.RequestMessage.Reply(result);
             Node.Loger.Process(LogType.DEBUG, "{0}/{1} enter!", locked.Owner, locked.Key);
             return;
         }
     }
     if (mLokers.Count == 0)
     {
         if (BeEmpty != null)
         {
             BeEmpty(this);
         }
     }
 }
Exemplo n.º 2
0
 public void Exit(string key, string owner)
 {
     Protocols.FreeKey free = new Protocols.FreeKey();
     free.Owner = owner;
     free.Key   = key;
     Protocols.LockResult result = Subscriber.Publish <Protocols.LockResult>(DMonitoCenter.SMART_DLOCKCENTER, free, TimeOut);
     if (!result.Success)
     {
         throw new DLockExecption(result.StatusMessage);
     }
 }
Exemplo n.º 3
0
        public IDisposable Enter(string key)
        {
            string owner = mID + "_" + System.Threading.Thread.CurrentThread.ManagedThreadId;

            Protocols.EnterKey enter = new Protocols.EnterKey();
            enter.Owner = owner;
            enter.Key   = key;
            Protocols.LockResult result = Subscriber.Publish <Protocols.LockResult>(DMonitoCenter.SMART_DLOCKCENTER, enter, TimeOut);
            if (!result.Success)
            {
                throw new DLockExecption(result.StatusMessage);
            }
            return(new Locker {
                Key = key, Owner = owner, Moitor = this
            });
        }
Exemplo n.º 4
0
 private void Enter(LockInfo info)
 {
     info.Time = Node.GetRuntime();
     mLokers.Enqueue(info);
     if (mLokers.Count == 1)
     {
         Protocols.LockResult result = new Protocols.LockResult();
         result.Success = true;
         info.RequestMessage.Reply(result);
         Node.Loger.Process(LogType.DEBUG, "{0}/{1} enter!", info.Owner, info.Key);
     }
     else
     {
         Node.Loger.Process(LogType.DEBUG, "{0}/{1} wait!", info.Owner, info.Key);
     }
 }
Exemplo n.º 5
0
        private void Free(LockInfo info)
        {
            LockInfo locked = mLokers.Peek();

            Protocols.LockResult result = new Protocols.LockResult();
            if (info.Key == info.Key && info.Owner == info.Owner)
            {
                Node.Loger.Process(LogType.DEBUG, "{0}/{1} exit!", info.Owner, info.Key);
                Remove();
                result.Success = true;
            }
            else
            {
                result.StatusMessage = "invalid operation!";
                result.Success       = false;

                Node.Loger.Process(LogType.DEBUG, "{0}/{1} invalid operation {2}/{3}!", info.Owner, info.Key, locked.Owner,
                                   locked.Key);
            }
            info.RequestMessage.Reply(result);
        }