public ReplicatorMessageSerializer(Akka.Actor.ExtendedActorSystem system) : base(system) { _ser = new SerializationSupport(system); var cacheTtl = system.Settings.Config.GetTimeSpan("akka.cluster.distributed-data.serializer-cache-time-to-live"); _readCache = new SmallCache <Read, byte[]>(4, cacheTtl, m => ReadToProto(m).ToByteArray()); _writeCache = new SmallCache <Write, byte[]>(4, cacheTtl, m => WriteToProto(m).ToByteArray()); system.Scheduler.Advanced.ScheduleRepeatedly(cacheTtl, new TimeSpan(cacheTtl.Ticks / 2), () => { _readCache.Evict(); _writeCache.Evict(); }); }
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(); }); }