/// <summary>
        /// Sets a <paramref name="bucket"/> of values inside current dictionary under provided <paramref name="key"/>
        /// in the context of the provided cluster <paramref name="node"/>.
        /// </summary>
        public ORMultiValueDictionary <TKey, TValue> SetItems(UniqueAddress node, TKey key, IImmutableSet <TValue> bucket)
        {
            var newUnderlying = Underlying.AddOrUpdate(node, key, ORSet <TValue> .Empty, _withValueDeltas, old =>
                                                       bucket.Aggregate(old.Clear(node), (set, element) => set.Add(node, element)));

            return(new ORMultiValueDictionary <TKey, TValue>(newUnderlying, _withValueDeltas));
        }
Ejemplo n.º 2
0
 public override int GetHashCode()
 {
     unchecked
     {
         // Choose large primes to avoid hashing collisions
         const int hashingBase       = (int)2166136261;
         const int hashingMultiplier = 16777619;
         return(_immutableSetImplementation.Aggregate(hashingBase,
                                                      (aggregate, element) => (aggregate * hashingMultiplier) ^ element.ToString().GetHashCode()));
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Concatenates a set of tags using a provided separator.
        /// </summary>
        /// <param name="tags"></param>
        /// <param name="separator"></param>
        /// <returns></returns>
        private static string StringSep(IImmutableSet <string> tags,
                                        string separator)
        {
            if (tags.Count == 0)
            {
                return("");
            }

            return(tags.Aggregate((tl, tr) =>
                                  tl + separator + tr));
        }
Ejemplo n.º 4
0
 private static bool CheckDayOfYear(DateTime time, IImmutableSet <int> times)
 {
     return(times.Aggregate(seed: false,
                            func: (accu, current) => {
         if (current > 0)
         {
             return accu || time.DayOfYear == current;
         }
         else
         {
             return accu || time.DayOfYear == new DateTime(time.Year, 12, 31).AddDays(current + 1).DayOfYear;
         }
     }));
 }
Ejemplo n.º 5
0
 private static bool CheckDayOfMonth(DateTime time, IImmutableSet <int> times)
 {
     return(times.Aggregate(seed: false,
                            func: (accu, current) => {
         if (current > 0)
         {
             return accu || time.Day == current;
         }
         else
         {
             return accu || time.Day == new DateTime(time.Year, time.Month, 1).AddMonths(1).AddDays(current).Day;
         }
     }));
 }
Ejemplo n.º 6
0
        public object ToJournal(object evt)
        {
            var s = evt as string;

            if (s != null)
            {
                var tags = Colors.Aggregate(ImmutableHashSet <string> .Empty, (acc, color) => s.Contains(color) ? acc.Add(color) : acc);
                return(tags.IsEmpty
                    ? evt
                    : new Tagged(evt, tags));
            }
            else
            {
                return(evt);
            }
        }
        protected override Try <JournalRow> Serialize(IPersistentRepresentation persistentRepr, IImmutableSet <string> tTags, long timeStamp = 0)
        {
            try
            {
                var serializer = _serializer.FindSerializerForType(persistentRepr.Payload.GetType(), _journalConfig.DefaultSerializer);
                // TODO: hack. Replace when https://github.com/akkadotnet/akka.net/issues/3811
                string manifest = "";
                var    binary   = Akka.Serialization.Serialization.WithTransport(_serializer.System, () =>
                {
                    if (serializer is SerializerWithStringManifest stringManifest)
                    {
                        manifest =
                            stringManifest.Manifest(persistentRepr.Payload);
                    }
                    else
                    {
                        if (serializer.IncludeManifest)
                        {
                            manifest = persistentRepr.Payload.GetType().TypeQualifiedName();
                        }
                    }

                    return(serializer.ToBinary(persistentRepr.Payload));
                });
                return(new Try <JournalRow>(new JournalRow()
                {
                    manifest = manifest,
                    message = binary,
                    persistenceId = persistentRepr.PersistenceId,
                    tags = tTags.Any()?  tTags.Aggregate((tl, tr) => tl + _separator + tr) : "",
                    Identifier = serializer.Identifier,
                    sequenceNumber = persistentRepr.SequenceNr,
                    Timestamp = persistentRepr.Timestamp == 0?  timeStamp: persistentRepr.Timestamp
                }));
            }
            catch (Exception e)
            {
                return(new Try <JournalRow>(e));
            }
        }
Ejemplo n.º 8
0
 private DataEnvelope PruningCleanupTombstoned(DataEnvelope envelope)
 {
     return(_tombstonedNodes.Aggregate(envelope, PruningCleanupTombstoned));
 }
Ejemplo n.º 9
0
        public static T AssertAllStagesStopped <T>(this AkkaSpec spec, Func <T> block, IMaterializer materializer)
        {
            var impl = materializer as ActorMaterializerImpl;

            if (impl == null)
            {
                return(block());
            }

            var probe = spec.CreateTestProbe(impl.System);

            probe.Send(impl.Supervisor, StreamSupervisor.StopChildren.Instance);
            probe.ExpectMsg <StreamSupervisor.StoppedChildren>();
            var result = block();

            probe.Within(TimeSpan.FromSeconds(5), () =>
            {
                IImmutableSet <IActorRef> children = ImmutableHashSet <IActorRef> .Empty;
                try
                {
                    probe.AwaitAssert(() =>
                    {
                        impl.Supervisor.Tell(StreamSupervisor.GetChildren.Instance, probe.Ref);
                        children = probe.ExpectMsg <StreamSupervisor.Children>().Refs;
                        if (children.Count != 0)
                        {
                            throw new Exception($"expected no StreamSupervisor children, but got {children.Aggregate("", (s, @ref) => s + @ref + ", ")}");
                        }
                    });
                }
                catch
                {
                    children.ForEach(c => c.Tell(StreamSupervisor.PrintDebugDump.Instance));
                    throw;
                }
            });

            return(result);
        }