Ejemplo n.º 1
0
        private async Task RestoreStateFromPreviousRunsAsync()
        {
            if (this.GetType().IsSubclassOf(typeof(TimeTriggeredAgent)))
            {
                this.Logger.LogMessage("RestoreStateFromPreviousRunsAsync:: Skipping Restore for TimeTriggered Agents");
                return;
            }

            // Restore the signals that haven't been processed yet. Read them from persistent storage and put them into our in memory queue.
            var analysisDetails = await this.signalWaitingToBeProcessedStoreInstance.GetAllValuesAsync(this.CancelToken).ConfigureAwait(false);

            this.Logger.LogMessage("RestoreStateFromPreviousRunsAsync:: Restoring unprocessed Signal Queue. Queue Depth: {0}", analysisDetails.Count);
            foreach (var entry in analysisDetails)
            {
                var queue = this.signalWaitingToBeProcessedMap.GetOrAdd(entry.Key, InsightsUtil.DeSerialize <ConcurrentQueue <ScenarioData> >(entry.Value));
            }

            // Restores the Analysis metadata map from persistent storage.
            var metadataInMemoryMap = await this.analysisMetadataObjectStore.GetCurrentSnapshotOfAllTypedObjectsAsync().ConfigureAwait(false);

            foreach (var oneMetatada in metadataInMemoryMap.Values)
            {
                // Little bit of hacky way. Basically any analysis that was in progress or not started from some earlier run,
                // we mark them as suspended with immediate resume so that activator thread can pick it up.
                if (oneMetatada.SchedulingInfo.CurrentStatus == AnalysisStatus.InProgress ||
                    oneMetatada.SchedulingInfo.CurrentStatus == AnalysisStatus.NotStarted ||
                    oneMetatada.SchedulingInfo.CurrentStatus == AnalysisStatus.Queued)
                {
                    oneMetatada.SchedulingInfo.SetContinuation(Continuation.ResumeImmediately);
                    await this.analysisMetadataObjectStore.PersistTypedObjectAsync(oneMetatada).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 2
0
        public async Task SavePrimaryReplicaContextAsync(PrimaryReplicaContext context)
        {
            await this.InitializeStoreAsync().ConfigureAwait(false);

            string serializedContext = InsightsUtil.Serialize(context);

            await this.contextStore.SetEntityAsync(context.PartitionId, serializedContext, this.cancellationToken).ConfigureAwait(false);
        }
Ejemplo n.º 3
0
        public async Task <PrimaryReplicaContext> GetPrimaryReplicaContextAsync(Guid partitionId)
        {
            await this.InitializeStoreAsync().ConfigureAwait(false);

            string contextAsString = await this.contextStore.GetEntityAsync(partitionId, this.cancellationToken).ConfigureAwait(false);

            var context = InsightsUtil.DeSerialize <PrimaryReplicaContext>(contextAsString);

            return(context);
        }
Ejemplo n.º 4
0
        // This routine reads from the undispatched persistent store and return all the values present there.
        private async Task <IList <ScenarioNotificationData> > GetUndispatchedSignalsFromLastRunAsync(CancellationToken token)
        {
            var undispatchDataList = new List <ScenarioNotificationData>();
            var allDataSerialized  = await this.signalsInDispatchQueuePersistentStore.GetAllValuesAsync(token).ConfigureAwait(false);

            foreach (var oneVal in allDataSerialized.Values)
            {
                var data = InsightsUtil.DeSerialize <ScenarioNotificationData>(oneVal);
                undispatchDataList.Add(data);
            }

            return(undispatchDataList);
        }
Ejemplo n.º 5
0
        // Sometime when a signal is received, the analysis container may not be in position to accept the data and
        // the data is put into this queue. When the analysis is in position to accept more data, this routine
        // is called to fetch data (if present).
        private async Task <ScenarioData> GetQueuedUpDataForAnalysisAsync(Guid analysisContainerIdentifier)
        {
            ConcurrentQueue <ScenarioData> queueOfDataInDispatchWaiting;

            if (!this.signalWaitingToBeProcessedMap.TryGetValue(analysisContainerIdentifier, out queueOfDataInDispatchWaiting))
            {
                return(null);
            }

            ScenarioData firstInQueue;

            if (!queueOfDataInDispatchWaiting.TryDequeue(out firstInQueue))
            {
                return(null);
            }

            // Persist the change in queue.
            await this.signalWaitingToBeProcessedStoreInstance.SetEntityAsync(
                analysisContainerIdentifier,
                InsightsUtil.Serialize(queueOfDataInDispatchWaiting),
                this.CancelToken).ConfigureAwait(false);

            return(firstInQueue);
        }