Esempio n. 1
0
        /// <summary>
        /// Scale Up by one unit
        /// </summary>
        /// <param name="factory">Factory</param>
        /// <param name="configuration">Configuration</param>
        /// <param name="taskName">Task Name</param>
        public virtual void ScaleUp(ITaskFactory <T> factory, T configuration, string taskName)
        {
            if (null == factory)
            {
                throw new ArgumentNullException("factory");
            }
            if (string.IsNullOrWhiteSpace(taskName))
            {
                throw new ArgumentException("taskName");
            }

            Trace.TraceInformation("Scaling up: '{0}'.", taskName);

            var unit = new RoleTaskManager <T>(factory);

            var success = unit.OnStart();

            if (success)
            {
                unit.Run();

                if (units.TryAdd(unit))
                {
                    Trace.TraceInformation("Scaled up: '{0}'.", taskName);
                }
                else
                {
                    unit.Dispose();

                    Trace.TraceWarning("Failed to add scale unit: '{0}'.", taskName);
                }
            }
            else
            {
                unit.Dispose();

                Trace.TraceWarning("Failed to start scale unit: '{0}'.", taskName);
            }
        }