/** * Notifies every registered listener that a task execution has successfully * completed. * * @param executor * The task executor. */ internal void notifyTaskSucceeded(TaskExecutor executor) { if (executor == null) { throw new ArgumentNullException("executor", "executor is null."); } lock (listeners) { int size = listeners.Count; for (int i = 0; i < size; i++) { SchedulerListener l = (SchedulerListener)listeners[i]; l.TaskSucceeded(executor); } } }
/** * It waits until the given task executor is dead. It is similar to * {@link TaskExecutor#join()}, but this one avoids * {@link ThreadInterruptedException} instances. * * @param executor * The task executor. */ private void tillExecutorDies(TaskExecutor executor) { if (executor == null) { throw new ArgumentNullException("executor", "executor is null."); } bool dead = false; do { try { executor.Join(); dead = true; } catch (ThreadInterruptedException e) { ; } } while (!dead); }
/// <summary> /// /// </summary> /// <param name="executor"></param> public MyContext(TaskExecutor executor) { this.cTaskExecutor = executor; }
/** * Builds the executor. * * @param scheduler * The scheduler whose this executor belongs to. * @param task * The task that has to be executed. */ internal TaskExecutor(Scheduler scheduler, Task task) { this.scheduler = scheduler; this.task = task; this.context = new MyContext(this); this.myself = this; }
/// <summary> /// /// </summary> /// <param name="executor"></param> public Runner(TaskExecutor executor) { this.cTaskExecutor = executor; }
/** * It waits until the given task executor is dead. It is similar to * {@link TaskExecutor#join()}, but this one avoids * {@link ThreadInterruptedException} instances. * * @param executor * The task executor. */ private void tillExecutorDies(TaskExecutor executor) { if (executor == null) throw new ArgumentNullException("executor", "executor is null."); bool dead = false; do { try { executor.Join(); dead = true; } catch (ThreadInterruptedException e) { ; } } while (!dead); }
/** * Notifies every registered listener that a task execution has failed due * to an uncaught exception. * * @param executor * The task executor. * @param exception * The exception. */ internal void notifyTaskFailed(TaskExecutor executor, ThrowableException exception) { if (executor == null) throw new ArgumentNullException("executor", "executor is null."); if (exception == null) throw new ArgumentNullException("exception", "exception is null."); lock (listeners) { int size = listeners.Count; if (size > 0) { for (int i = 0; i < size; i++) { SchedulerListener l = (SchedulerListener)listeners[i]; l.TaskFailed(executor, exception); } } else { // Logs on console if no one has been notified about it. Console.WriteLine(exception.ToString()); } } }
/** * Notifies every registered listener that a task execution has successfully * completed. * * @param executor * The task executor. */ internal void notifyTaskSucceeded(TaskExecutor executor) { if (executor == null) throw new ArgumentNullException("executor", "executor is null."); lock (listeners) { int size = listeners.Count; for (int i = 0; i < size; i++) { SchedulerListener l = (SchedulerListener)listeners[i]; l.TaskSucceeded(executor); } } }
/** * This method is called by a task executor to notify that the execution is * completed. * * @param executor * The executor which has completed its task. */ internal void notifyExecutorCompleted(TaskExecutor executor) { if (executor == null) throw new ArgumentNullException("executor", "executor is null."); lock (executors) { executors.Remove(executor); } }
/** * Starts the given task within a task executor. * * @param task * The task. * @return The spawned task executor. */ internal TaskExecutor spawnExecutor(Task task) { if (task == null) throw new ArgumentNullException("task", "task is null."); TaskExecutor e = new TaskExecutor(this, task); lock (executors) { executors.Add(e); } e.Start(daemon); return e; }