Example #1
0
        private static MiniServer GetAnyBackEndServer(int versionNumber, bool needsExactVersionMatch)
        {
            MiniServer miniServer = null;

            try
            {
                miniServer = ServersCache.GetDeterministicBackEndServerForASite(versionNumber, null, needsExactVersionMatch, null);
            }
            catch (ServerHasNotBeenFoundException)
            {
            }
            if (miniServer != null)
            {
                return(miniServer);
            }
            try
            {
                ServersCache.CacheLockForServersDictionary.EnterReadLock();
                miniServer = ServersCache.FindMiniServerInListWithoutAffinity(ServersCache.ServersDictionary.Values.ToList <ServersCache.ServerInfo>(), versionNumber, needsExactVersionMatch);
            }
            finally
            {
                ServersCache.CacheLockForServersDictionary.ExitReadLock();
            }
            if (miniServer != null)
            {
                return(miniServer);
            }
            MiniServer oneMailboxServerForASite = ServersCache.GetOneMailboxServerForASite(null, versionNumber, needsExactVersionMatch);

            ServersCache.UpdateMiniServerIntoCache(oneMailboxServerForASite);
            return(oneMailboxServerForASite);
        }
Example #2
0
        private static MiniServer FindAndReturnMiniServerFromCacheForASite(ADObjectId siteId, int versionNumber, string identifier, bool needsExactVersionMatch)
        {
            int        startIndex = -1;
            int        endIndex   = -1;
            MiniServer miniServer = null;

            if (ServersCache.SiteToServersDictionary.ContainsKey(siteId))
            {
                try
                {
                    ServersCache.CacheLockForSiteToServersDictionary.EnterReadLock();
                    List <ServersCache.ServerInfo> list = ServersCache.SiteToServersDictionary[siteId];
                    if (ServersCache.IsLocalSite(siteId))
                    {
                        if (DateTime.UtcNow - ServersCache.LastRefreshTimeForLocalSiteCache > ServersCache.RefreshInterval)
                        {
                            miniServer = null;
                        }
                        else
                        {
                            bool flag = ServersCache.TryCalculateStartAndEndIndex(list, versionNumber, needsExactVersionMatch, out startIndex, out endIndex);
                            if (flag)
                            {
                                int index = ServersCache.GenerateIndexOfServer(startIndex, endIndex, identifier);
                                miniServer = list[index].MiniServer;
                            }
                        }
                    }
                    else
                    {
                        miniServer = ServersCache.FindMiniServerInListWithoutAffinity(list, versionNumber, needsExactVersionMatch);
                    }
                    if (miniServer == null)
                    {
                        ServersCache.Tracer.TraceError <int>(0L, "ServersCache: No server with the version number {0} in the cache.", versionNumber);
                    }
                    return(miniServer);
                }
                finally
                {
                    ServersCache.CacheLockForSiteToServersDictionary.ExitReadLock();
                }
            }
            return(null);
        }