/** * Adds a pattern and a task to the collector. * * @param pattern * The scheduling pattern. * @param task * The task. * @return An ID for the scheduled operation. */ public string Add(SchedulingPattern pattern, Task task) { string id = GUIDGenerator.Generate(); lock (patterns) { patterns.Add(id, new KeyValuePair <SchedulingPattern, Task>(pattern, task)); } return(id); }
/** * Updates a scheduling pattern in the collector. * * @param id * The ID of the scheduled couple. */ public void Update(string id, SchedulingPattern pattern) { KeyValuePair <SchedulingPattern, Task> v; lock (patterns) { if (patterns.TryGetValue(id, out v)) { patterns[id] = new KeyValuePair <SchedulingPattern, Task>(pattern, v.Value); } } }
/** * This method schedules a task execution. * * @param schedulingPattern * The scheduling pattern for the task. * @param task * The task, as a plain Runnable object. * @return The task auto-generated ID assigned by the scheduler. This ID can * be used later to reschedule and deschedule the task, and also to * retrieve informations about it. * @since 2.0 */ public string schedule(SchedulingPattern schedulingPattern, Task task) { if (schedulingPattern == null) { throw new ArgumentNullException("schedulingPattern", "schedulingPattern is null."); } if (task == null) { throw new ArgumentNullException("task", "task is null."); } return(memoryTaskCollector.Add(schedulingPattern, task)); }
/** * This method changes the scheduling pattern of a task. * * @param id * The ID assigned to the previously scheduled task. * @param schedulingPattern * The new scheduling pattern for the task. * @since 2.0 */ public void reschedule(string id, SchedulingPattern schedulingPattern) { if (String.IsNullOrEmpty(id)) { throw new ArgumentException("id is null or empty.", "id"); } if (schedulingPattern == null) { throw new ArgumentNullException("schedulingPattern", "schedulingPattern is null."); } memoryTaskCollector.Update(id, schedulingPattern); }
/** * Overrides {@link Thread#run()}. */ public void Run() { //outer: for (int i = 0; i < collectors.Length; i++) { TaskTable taskTable = collectors[i].GetTasks(); int size = taskTable.Size(); for (int j = 0; j < size; j++) { //if (cThread.isInterrupted()) { // goto outer; //} SchedulingPattern pattern = taskTable.GetSchedulingPattern(j); if (pattern.Match(scheduler.getTimeZone(), referenceTimeInMillis)) { Task task = taskTable.GetTask(j); scheduler.spawnExecutor(task); } } } // Notifies completed. scheduler.notifyLauncherCompleted(this); }
/** * Adds a task and an associated scheduling pattern to the table. * * @param pattern * The associated scheduling pattern. * @param task * The task. */ public void Add(SchedulingPattern pattern, Task task) { patterns.Add(new KeyValuePair<SchedulingPattern, Task>(pattern, task)); }
/** * It builds a predictor with the given scheduling pattern and the current * system time as the prediction start time. * * @param schedulingPattern * The pattern on which the prediction will be based. * @since 2.0 */ public Predictor(SchedulingPattern schedulingPattern) : this(schedulingPattern, DateTime.Now) { }
/** * It builds a predictor with the given scheduling pattern and start time. * * @param schedulingPattern * The pattern on which the prediction will be based. * @param start * The start time of the prediction. * @since 2.0 */ public Predictor(SchedulingPattern schedulingPattern, DateTime start) { this.schedulingPattern = schedulingPattern; this.time = start; }
/** * It builds a predictor with the given scheduling pattern and start time. * * @param schedulingPattern * The pattern on which the prediction will be based. * @param start * The start time of the prediction. * @since 2.0 */ public Predictor(SchedulingPattern schedulingPattern, long start) : this(schedulingPattern, new DateTime(start)) { }
/** * This method changes the scheduling pattern of a task. * * @param id * The ID assigned to the previously scheduled task. * @param schedulingPattern * The new scheduling pattern for the task. * @since 2.0 */ public void reschedule(string id, SchedulingPattern schedulingPattern) { if (String.IsNullOrEmpty(id)) throw new ArgumentException("id is null or empty.", "id"); if (schedulingPattern == null) throw new ArgumentNullException("schedulingPattern", "schedulingPattern is null."); memoryTaskCollector.Update(id, schedulingPattern); }
/** * This method schedules a task execution. * * @param schedulingPattern * The scheduling pattern for the task. * @param task * The task, as a plain Runnable object. * @return The task auto-generated ID assigned by the scheduler. This ID can * be used later to reschedule and deschedule the task, and also to * retrieve informations about it. * @since 2.0 */ public string schedule(SchedulingPattern schedulingPattern, Task task) { if (schedulingPattern == null) throw new ArgumentNullException("schedulingPattern", "schedulingPattern is null."); if (task == null) throw new ArgumentNullException("task", "task is null."); return memoryTaskCollector.Add(schedulingPattern, task); }
/** * Adds a task and an associated scheduling pattern to the table. * * @param pattern * The associated scheduling pattern. * @param task * The task. */ public void Add(SchedulingPattern pattern, Task task) { patterns.Add(new KeyValuePair <SchedulingPattern, Task>(pattern, task)); }
/** * Parses a crontab-like line. * * @param table * The table on which the parsed task will be stored, by * side-effect. * @param line * The crontab-like line. * @throws Exception * The supplied line doesn't represent a valid task line. */ public static void parseLine(TaskTable table, string line) { if (string.IsNullOrEmpty(line)) { return; } line = line.Trim(); if (line.Length == 0 || line[0] == '#') { return; } // Detecting the pattern. int size = line.Length; string pattern = null; for (int i = size; i >= 0; i--) { string aux = line.Substring(0, i); if (SchedulingPattern.Validate(aux)) { pattern = aux; break; } } if (pattern == null) { throw new Exception("Invalid cron line: " + line); } line = line.Substring(pattern.Length); size = line.Length; // Splitting the line List <string> splitted = new List <string>(); StringBuilder current = null; bool quotes = false; for (int i = 0; i < size; i++) { char c = line[i]; if (current == null) { if (c == '"') { current = new StringBuilder(); quotes = true; } else if (c > ' ') { current = new StringBuilder(); current.Append(c); quotes = false; } } else { bool closeCurrent; if (quotes) { closeCurrent = (c == '"'); } else { closeCurrent = (c <= ' '); } if (closeCurrent) { if (current != null && current.Length > 0) { string str = current.ToString(); if (quotes) { str = escape(str); } splitted.Add(str); } current = null; } else { current.Append(c); } } } if (current != null && current.Length > 0) { string str = current.ToString(); if (quotes) { str = escape(str); } splitted.Add(str); current = null; } // Analyzing size = splitted.Count; int status = 0; // Status values: // 0 -> fetching environment variables, working directory and channels // 1 -> fetching the command and its arguments string dirString = null; FileInfo stdinFile = null; FileInfo stdoutFile = null; FileInfo stderrFile = null; List <string> envsList = new List <string>(); string command = null; List <string> argsList = new List <string>(); for (int i = 0; i < size; i++) { string tk = (string)splitted[i]; // Check the local status. if (status == 0) { // Environment variables, working directory and channels if (tk.StartsWith("ENV:")) { envsList.Add(tk.Substring(4)); continue; } else if (tk.StartsWith("DIR:")) { dirString = tk.Substring(4); continue; } else if (tk.StartsWith("IN:")) { stdinFile = new FileInfo(tk.Substring(3)); continue; } else if (tk.StartsWith("OUT:")) { stdoutFile = new FileInfo(tk.Substring(4)); continue; } else if (tk.StartsWith("ERR:")) { stderrFile = new FileInfo(tk.Substring(4)); continue; } else { status = 1; } } if (status == 1) { // Command or argument? if (command == null) { command = tk; } else { argsList.Add(tk); } } } // Task preparing. Task task = null; // Command evaluation. if (command == null) { // No command! throw new Exception("Invalid cron line: " + line); } else if (command.StartsWith("dotnet:")) //INFO in cron4net use dotnet mark .NET Type { // Java inner-process. string className = command.Substring(7); if (className.Length == 0) { throw new Exception("Invalid .NET type name on line: " + line); } string methodName; int sep = className.IndexOf('#'); if (sep == -1) { methodName = "Main"; } else { methodName = className.Substring(sep + 1); className = className.Substring(0, sep); if (methodName.Length == 0) { throw new Exception("Invalid .NET method name on line: " + line); } } string[] args = argsList.ToArray(); task = new StaticMethodTask(className, methodName, args); } else { // External command. string[] cmdarray = new string[1 + argsList.Count]; cmdarray[0] = command; for (int i = 0; i < argsList.Count; i++) { cmdarray[i + 1] = argsList[i]; } // Environments. string[] envs = null; size = envsList.Count; if (size > 0) { envs = envsList.ToArray(); } // Working directory. DirectoryInfo dir = null; if (dirString != null) { dir = new DirectoryInfo(dirString); if (!dir.Exists) { throw new Exception( "Invalid cron working directory parameter at line: " + line, new FileNotFoundException(dirString + " doesn't exist or it is not a directory")); } } //TODO ProcessTask //// Builds the task. //ProcessTask process = new ProcessTask(cmdarray, envs, dir); //// Channels. //if (stdinFile != null) //{ // process.setStdinFile(stdinFile); //} //if (stdoutFile != null) //{ // process.setStdoutFile(stdoutFile); //} //if (stderrFile != null) //{ // process.setStderrFile(stderrFile); //} //task = process; } // End. table.Add(new SchedulingPattern(pattern), task); }