/// <summary> /// The constructor of this class.</summary> public CommonStartInfo(AgentType configuration) { this._configuration = configuration; // Get the selected connection, if no connection is enabled it is an error this._enabledConnection = configuration.getEnabledConnection(); if (this._enabledConnection == null) { LOGGER.Error("No selected connection in the configuration. Exiting ..."); Environment.Exit(0); } else { LOGGER.Info("Selected connection " + this._enabledConnection.GetType().Name); } // The list of jvm options (default + user defined) List <string> mergedJvmOptionsList = new List <string>(); // Add default parameters this._enabledConnection.fillDefaultJvmOptions(mergedJvmOptionsList, this._configuration.config.proactiveHome); // Add user defined if (this._configuration.config.jvmParameters != null) { mergedJvmOptionsList.AddRange(this._configuration.config.jvmParameters); } this._jvmOptions = mergedJvmOptionsList.ToArray(); // The system env variable must not be null otherwise the delay is not enabled string value = System.Environment.GetEnvironmentVariable("PA_AGENT_RUNTIME_START_DELAY", EnvironmentVariableTarget.Machine); if (value != null) { if (!Int32.TryParse(value, out this._runtimeStartDelayInMs)) { LOGGER.Warn("Unable to parse the runtime start delay using default value " + this._runtimeStartDelayInMs + " ms"); } else { this._runtimeStartDelayEnabled = true; LOGGER.Info("Runtime start delay is set to " + this._runtimeStartDelayInMs + " ms"); } } this._cpuLimiterEnabled = !(configuration.isAlwaysAvailable() && configuration.config.maxCpuUsage == 100); }
// The constructor should be called only during starting the service public ExecutorsManager(AgentType configuration) { // The configuration specifies the number of executors int nbProcesses = configuration.config.nbRuntimes == 0 ? 1 : configuration.config.nbRuntimes; LOGGER.Info("Creating " + nbProcesses + " executors"); // Get the runtime common start info shared between all executors CommonStartInfo commonStartInfo = new CommonStartInfo(configuration); // Create as many executors with a unique rank as specified in the configuration this.proActiveRuntimeExecutors = new List <ProActiveRuntimeExecutor>(nbProcesses); for (int rank = 0; rank < nbProcesses; rank++) { ProActiveRuntimeExecutor executor = new ProActiveRuntimeExecutor(commonStartInfo, rank); this.proActiveRuntimeExecutors.Add(executor); } // Create the start/stop timers for scheduled events this.startTimers = new List <Timer>(); this.stopTimers = new List <Timer>(); // If always available simply invoke start method with the stop time at max value if (configuration.isAlwaysAvailable()) { LOGGER.Info("Using always available planning"); this.mySendStartAction(new StartActionInfo( commonStartInfo.enabledConnection, DateTime.MaxValue, commonStartInfo.configuration.config.processPriority, commonStartInfo.configuration.config.maxCpuUsage, commonStartInfo.configuration.config.nbWorkers)); } else { // Fix the current time (usefull when there is a lot of events) DateTime currentFixedTime = DateTime.Now; int currentDayOfWeek = (int)currentFixedTime.DayOfWeek; foreach (CalendarEventType cEvent in configuration.events) { // for each calendar event we calculate remaining time to start and stop service // and according to that register timers // we provide the day of the week to present start time // the algorithm to count next start is as follows: // 1. how many days are to start action // 2. we add this amount to the current date // 3. we create time event that will be the exact start time (taking year, month and // day from the current date and other fields from configuration // 4. we keep duration of task // 5. we count due time for beginning and stopping the task // 6. if time is negative, we move it into next week (to avoid waiting for past events) int eventDayOfWeek = (int)cEvent.start.day; int daysAhead = dayDifference(currentDayOfWeek, eventDayOfWeek); DateTime startTime = currentFixedTime.AddDays(daysAhead); // Absolute start time DateTime absoluteStartTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, cEvent.start.hour, cEvent.start.minute, cEvent.start.second); // Delay to wait until start TimeSpan delayUntilStart = absoluteStartTime - currentFixedTime; // Get the time span duration TimeSpan duration = new TimeSpan(cEvent.duration.days, cEvent.duration.hours, cEvent.duration.minutes, cEvent.duration.seconds); // Delay to wait until stop TimeSpan delayUntilStop = delayUntilStart.Add(duration); // Absolute stop time DateTime absoluteStopTime = absoluteStartTime.Add(duration); // Check if we need to start immidiately bool startNow = (delayUntilStart <TimeSpan.Zero && delayUntilStop> TimeSpan.Zero); if (delayUntilStart < TimeSpan.Zero) { delayUntilStart = delayUntilStart.Add(WEEK_DELAY); } if (delayUntilStop < TimeSpan.Zero) { delayUntilStop = delayUntilStop.Add(WEEK_DELAY); } StartActionInfo startInfo = new StartActionInfo( commonStartInfo.enabledConnection, absoluteStopTime, cEvent.config.processPriority, cEvent.config.maxCpuUsage, cEvent.config.nbWorkers); LOGGER.Info("Loading weekly event [" + absoluteStartTime.DayOfWeek + ":" + absoluteStartTime.ToString(Constants.DATE_FORMAT) + "] -> [" + absoluteStopTime.DayOfWeek + ":" + absoluteStopTime.ToString(Constants.DATE_FORMAT) + "]"); // After dueStart milliseconds this timer will invoke only once per week the callback Timer startT = new Timer(new TimerCallback(mySendStartAction), startInfo, delayUntilStart, WEEK_DELAY); this.startTimers.Add(startT); // After dueStop milliseconds this timer will invoke only once per week the callback Timer stopT = new Timer(new TimerCallback(mySendStopAction), null, delayUntilStop, WEEK_DELAY); this.stopTimers.Add(stopT); if (startNow) { this.mySendStartAction(startInfo); } } } }