コード例 #1
0
        public void KeyRemoved(string key, bool isUserOperation, string clientId)
        {
            lock (this)
            {
                if (!isUserOperation)
                {
                    UnRegisterKeyNotification(key, null, null);
                    return;
                }
                if (_registeredKeys.ContainsKey(key))
                {
                    _lastChangeTime = HPTime.Now; // set last change time

                    KeyInfo keyInfo = _registeredKeys[key];
                    keyInfo.UpdatedTime = HPTime.Now;
                    keyInfo             = keyInfo.Clone() as KeyInfo;
                    keyInfo.UpdatedBy   = clientId;

                    if (!_removedKeys.ContainsKey(key))
                    {
                        _removedKeys.Add(key, keyInfo);
                    }
                    else
                    {
                        _removedKeys[key] = keyInfo;
                    }

                    if (_updatedKeys.ContainsKey(key))
                    {
                        _updatedKeys.Remove(key);
                    }
                }
            }
        }
コード例 #2
0
 public ClientNotificationMgr(string clientId, ref HashVector <string, KeyInfo> updatedKeys, ref HashVector <string, KeyInfo> removedKeys)
 {
     _updatedKeys    = updatedKeys;
     _removedKeys    = removedKeys;
     _interestedKeys = new HashVector <string, NotificationEntry>();
     _lastPollTime   = HPTime.Now;
     _clientId       = clientId;
 }
コード例 #3
0
        private void SendPollRequestTask()
        {
            try
            {
                // Waiting 30 minutes to declare a client dead.
                // No of notifications to be sent in 30 minutes
                float deadClientTest = (float)_deadClientInterval / _pollRequestInterval;

                HPTime lastDeadClientCheckTime = HPTime.Now;
                bool   looped = false;
                while (!_isDisposing)
                {
                    try
                    {
                        for (float i = 0; i < deadClientTest; i++)
                        {
                            looped = true;
                            if (_isDisposing)
                            {
                                break;
                            }
                            SendPollRequest();
                            lock (this)
                            {
                                Monitor.Wait(this, _pollRequestInterval);
                            }
                        }

                        if (looped)
                        {
                            CleanDeadClients(lastDeadClientCheckTime);
                        }

                        lastDeadClientCheckTime = HPTime.Now;
                    }
                    catch (ThreadAbortException)
                    {
                        break;
                    }
                    catch (ThreadInterruptedException)
                    {
                        break;
                    }
                }
            }
            catch (ThreadAbortException) { }
            catch (ThreadInterruptedException) { }
            catch (Exception e)
            {
                NCacheLog.Error("PullBasedNotificationManager.SendPollRequest", e.ToString());
            }
        }
コード例 #4
0
        public void ClearCache(bool raisenotification)
        {
            lock (this)
            {
                foreach (KeyValuePair <string, ClientNotificationMgr> kvp in _clients)
                {
                    kvp.Value.ClearKeys();
                }
                _registeredKeys.Clear();
                _removedKeys.Clear();
                _updatedKeys.Clear();
            }

            if (raisenotification)
            {
                lock (this)
                {
                    IDictionaryEnumerator ide = _clients.GetEnumerator();
                    while (ide.MoveNext())
                    {
                        _lastChangeTime = HPTime.Now;
                        ((ClientNotificationMgr)ide.Value).AddKey(_clearKey, null, null);

                        if (!_registeredKeys.ContainsKey(_clearKey))
                        {
                            _registeredKeys.Add(_clearKey, new KeyInfo());
                        }

                        KeyInfo keyInfo = _registeredKeys[_clearKey];

                        keyInfo.UpdatedTime = HPTime.Now;
                        keyInfo             = keyInfo.Clone() as KeyInfo;
                        keyInfo.UpdatedBy   = ide.Key as string;

                        if (!_updatedKeys.ContainsKey(_clearKey))
                        {
                            _updatedKeys.Add(_clearKey, keyInfo);
                        }
                        else
                        {
                            _updatedKeys[_clearKey] = keyInfo;
                        }
                    }
                }
            }
        }
コード例 #5
0
        public void KeyUpdated(string key, bool isUseroperation, string clientId)
        {
            lock (this)
            {
                KeyInfo keyInfo;
                if (_registeredKeys.TryGetValue(key, out keyInfo))
                {
                    _lastChangeTime = HPTime.Now; // set last change time


                    keyInfo.UpdatedTime = HPTime.Now;
                    keyInfo             = keyInfo.Clone() as KeyInfo;
                    keyInfo.UpdatedBy   = clientId;

                    _updatedKeys[key] = keyInfo;
                }
            }
        }
コード例 #6
0
 private void CleanDeadClients(HPTime lastDeadClientTimeCheck)
 {
     try
     {
         lock (this)
         {
             List <string> deadClients = new List <string>();
             foreach (KeyValuePair <string, ClientNotificationMgr> kvp in _clients)
             {
                 ClientNotificationMgr client = kvp.Value;
                 if (client.LastPollTime.CompareTo(lastDeadClientTimeCheck) < 0)
                 {
                     deadClients.Add(kvp.Key);
                     RemoveClient(kvp.Key);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         NCacheLog.Error("PullBaseNotificationManager.CleanDeadClients()", " Exception: " + ex);
     }
 }
コード例 #7
0
 public void Deserialize(CompactReader reader)
 {
     _trace     = reader.ReadObject() as string;
     _timeStamp = reader.ReadObject() as HPTime;
 }
コード例 #8
0
 public MessageTrace(string trace)
 {
     _trace     = trace;
     _timeStamp = HPTime.Now;
 }
コード例 #9
0
        public PollingResult GetChangedKeys(ILogger logger)
        {
            PollingResult result      = new PollingResult();
            HPTime        newPollTime = HPTime.Now;

            lock (_interestedKeys)
            {
                IDictionaryEnumerator enumerator = _interestedKeys.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    string key = enumerator.Key as string;

                    // add to result if clearkey exists in interest
                    if (key.Equals(_clearKey))
                    {
                        result.UpdatedKeys.Add(_clearKey);
                        DecrementOrRemove(ref _updatedKeys, _clearKey);
                    }

                    NotificationEntry enntry = (NotificationEntry)enumerator.Value;
                    if (enntry.NotifyOnUpdate)
                    {
                        if (_updatedKeys.ContainsKey(key))
                        {
                            //change must be detected if a client had registered prior to change occured
                            if (_updatedKeys[key].UpdatedTime.CompareTo(enntry.RegistrationTime) > 0 &&
                                _updatedKeys[key].UpdatedTime.CompareTo(_lastPollTime) >= 0)
                            {
                                if (_updatedKeys[key].UpdatedBy != null && string.Compare(_updatedKeys[key].UpdatedBy, _clientId, true) != 0)
                                {
                                    result.UpdatedKeys.Add(key);
                                }
                                else if (_updatedKeys[key].UpdatedBy == null)
                                {
                                    result.UpdatedKeys.Add(key);
                                }

                                DecrementOrRemove(ref _updatedKeys, key);
                            }
                        }
                    }
                    if (enntry.NotifyOnRemove)
                    {
                        if (_removedKeys.ContainsKey(key))
                        {
                            //change must be detected if a client had registered prior to change occured
                            if (_removedKeys[key].UpdatedTime.CompareTo(enntry.RegistrationTime) > 0 &&
                                _removedKeys[key].UpdatedTime.CompareTo(_lastPollTime) >= 0)
                            {
                                if (_removedKeys[key].UpdatedBy != null && string.Compare(_removedKeys[key].UpdatedBy, _clientId, true) != 0)
                                {
                                    result.RemovedKeys.Add(key);
                                }
                                else if (_removedKeys[key].UpdatedBy == null)
                                {
                                    result.RemovedKeys.Add(key);
                                }
                                DecrementOrRemove(ref _removedKeys, key);
                            }
                        }
                    }
                }

                _lastPollTime = newPollTime;
                //Remove keys that are deleted from interestedKeys here
                foreach (string key in result.RemovedKeys)
                {
                    _interestedKeys.Remove(key);
                }

                if (_interestedKeys.ContainsKey(_clearKey))
                {
                    _interestedKeys.Remove(_clearKey);
                }
            }
            return(result);
        }
コード例 #10
0
 public KeyInfo()
 {
     _refCount    = 1;
     _updatedTime = HPTime.Now;
 }