Exemple #1
0
        public void Run()
        {
            try
            {
                ArrayList idleMembers;
                ArrayList suspectedList = new ArrayList();
                _ct.SetConnectionsStatus(true);
                Thread.Sleep(_interval);

                while (_thread != null)
                {
                    idleMembers = _ct.GetIdleMembers();

                    if (idleMembers.Count > 0)
                    {
                        lock (_idleConnections.SyncRoot)
                        {
                            for (int i = 0; i < idleMembers.Count; i++)
                            {
                                Address member = idleMembers[i] as Address;

                                if (_enclosingInstance.Stack.NCacheLog.IsInfoEnabled)
                                {
                                    _enclosingInstance.Stack.NCacheLog.Info("ConnectionKeepAlive.Run", "pining idle member ->:" + member.ToString());
                                }

                                if (!_idleConnections.Contains(member))
                                {
                                    _idleConnections.Add(idleMembers[i], (int)1);
                                }
                                else
                                {
                                    int attemptCount = (int)_idleConnections[member];
                                    attemptCount++;

                                    if (attemptCount > _maxAttempts)
                                    {
                                        _idleConnections.Remove(member);
                                        suspectedList.Add(member);
                                    }
                                    else
                                    {
                                        if (_enclosingInstance.Stack.NCacheLog.IsErrorEnabled)
                                        {
                                            _enclosingInstance.Stack.NCacheLog.Error("ConnectionKeepAlive.Run", attemptCount + " did not received any heart beat ->:" + member.ToString());
                                        }

                                        _idleConnections[member] = attemptCount;
                                    }
                                }
                            }
                        }
                        AskHeartBeats(idleMembers);
                    }

                    if (_enclosingInstance.Stack.NCacheLog.IsInfoEnabled)
                    {
                        _enclosingInstance.Stack.NCacheLog.Info("ConnectionKeepAlive.Run", "setting connections status to idle ->:");
                    }

                    _ct.SetConnectionsStatus(true);

                    foreach (Address suspected in suspectedList)
                    {
                        if (_enclosingInstance.Stack.NCacheLog.IsErrorEnabled)
                        {
                            _enclosingInstance.Stack.NCacheLog.Error("ConnectionKeepAlive.Run", "member being suspected ->:" + suspected.ToString());
                        }

                        _ct.remove(suspected, true);
                        _enclosingInstance.connectionClosed(suspected);
                    }
                    suspectedList.Clear();

                    Thread.Sleep(_interval);
                }
            }
            catch (ThreadAbortException) { }
            catch (ThreadInterruptedException) { }
            catch (Exception e)
            {
                _enclosingInstance.Stack.NCacheLog.Error("ConnectionKeepAlive.Run", e.ToString());
            }
            if (_enclosingInstance.Stack.NCacheLog.IsInfoEnabled)
            {
                _enclosingInstance.Stack.NCacheLog.Info("ConnectionKeepAlive.Run", "exiting keep alive thread");
            }
        }