public bool CheckAndTrackDynamicThrottleMDBTimeout(Guid databaseGuid, IMailboxDatabaseConnectionInfo mdbConnectionInfo, IMailboxDatabaseConnectionManager mdbConnectionManager, long smtpSessionId, IPAddress sessionRemoteEndPointAddress, TimeSpan connectionWaitTime, List <KeyValuePair <string, double> > mdbHealthMonitorValues) { ArgumentValidator.ThrowIfNull("databaseGuid", databaseGuid); ArgumentValidator.ThrowIfNull("mdbConnectionManager", mdbConnectionManager); ArgumentValidator.ThrowIfNull("sessionRemoteEndPointAddress", sessionRemoteEndPointAddress); if (!mdbConnectionManager.TryAcquire(smtpSessionId, sessionRemoteEndPointAddress, connectionWaitTime, out mdbConnectionInfo)) { DeliveryThrottling.Diag.TraceDebug <Guid, long, IPAddress>(0, (long)this.GetHashCode(), "Dynamic Throttling: Connection was unable to be acquired. Dynamic Throttling Limit Exceeded. MDB {0} SessionId {1} IP {2}", databaseGuid, smtpSessionId, sessionRemoteEndPointAddress); this.DeliveryThrottlingLogWorker.TrackMDBThrottle(true, databaseGuid.ToString(), (double)DeliveryConfiguration.Instance.Throttling.MaxMailboxDeliveryPerMdbConnections, mdbHealthMonitorValues, ThrottlingResource.Threads_PendingConnectionTimedOut); return(false); } DeliveryThrottling.Diag.TraceDebug <Guid, long, IPAddress>(0, (long)this.GetHashCode(), "Dynamic Throttling: Connection was acquired. MDB {0} SessionId {1} IP {2}", databaseGuid, smtpSessionId, sessionRemoteEndPointAddress); this.DeliveryThrottlingLogWorker.TrackMDBThrottle(false, databaseGuid.ToString(), (double)DeliveryConfiguration.Instance.Throttling.MaxMailboxDeliveryPerMdbConnections, mdbHealthMonitorValues, ThrottlingResource.Threads_PendingConnectionTimedOut); return(true); }
public bool CheckAndTrackDynamicThrottleMDBPendingConnections(Guid databaseGuid, IMailboxDatabaseConnectionManager mdbConnectionManager, long smtpSessionId, IPAddress sessionRemoteEndPointAddress, out List <KeyValuePair <string, double> > mdbHealthMonitorValues) { mdbHealthMonitorValues = null; ArgumentValidator.ThrowIfNull("databaseGuid", databaseGuid); ArgumentValidator.ThrowIfNull("mdbConnectionManager", mdbConnectionManager); ArgumentValidator.ThrowIfNull("sessionRemoteEndPointAddress", sessionRemoteEndPointAddress); bool result; try { int num = -1; int num2 = -1; if (mdbConnectionManager.GetMdbHealthAndAddConnection(smtpSessionId, sessionRemoteEndPointAddress, out num, out mdbHealthMonitorValues, out num2)) { DeliveryThrottling.Diag.TraceDebug <Guid, long, IPAddress>(0, (long)this.GetHashCode(), "Dynamic Throttling: Connection added. MDB {0} SeesionId {1} IP {2}", databaseGuid, smtpSessionId, sessionRemoteEndPointAddress); this.DeliveryThrottlingLogWorker.TrackMDBThrottle(false, databaseGuid.ToString(), (double)DeliveryConfiguration.Instance.Throttling.MaxMailboxDeliveryPerMdbConnections, mdbHealthMonitorValues, ThrottlingResource.Threads_MaxPerHub); mdbConnectionManager.UpdateLastActivityTime(smtpSessionId); result = true; } else { DeliveryThrottling.Diag.TraceDebug <long>(0, (long)this.GetHashCode(), "Dynamic Throttling: Connection from the remote IP address is already in the pending queue. SessionId {0}", smtpSessionId); this.DeliveryThrottlingLogWorker.TrackMDBThrottle(true, databaseGuid.ToString(), (double)DeliveryConfiguration.Instance.Throttling.MaxMailboxDeliveryPerMdbConnections, mdbHealthMonitorValues, ThrottlingResource.Threads_MaxPerHub); result = false; } } catch (InvalidOperationException ex) { DeliveryThrottling.Diag.TraceDebug <long, string>(0, (long)this.GetHashCode(), "Dynamic Throttling: Error attempting to add connection. SessionId {0} Error: {1}", smtpSessionId, ex.ToString()); result = false; } return(result); }