Example #1
0
        public HyperionSerializer(ExtendedActorSystem system) : base(system)
        {
            var knownTypes        = new[] { typeof(Msg) };
            var serializerOptions = new SerializerOptions(knownTypes: knownTypes);

            _serializer = new Hyperion.Serializer(serializerOptions);
        }
        public ReplicatorMessageSerializer(ExtendedActorSystem system) : base(system)
        {
            var cacheTtl = system.Settings.Config.GetTimeSpan("akka.cluster.distributed-data.serializer-cache-time-to-live");

            readCache  = new SmallCache <Read, byte[]>(4, cacheTtl, Serialize);
            writeCache = new SmallCache <Write, byte[]>(4, cacheTtl, Serialize);

            var akkaSurrogate =
                Hyperion.Surrogate.Create <ISurrogated, ISurrogate>(
                    toSurrogate: from => from.ToSurrogate(system),
                    fromSurrogate: to => to.FromSurrogate(system));

            serializer = new Hyperion.Serializer(new SerializerOptions(
                                                     preserveObjectReferences: true,
                                                     versionTolerance: true,
                                                     surrogates: new[] { akkaSurrogate },
                                                     knownTypes: new []
            {
                typeof(Get),
                typeof(GetSuccess),
                typeof(GetFailure),
                typeof(NotFound),
                typeof(Subscribe),
                typeof(Unsubscribe),
                typeof(Changed),
                typeof(DataEnvelope),
                typeof(Write),
                typeof(WriteAck),
                typeof(Read),
                typeof(ReadResult),
                typeof(Internal.Status),
                typeof(Gossip)
            }));

            using (var stream = new MemoryStream())
            {
                serializer.Serialize(WriteAck.Instance, stream);
                stream.Position = 0;
                writeAckBytes   = stream.ToArray();
            }

            system.Scheduler.Advanced.ScheduleRepeatedly(cacheTtl, new TimeSpan(cacheTtl.Ticks / 2), () =>
            {
                readCache.Evict();
                writeCache.Evict();
            });
        }
        public ReplicatedDataSerializer(ExtendedActorSystem system) : base(system)
        {
            var akkaSurrogate =
                Surrogate
                .Create <ISurrogated, ISurrogate>(
                    from => from.ToSurrogate(system),
                    to => to.FromSurrogate(system));

            _serializer =
                new Hyperion.Serializer(new SerializerOptions(
                                            preserveObjectReferences: true,
                                            versionTolerance: true,
                                            surrogates: new[]
            {
                akkaSurrogate
            }));
        }