Example #1
0
 public void OnNext(IRunningTask value)
 {
     Logger.Log(Level.Info, "Task running: " + value.Id);
     if (_disposeMessage.Equals(NoMessage))
     {
         value.Dispose();
     }
     else
     {
         value.Dispose(Encoding.UTF8.GetBytes(_disposeMessage));
     }
 }
Example #2
0
        public void OnNext(IRunningTask task)
        {
            Log.Log(Level.Info,
                    "TaskRuntime: {0} expect {1}",
                    task.Id, _taskId);

            if (!_taskId.Equals(task.Id))
            {
                throw new DriverSideFailure($"Task ID {task.Id} not equal expected ID {_taskId}");
            }

            switch (_failTaskName)
            {
            case "FailTaskMsg":
                Log.Log(Level.Info, "TaskRuntime: Send message: {0}", task);
                task.Send(new byte[0]);
                break;

            case "FailTaskSuspend":
                Log.Log(Level.Info, "TaskRuntime: Suspend: {0}", task);
                task.Suspend();
                break;

            case "FailTaskStop":
            case "FailTaskClose":
                Log.Log(Level.Info, "TaskRuntime: Stop/Close: {0}", task);
                task.Dispose();
                break;

            default:
                break;
            }
        }
Example #3
0
 public void OnNext(IRunningTask value)
 {
     if (value.Id == TaskId)
     {
         value.Dispose();
     }
 }
Example #4
0
        public void OnNext(Alarm time)
        {
            CheckMsgOrder(time);
            switch (_state)
            {
            case DriverState.SendMsg:
                Log.Log(Level.Info, "Send message to task {0}", _task.Id);
                _task.Send(HelloStringByteArray);
                break;

            case DriverState.Suspend:
                Log.Log(Level.Info, "Suspend task {0}", _task.Id);
                _task.Suspend();
                break;

            case DriverState.Close:
                Log.Log(Level.Info, "Close task {0}", _task.Id);
                _task.Dispose();
                break;

            default:
                Log.Log(Level.Warning, "Unexpected state at AlarmHandler: {0}", _state);
                throw new DriverSideFailure("Unexpected state: " + _state);
            }
        }
Example #5
0
            /// <summary>
            /// Task1: Close task and expect it to return from Call()
            /// Task2: Close the task and expect it throw exception
            /// Task3: Let context Dispose to close a running task and make sure the task is disposed
            /// </summary>
            /// <param name="value"></param>
            public void OnNext(IRunningTask value)
            {
                Logger.Log(Level.Info, "Task running: " + value.Id);
                switch (value.Id)
                {
                case TaskId + "1":
                    value.Dispose(Encoding.UTF8.GetBytes(ExitByReturn));
                    break;

                case TaskId + "2":
                    value.Dispose(Encoding.UTF8.GetBytes(ExitByException));
                    break;

                case TaskId + "3":
                    value.ActiveContext.Dispose();
                    break;
                }
            }
Example #6
0
        /// <summary>
        /// This method is called when receiving an IRunningTask event but system is either in shutting down or fail.
        /// In this case, the task should not be added in Running Tasks yet.
        /// Change the task state to TaskRunning if it is still in TaskSubmitted state
        /// Closes the IRunningTask
        /// Then move the task state to WaitingTaskToClose
        /// Throw IMRUSystemException if runningTask is null or the running task is already added in the running task collection
        /// </summary>
        internal void RecordRunningTaskDuringSystemFailure(IRunningTask runningTask, string closeMessage)
        {
            if (runningTask == null)
            {
                Exceptions.Throw(new IMRUSystemException("RunningTask is null."), Logger);
            }

            if (_runningTasks.ContainsKey(runningTask.Id))
            {
                var msg = string.Format(CultureInfo.InvariantCulture, "The task [{0}] is already in running tasks.", runningTask.Id);
                Exceptions.Throw(new IMRUSystemException(msg), Logger);
            }

            UpdateState(runningTask.Id, TaskStateEvent.RunningTask);
            runningTask.Dispose(Encoding.UTF8.GetBytes(closeMessage));
            UpdateState(runningTask.Id, TaskStateEvent.WaitingTaskToClose);
        }
Example #7
0
            /// <summary>
            /// Close the first two tasks and send message to the 3rd and 4th tasks
            /// </summary>
            /// <param name="value"></param>
            public void OnNext(IRunningTask value)
            {
                Logger.Log(Level.Info, "Task running: " + value.Id);
                switch (value.Id)
                {
                case TaskId + "1":
                    value.Dispose(Encoding.UTF8.GetBytes(KillTaskCommandFromDriver));
                    break;

                case TaskId + "2":
                case TaskId + "3":
                    value.Send(Encoding.UTF8.GetBytes(CompleteTaskCommandFromDriver));
                    break;

                default:
                    throw new Exception("It should not be reached.");
                }
            }
Example #8
0
        /// <summary>
        /// This method is called when receiving an IRunningTask event but system is either in shutting down or fail.
        /// In this case, the task should not be added in Running Tasks yet.
        /// Change the task state to TaskRunning if it is still in TaskSubmitted state
        /// Closes the IRunningTask 
        /// Then move the task state to WaitingTaskToClose
        /// Throw IMRUSystemException if runningTask is null or the running task is already added in the running task collection
        /// </summary>
        /// <param name="runningTask"></param>
        /// <param name="closeMessage"></param>
        internal void RecordRunningTaskDuringSystemFailure(IRunningTask runningTask, string closeMessage)
        {
            if (runningTask == null)
            {
                Exceptions.Throw(new IMRUSystemException("RunningTask is null."), Logger);
            }

            if (_runningTasks.ContainsKey(runningTask.Id))
            {
                var msg = string.Format(CultureInfo.InvariantCulture, "The task [{0}] is already in running tasks.", runningTask.Id);
                Exceptions.Throw(new IMRUSystemException(msg), Logger);
            }

            UpdateState(runningTask.Id, TaskStateEvent.RunningTask);
            runningTask.Dispose(Encoding.UTF8.GetBytes(closeMessage));
            UpdateState(runningTask.Id, TaskStateEvent.WaitingTaskToClose);
        }