Exemple #1
0
        private static void CheckMemoryAvailable()
        {
            ApplicationServiceSettings settings = new ApplicationServiceSettings();

            if (settings.MinimumFreeMemoryMB <= 0)
            {
                return;
            }

            bool memoryAvailable = SystemResources.GetAvailableMemory(SizeUnits.Megabytes) > settings.MinimumFreeMemoryMB;

            if (!memoryAvailable)
            {
                string error = String.Format(
                    "Application server out of resources.  Minimum free memory not available ({0}MB required, {1}MB available).",
                    settings.MinimumFreeMemoryMB,
                    SystemResources.GetAvailableMemory(SizeUnits.Megabytes));

                Platform.Log(LogLevel.Warn, error);
                throw new FaultException <OutOfResourceFault>(new OutOfResourceFault {
                    ErrorMessage = error
                });
            }
        }
Exemple #2
0
        /// <summary>
        /// Ensure number of applicatin
        /// </summary>
        private static void CheckNumberOfApplications()
        {
            ApplicationServiceSettings settings = new ApplicationServiceSettings();

            if (settings.MaximumSimultaneousApplications <= 0)
            {
                return;
            }

            Cache cache = Cache.Instance;

            lock (cache.SyncLock)
            {
                // Note: because app is added into the cache ONLY when it has successfully started, there's a small chance that
                // this check will fail and # of app actually will exceed the max allowed. Decided to live with it for now.
                if (cache.Count >= settings.MaximumSimultaneousApplications)
                {
                    Platform.Log(LogLevel.Warn, "Refuse to start: Max # of Simultaneous Applications ({0}) has been reached.", settings.MaximumSimultaneousApplications);
                    throw new FaultException <OutOfResourceFault>(new OutOfResourceFault {
                        ErrorMessage = SR.MessageMaxApplicationsAllowedExceeded
                    });
                }
            }
        }