protected MetricStore(MetricStore another) { this.vmName = another.vmName; this.date = another.date; this.metrics = new Dictionary <string, Metric>(); foreach (var entry in another.metrics) { this.metrics.Add(entry.Key, entry.Value); } }
public MetricStoreActor(string vmName, string date) { _metricStore = new MetricStore(vmName, date); // Recover messages Recover <UpsertMetric>(um => ProcessUpsertMetric(um)); Recover <SnapshotOffer>(offer => { var ms = offer.Snapshot as MetricStore; if (ms != null) // null check { _metricStore = ms; } }); // Commands Command <UpsertMetric>(um => Persist(um, s => { _log.Debug($"Received UpserMetrics msg actor id={PersistenceId}"); ProcessUpsertMetric(um); // SaveSnapshot(_metricStore.Clone()); })); Command <Messages.Stopping>(um => ProcessStopping()); Command <SaveSnapshotSuccess>(success => { // soft-delete the journal up until the sequence # at // which the snapshot was taken DeleteMessages(success.Metadata.SequenceNr); // Delete all previous snapshots so we only keep the latest one var snapSelectCrit = new SnapshotSelectionCriteria(success.Metadata.SequenceNr - 1, success.Metadata.Timestamp, 0, new DateTime(0)); DeleteSnapshots(snapSelectCrit); _log.Info($"Save snapshot successful for actor id={PersistenceId}"); // Tell all the metric accumulators dispatchers that this actor is finishing var selection = Context.ActorSelection("/user/*/MetricAccumulatorDispatcher"); // var selection = Context.ActorSelection("/*/MetricAccumulatorDispatcher*"); selection.Tell(new Messages.MetricStoreActorStopping()); _log.Debug($"Signalled stopping to MetricAccumulatorDispatcher for actor id={PersistenceId}"); Context.Stop(Context.Self); }); Command <SaveSnapshotFailure>(failure => { _log.Error($"ERROR: Failed to save snapshot for actor with id={PersistenceId}.\nMessage:{failure.Cause.Message}"); }); Command <Messages.BuildTransformSeries>(msg => ProcessPipeline(msg)); }