Ejemplo n.º 1
0
 public void AddTask(AcaciaTask task)
 {
     Interlocked.Increment(ref Statistics.StartedTasks);
     Tracer?.OnTaskAdding(task);
     EnqueueTask(task);
     Tracer?.OnTaskAdded(task);
 }
 private void Worker()
 {
     while (!_tasks.IsCompleted)
     {
         AcaciaTask task = _tasks.Take();
         PerformTask(task);
     }
 }
Ejemplo n.º 3
0
 public static void Task(AcaciaTask task, bool synchronous = false)
 {
     if (synchronous)
     {
         task.Execute();
     }
     else
     {
         Executor.AddTask(task);
     }
 }
Ejemplo n.º 4
0
 protected void PerformTask(AcaciaTask task)
 {
     try
     {
         task.Execute();
     }
     finally
     {
         Interlocked.Increment(ref Statistics.FinishedTasks);
     }
 }
        /// <summary>
        /// Adds a task to be executed.
        /// </summary>
        /// <param name="name">The name, for debugging and logging.</param>
        /// <param name="action">The action to execute</param>
        override protected void EnqueueTask(AcaciaTask task)
        {
            if (_init == InitState.Uninitialised)
            {
                _init = InitState.InitialisedIdle;
                // Set up the idle handler
                Application.Idle += IdleHandler;
            }

            // Enqueue the task
            _tasks.Enqueue(task);
        }
 /// <summary>
 /// Checks if any tasks can be executed and executes them if possible.
 /// </summary>
 private void PollTasks()
 {
     if (_tasks.Count > 0)
     {
         Stopwatch timer = new Stopwatch(); timer.Start();
         do
         {
             AcaciaTask task = _tasks.Dequeue();
             Logger.Instance.Trace(task.Id, "Beginning task");
             PerformTask(task);
             Logger.Instance.Info(task.Id, "Ending task: {0}ms", timer.ElapsedMilliseconds);
             // Execute another task if available and we haven't taken too long.
         } while (_tasks.Count > 0 && timer.ElapsedMilliseconds < 50);
     }
 }
Ejemplo n.º 7
0
        public static void Task(AcaciaTask task, bool synchronous = false)
        {
            task.TaskId = Interlocked.Increment(ref _taskId);

            Logger.Instance.Trace(typeof(Tasks), "TASK added: {0}", task);
            if (synchronous)
            {
                Logger.Instance.Trace(typeof(Tasks), "TASK exec synchronous 1: {0}", task);
                task.Execute();
                Logger.Instance.Trace(typeof(Tasks), "TASK exec synchronous 2: {0}", task);
            }
            else
            {
                Executor.AddTask(task);
            }
        }
Ejemplo n.º 8
0
 protected void PerformTask(AcaciaTask task)
 {
     try
     {
         Tracer?.OnTaskExecuting(task);
         task.Execute();
     }
     catch (Exception e)
     {
         Tracer?.OnTaskFailed(task, e);
         throw e;
     }
     finally
     {
         Tracer?.OnTaskExecuted(task);
         Interlocked.Increment(ref Statistics.FinishedTasks);
     }
 }
Ejemplo n.º 9
0
 private void Worker()
 {
     try
     {
         while (!_tasks.IsCompleted)
         {
             Logger.Instance.Trace(this, "Take task 1");
             AcaciaTask task = _tasks.Take();
             Logger.Instance.Trace(this, "Take task 2: {0}", task);
             PerformTask(task);
             Logger.Instance.Trace(this, "Take task 3: {0}", task);
         }
         Logger.Instance.Debug(this, "Worker completed");
     }
     catch (Exception e)
     {
         Logger.Instance.Warning(this, "Worker failure: {0}", e);
     }
 }
Ejemplo n.º 10
0
 protected override void EnqueueTask(AcaciaTask task)
 {
     Logger.Instance.Trace(this, "EnqueueTask 1: {0}", task);
     _tasks.Add(task);
     Logger.Instance.Trace(this, "EnqueueTask 2: {0}", task);
 }
Ejemplo n.º 11
0
 internal void OnTaskAdded(AcaciaTask task)
 {
     GetTaskInfo(task)?.Event(TaskInfo.EventType.Added);
 }
Ejemplo n.º 12
0
 protected override void EnqueueTask(AcaciaTask task)
 {
     PerformTask(task);
 }
Ejemplo n.º 13
0
 public void AddTask(AcaciaTask task)
 {
     Interlocked.Increment(ref Statistics.StartedTasks);
     EnqueueTask(task);
 }
Ejemplo n.º 14
0
 abstract protected void EnqueueTask(AcaciaTask task);
Ejemplo n.º 15
0
 internal void OnTaskFailed(AcaciaTask task, Exception e)
 {
     GetTaskInfo(task)?.SetFailed(e);
 }
Ejemplo n.º 16
0
 internal void OnTaskExecuting(AcaciaTask task)
 {
     GetTaskInfo(task)?.Event(TaskInfo.EventType.Started);
 }
Ejemplo n.º 17
0
 internal void OnTaskExecuted(AcaciaTask task)
 {
     GetTaskInfo(task)?.Event(TaskInfo.EventType.Finished);
 }
Ejemplo n.º 18
0
 public TaskInfo(AcaciaTask task)
 {
     this._task = task;
 }
 protected override void EnqueueTask(AcaciaTask task)
 {
     _tasks.Add(task);
 }
Ejemplo n.º 20
0
 private TaskInfo GetTaskInfo(AcaciaTask task)
 {
     return(_all.GetOrAdd(task.TaskId, new TaskInfo(task)));
 }
Ejemplo n.º 21
0
 internal void OnTaskAdding(AcaciaTask task)
 {
     GetTaskInfo(task)?.Event(TaskInfo.EventType.Created);
 }