public void CompleteSession( string id, byte[] newState, IList <TaskMessage> newMessages, TaskMessage continuedAsNewMessage) { lock (this.thisLock) { TaskSession taskSession = this.lockedSessionQueue.Find((ts) => string.Equals(ts.Id, id, StringComparison.InvariantCultureIgnoreCase)); if (taskSession == null) { // TODO : throw proper lock lost exception (AFFANDAR) throw new InvalidOperationException("Lock lost"); } this.lockedSessionQueue.Remove(taskSession); // make the required updates to the session foreach (TaskMessage tm in taskSession.LockTable) { taskSession.Messages.Remove(tm); } taskSession.LockTable.Clear(); taskSession.SessionState = newState; if (newState != null) { this.sessionQueue.Add(taskSession); } foreach (TaskMessage m in newMessages) { SendMessage(m); } if (continuedAsNewMessage != null) { SendMessage(continuedAsNewMessage); } } }
public void DropSession(string id) { lock (this.thisLock) { TaskSession taskSession = this.lockedSessionQueue.Find((ts) => string.Equals(ts.Id, id, StringComparison.InvariantCultureIgnoreCase)); if (taskSession == null) { return; } if (this.sessionQueue.Contains(taskSession)) { this.sessionQueue.Remove(taskSession); } else if (this.lockedSessionQueue.Contains(taskSession)) { this.lockedSessionQueue.Remove(taskSession); } } }
public void AbandonSession(string id) { lock (this.thisLock) { TaskSession taskSession = this.lockedSessionQueue.Find((ts) => string.Equals(ts.Id, id, StringComparison.InvariantCultureIgnoreCase)); if (taskSession == null) { // TODO : throw proper lock lost exception (AFFANDAR) throw new InvalidOperationException("Lock lost"); } this.lockedSessionQueue.Remove(taskSession); // TODO : note that this we are adding to the tail of the queue rather than head, which is what sbus would actually do (AFFANDAR) // doesn't really matter though in terms of semantics this.sessionQueue.Add(taskSession); // unlock all messages taskSession.LockTable.Clear(); } }
/// <inheritdoc /> public async Task <TaskOrchestrationWorkItem> LockNextTaskOrchestrationWorkItemAsync( TimeSpan receiveTimeout, CancellationToken cancellationToken) { TaskSession taskSession = await this._OrchestratorQueue.AcceptSessionAsync(receiveTimeout, CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, this._CancellationTokenSource.Token).Token); if (taskSession == null) { return(null); } var wi = new TaskOrchestrationWorkItem { NewMessages = taskSession.Messages.ToList(), InstanceId = taskSession.Id, LockedUntilUtc = DateTime.UtcNow.AddMinutes(5), OrchestrationRuntimeState = DeserializeOrchestrationRuntimeState(taskSession.SessionState) ?? new OrchestrationRuntimeState(), }; return(wi); }