示例#1
0
        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);
                }
            }
        }
示例#2
0
        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);
                }
            }
        }
示例#3
0
        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);
            }

            TaskOrchestrationWorkItem wi = new TaskOrchestrationWorkItem()
            {
                NewMessages               = taskSession.Messages,
                InstanceId                = taskSession.Id,
                LockedUntilUtc            = DateTime.UtcNow.AddMinutes(5),
                OrchestrationRuntimeState =
                    this.DeserializeOrchestrationRuntimeState(taskSession.SessionState) ??
                    new OrchestrationRuntimeState(),
            };

            return(wi);
        }