public void TestCompositeTaskRunner() { int attempts = 0; CompositeTaskRunner runner = new CompositeTaskRunner(); CountingTask task1 = new CountingTask("task1", 100); CountingTask task2 = new CountingTask("task2", 200); runner.AddTask(task1); runner.AddTask(task2); runner.Wakeup(); while (attempts++ != 10) { Thread.Sleep(1000); if (task1.Count == 100 && task2.Count == 200) { break; } } Assert.IsTrue(task1.Count == 100); Assert.IsTrue(task2.Count == 200); runner.RemoveTask(task1); runner.RemoveTask(task2); }
private void ReadCheck() { var now = DateTime.Now; var elapsed = now - _lastReadCheckTime; if (!AllowReadCheck(elapsed)) { return; } _lastReadCheckTime = now; if (_inRead.Value || _failed.Value || _asyncErrorTask == null) { if (Tracer.IsWarnEnabled) { Tracer.Warn($"InactivityMonitor[{_instanceId}]: A receive is in progress or already failed."); } return; } if (!_commandReceived.Value) { if (Tracer.IsWarnEnabled) { Tracer.Warn($"InactivityMonitor[{_instanceId}]: No message received since last read check! Sending an InactivityException!"); } _asyncErrorTask.IsPending = true; _asyncTasks.Wakeup(); } else { _commandReceived.Value = false; } }
/// <summary> /// Check the write to the broker /// </summary> public void WriteCheck() { if (this.inWrite.Value || this.failed.Value) { Tracer.DebugFormat("InactivityMonitor[{0}]: is in write or already failed.", instanceId); return; } CompositeTaskRunner taskRunner = this.asyncTasks; if (!commandSent.Value) { Tracer.DebugFormat("InactivityMonitor[{0}]: No Message sent since last write check. Sending a KeepAliveInfo.", instanceId); if (null != this.asyncWriteTask) { this.asyncWriteTask.IsPending = true; } if (this.monitorStarted.Value && taskRunner != null) { taskRunner.Wakeup(); } } else { Tracer.DebugFormat("InactivityMonitor[{0}]: Message sent since last write check. Resetting flag.", instanceId); } commandSent.Value = false; }
/// <summary> /// Check the write to the broker /// </summary> private void WriteCheck() { if (_inWrite.Value || _failed.Value) { Tracer.Warn($"InactivityMonitor[{_instanceId}]: is in write or already failed."); return; } if (!_commandSent.Value) { Tracer.Warn($"InactivityMonitor[{_instanceId}]: No Message sent since last write check. Sending a KeepAliveInfo."); _asyncWriteTask.IsPending = true; _asyncTasks.Wakeup(); } _commandSent.Value = false; }
public void ReadCheck() { DateTime now = DateTime.Now; TimeSpan elapsed = now - this.lastReadCheckTime; CompositeTaskRunner taskRunner = this.asyncTasks; if (!AllowReadCheck(elapsed)) { Tracer.Debug("InactivityMonitor[" + instanceId + "]: A read check is not currently allowed."); return; } this.lastReadCheckTime = now; if (this.inRead.Value || this.failed.Value) { Tracer.DebugFormat("InactivityMonitor[{0}]: A receive is in progress or already failed.", instanceId); return; } if (!commandReceived.Value) { Tracer.DebugFormat("InactivityMonitor[{0}]: No message received since last read check! Sending an InactivityException!", instanceId); if (null != this.asyncErrorTask) { this.asyncErrorTask.IsPending = true; } if (this.monitorStarted.Value && taskRunner != null) { taskRunner.Wakeup(); } } else { commandReceived.Value = false; } }