Exemple #1
0
        protected BaseCallbackStore(IStoreProvider storeProvider, ITaskRunner taskRunner, ILogProvider logProvider, CancellationToken token)
        {
            Assert.IsNotNull(storeProvider, "Store Provider can't be null");
            Assert.IsNotNull(taskRunner, "Task Runner can't be null");
            Assert.IsNotNull(logProvider, "Log Provider can't be null");

            this.singleAccessLock = new SemaphoreSlim(1);
            this.callbackMap      = new Dictionary <NotifyFilter, IList <Func <ScenarioData, Task> > >();
            this.Logger           = logProvider.CreateLoggerInstance(this.GetType().ToString().Split('.').Last());
            this.taskRunner       = taskRunner;

            this.InternalTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token);
            token = this.InternalTokenSource.Token;

            // Some signals may not show up immedietly so we don't want their last seen time bailing on us.
            this.callBackCheckPointTimeStore = storeProvider.CreatePersistentStoreForTimeAsync(CallbackTimeBookmarkStore, AgeBasedRetentionPolicy.OneDay, token)
                                               .GetAwaiter().GetResult();

            // This store keeps track of unique Ids of signals seen to avoid duplicate reporting. The entries in this
            // collection needs to be long lived. Consider a signal that is living in the system for a long time
            // If we don't track that this has been reported, we may try to report it again.
            this.reportedSignalsUniqueIdsStore = storeProvider
                                                 .CreatePersistentStoreKeyGuidValueStringAsync(ReportedSignalUniqueIdsStoreName, AgeBasedRetentionPolicy.OneWeek, token).GetAwaiter()
                                                 .GetResult();

            this.signalsInDispatchQueuePersistentStore = storeProvider
                                                         .CreatePersistentStoreKeyGuidValueStringAsync(SignalsInDispatchQueueStoreName, AgeBasedRetentionPolicy.OneHour, token).GetAwaiter().GetResult();

            this.producerConsumerBufferBlock = new BufferBlock <ScenarioNotificationData>();
            this.InitSignalSeenBookmarkStoreAsync(token).Wait(token);
        }
        public AnalysisScheduler(
            ILogProvider logProvider,
            IStoreProvider storeProvider,
            ITaskRunner taskRunner,
            TraceStoreConnection traceStoreConnection,
            CancellationToken token)
        {
            Assert.IsNotNull(logProvider, "Log Provider can't be null");
            Assert.IsNotNull(storeProvider, "Store Provider can't be null");
            Assert.IsNotNull(taskRunner, "Task Runner can't be null");
            Assert.IsNotNull(traceStoreConnection, "Trace store connection can't be null");

            this.Logger      = logProvider.CreateLoggerInstance(TracePrefix);
            this.TaskRunner  = taskRunner;
            this.consumerMap = new Dictionary <AgentIdentifier, IDictionary <IAnalysisConsumer, ConsumeOptions> >();
            this.CancelToken = token;

            // The in memory Caches for typed objects
            this.signalWaitingToBeProcessedMap = new ConcurrentDictionary <Guid, ConcurrentQueue <ScenarioData> >();

            this.analysisMetadataObjectStore = new TypedObjectStore <AnalysisMetadata>(
                this.Logger,
                storeProvider,
                AgentConstants.AnalysisMetadataStoreId,
                AgentConstants.AnalysisMetadataStoreRetentionPolicy,
                token);

            this.analysisContainerObjectStore = new TypedObjectStore <AnalysisContainer>(
                this.Logger,
                storeProvider,
                AgentConstants.AnalysisContainerStoreId,
                AgentConstants.AnalysisContainerStoreRetentionPolicy,
                token);

            this.signalWaitingToBeProcessedStoreInstance = storeProvider.CreatePersistentStoreKeyGuidValueStringAsync(
                AgentConstants.AnalysisUnprocessedSignalStoreId,
                AgentConstants.AnalysisUnprocessedSignalStoreRetentionPolicy,
                this.CancelToken).GetAwaiter().GetResult();

            Assert.IsNotNull(this.signalWaitingToBeProcessedStoreInstance, "signalWaitingToBeProcessedStoreInstance");

            // Restore state from any of the previous Runs.
            this.RestoreStateFromPreviousRunsAsync().GetAwaiter().GetResult();

            this.Logger.LogMessage("kicking off Activation Task");
            var activationTask = this.TaskRunner.Run("AgentActivationTask", this.ActivateAnalysisAsync, this.CancelToken);

            this.InitializeDataFlowPipeline();
        }