Ejemplo n.º 1
0
        /// <summary>
        /// Handle Task close event.
        /// Cancel the CancellationToken for data reading operation, then waiting for the signal from Call method. 
        /// </summary>
        /// <param name="closeEvent"></param>
        /// <param name="cancellationTokenSource"></param>
        internal void HandleEvent(ICloseEvent closeEvent, CancellationTokenSource cancellationTokenSource)
        {
            cancellationTokenSource.Cancel();
            _waitToCloseEvent.Wait();

            if (closeEvent.Value.IsPresent())
            {
                Logger.Log(Level.Info, "The task received close event with message: {0}.", Encoding.UTF8.GetString(closeEvent.Value.Value));
            }
            else
            {
                Logger.Log(Level.Info, "The task received close event with no message.");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handle Task close event.
        /// Cancel the CancellationToken for data reading operation, then waiting for the signal from Call method.
        /// </summary>
        /// <param name="closeEvent"></param>
        /// <param name="cancellationTokenSource"></param>
        internal void HandleEvent(ICloseEvent closeEvent, CancellationTokenSource cancellationTokenSource)
        {
            cancellationTokenSource.Cancel();
            _waitToCloseEvent.Wait();

            if (closeEvent.Value.IsPresent())
            {
                Logger.Log(Level.Info, "The task received close event with message: {0}.", Encoding.UTF8.GetString(closeEvent.Value.Value));
            }
            else
            {
                Logger.Log(Level.Info, "The task received close event with no message.");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handle Task close event.
        /// Set _shouldCloseTask to 1 so that to inform the task to stop at the end of the current iteration.
        /// Then waiting for the signal from Call method. Either it is signaled or after _enforceCloseTimeoutMilliseconds,
        /// If the closed event is sent from driver, checks if the _waitToCloseEvent has been signaled. If not, throw
        /// IMRUTaskSystemException to enforce the task to stop.
        /// </summary>
        /// <param name="closeEvent"></param>
        internal void HandleEvent(ICloseEvent closeEvent)
        {
            Interlocked.Exchange(ref _shouldCloseTask, 1);
            var taskSignaled = _waitToCloseEvent.Wait(TimeSpan.FromMilliseconds(_enforceCloseTimeoutMilliseconds));

            if (closeEvent.Value.IsPresent())
            {
                var msg = Encoding.UTF8.GetString(closeEvent.Value.Value);
                if (msg.Equals(TaskManager.CloseTaskByDriver))
                {
                    Logger.Log(Level.Info, "The task received close event with message: {0}.", msg);

                    if (!taskSignaled)
                    {
                        throw new IMRUTaskSystemException(TaskManager.TaskKilledByDriver);
                    }
                }
            }
            else
            {
                Logger.Log(Level.Warning, "The task received close event with no message.");
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Task close handler. Call TaskCloseCoordinator to handle the event.
 /// </summary>
 /// <param name="closeEvent"></param>
 public void OnNext(ICloseEvent closeEvent)
 {
     _taskCloseCoordinator.HandleEvent(closeEvent);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Task close handler. Calls TaskCloseCoordinator to handle the event.
 /// </summary>
 /// <param name="closeEvent"></param>
 public void OnNext(ICloseEvent closeEvent)
 {
     _taskCloseCoordinator.HandleEvent(closeEvent, _cancellationSource);
 }
Ejemplo n.º 6
0
 public void OnNext(ICloseEvent value)
 {
     Dispose();
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Handler for CloseEvent.
 /// </summary>
 /// <param name="closeEvent"></param>
 public void OnNext(ICloseEvent closeEvent)
 {
     Log.Log(Level.Info, "NoopTask.TaskCloseHandler.OnNext() invoked.");
     Dispose();
 }