Пример #1
0
        public bool RemoveConnection(long smtpSessionId, IPAddress remoteIPAddress)
        {
            if (remoteIPAddress == null)
            {
                throw new ArgumentNullException("remoteIPAddress");
            }
            MailboxDatabaseConnectionManager.ConnectionInfo connectionInfo = null;
            if (!this.connections.TryGetValue(smtpSessionId, out connectionInfo))
            {
                return(false);
            }
            if (!remoteIPAddress.Equals(connectionInfo.RemoteIPAddress))
            {
                return(false);
            }
            bool active = connectionInfo.Active;

            connectionInfo.Active = false;
            bool result = false;

            lock (this.syncObject)
            {
                result = this.RemoveConnectionTrackingItems(smtpSessionId);
                if (active)
                {
                    this.ActivateNextConnection();
                }
            }
            return(result);
        }
Пример #2
0
 public void UpdateLastActivityTime(long smtpSessionId)
 {
     MailboxDatabaseConnectionManager.ConnectionInfo connectionInfo = null;
     if (this.connections.TryGetValue(smtpSessionId, out connectionInfo))
     {
         connectionInfo.LastActivityTime = ExDateTime.UtcNow;
     }
 }
Пример #3
0
        private bool RemoveConnectionTrackingItems(long smtpSessionId)
        {
            MailboxDatabaseConnectionManager.ConnectionInfo connectionInfo = null;
            bool        result = this.connections.TryRemove(smtpSessionId, out connectionInfo);
            PooledEvent value  = null;
            bool        flag   = this.sessionEvents.TryRemove(smtpSessionId, out value);

            if (flag)
            {
                this.eventPool.Release(value);
            }
            return(result);
        }
Пример #4
0
        public int GetThreadCount()
        {
            int num = 0;

            foreach (long key in this.connections.Keys)
            {
                MailboxDatabaseConnectionManager.ConnectionInfo connectionInfo = null;
                if (this.connections.TryGetValue(key, out connectionInfo) && connectionInfo.Active)
                {
                    num++;
                }
            }
            return(num);
        }
Пример #5
0
 private bool IsPending(IPAddress remoteIPAddress)
 {
     lock (this.syncObject)
     {
         MailboxDatabaseConnectionManager.ConnectionInfo connectionInfo = null;
         foreach (long key in this.pendingConnections)
         {
             if (this.connections.TryGetValue(key, out connectionInfo) && !connectionInfo.Active && connectionInfo.RemoteIPAddress.Equals(remoteIPAddress))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #6
0
        public void ProcessStaleConnections(ExDateTime current, TimeSpan connectionMaxAge)
        {
            List <MailboxDatabaseConnectionManager.ConnectionInfo> list = new List <MailboxDatabaseConnectionManager.ConnectionInfo>();

            foreach (long key in this.connections.Keys)
            {
                MailboxDatabaseConnectionManager.ConnectionInfo connectionInfo = null;
                if (this.connections.TryGetValue(key, out connectionInfo) && ExDateTime.TimeDiff(current, connectionInfo.LastActivityTime).TotalMilliseconds > connectionMaxAge.TotalMilliseconds)
                {
                    list.Add(connectionInfo);
                }
            }
            foreach (MailboxDatabaseConnectionManager.ConnectionInfo connectionInfo2 in list)
            {
                this.RemoveConnection(connectionInfo2.SmtpSessionId, connectionInfo2.RemoteIPAddress);
            }
        }
Пример #7
0
        private bool ActivateNextConnection()
        {
            if (this.pendingConnections.Count == 0)
            {
                return(false);
            }
            long key = 0L;

            MailboxDatabaseConnectionManager.ConnectionInfo connectionInfo = null;
            while (connectionInfo == null && this.pendingConnections.TryDequeue(out key))
            {
                if (this.connections.TryGetValue(key, out connectionInfo))
                {
                    connectionInfo.Active = true;
                    this.SetSessionEvent(connectionInfo.SmtpSessionId);
                }
            }
            return(true);
        }
Пример #8
0
        public XElement GetDiagnosticInfo(XElement parentElement)
        {
            XElement xelement = new XElement("Database");

            xelement.Add(new XElement("id", this.mdbGuid));
            int num = 0;

            DeliveryThrottling.Instance.TryGetDatabaseHealth(this.mdbGuid, out num);
            xelement.Add(new XElement("databaseHealthMeasure", num));
            XElement xelement2 = new XElement("activeConnectionCount");
            XElement xelement3 = new XElement("pendingConnectionCount");

            xelement.Add(xelement2);
            xelement.Add(xelement3);
            XElement xelement4 = new XElement("Sessions");

            xelement.Add(xelement4);
            int num2 = 0;

            foreach (long num3 in this.connections.Keys)
            {
                XElement xelement5 = new XElement("Session");
                xelement4.Add(xelement5);
                xelement5.Add(new XElement("id", num3));
                MailboxDatabaseConnectionManager.ConnectionInfo connectionInfo = null;
                if (this.connections.TryGetValue(num3, out connectionInfo))
                {
                    if (connectionInfo.Active)
                    {
                        num2++;
                    }
                    xelement5.Add(new XElement("state", connectionInfo.Active ? "Active" : "Pending"));
                }
            }
            xelement2.SetValue(num2);
            xelement3.SetValue(this.pendingConnections.Count);
            parentElement.Add(xelement);
            return(parentElement);
        }
Пример #9
0
 public bool GetMdbHealthAndAddConnection(long smtpSessionId, IPAddress remoteIPAddress, out int mdbHealthMeasure, out List <KeyValuePair <string, double> > healthMonitorList, out int currentConnectionLimit)
 {
     mdbHealthMeasure       = -1;
     healthMonitorList      = null;
     currentConnectionLimit = -1;
     if (remoteIPAddress == null)
     {
         throw new ArgumentNullException("remoteIPAddress");
     }
     lock (this.syncObject)
     {
         if (this.IsPending(remoteIPAddress))
         {
             return(false);
         }
         currentConnectionLimit = DeliveryThrottling.Instance.GetMDBThreadLimitAndHealth(this.mdbGuid, out mdbHealthMeasure, out healthMonitorList);
         if (!this.sessionEvents.TryAdd(smtpSessionId, this.eventPool.Acquire()))
         {
             throw new InvalidOperationException("Unable to initialize synchronization events for the session.");
         }
         MailboxDatabaseConnectionManager.ConnectionInfo orAdd = this.connections.GetOrAdd(smtpSessionId, new MailboxDatabaseConnectionManager.ConnectionInfo(smtpSessionId, remoteIPAddress, ExDateTime.UtcNow, false));
         if (this.connections.Keys.Count <= currentConnectionLimit && this.pendingConnections.Count == 0)
         {
             orAdd.Active = true;
             this.SetSessionEvent(smtpSessionId);
         }
         else
         {
             this.pendingConnections.Enqueue(smtpSessionId);
             if (this.connections.Keys.Count <= currentConnectionLimit)
             {
                 this.ActivateNextConnection();
             }
         }
     }
     return(true);
 }