private Proto.Msg.DeltaPropagation DeltaPropagationToProto(DeltaPropagation msg) { var proto = new Proto.Msg.DeltaPropagation { FromNode = SerializationSupport.UniqueAddressToProto(msg.FromNode) }; if (msg.ShouldReply) { proto.Reply = msg.ShouldReply; } foreach (var entry in msg.Deltas) { var d = entry.Value; var delta = new Proto.Msg.DeltaPropagation.Types.Entry { Key = entry.Key, FromSeqNr = d.FromSeqNr, Envelope = DataEnvelopeToProto(d.DataEnvelope) }; if (d.ToSeqNr != d.FromSeqNr) { delta.ToSeqNr = d.ToSeqNr; } proto.Entries.Add(delta); } return(proto); }
private Proto.Msg.DataEnvelope.Types.PruningEntry PruningToProto(UniqueAddress addr, IPruningState pruning) { var proto = new Proto.Msg.DataEnvelope.Types.PruningEntry { RemovedAddress = SerializationSupport.UniqueAddressToProto(addr) }; switch (pruning) { case PruningPerformed performed: proto.Performed = true; proto.ObsoleteTime = performed.ObsoleteTime.Ticks; break; case PruningInitialized init: proto.Performed = false; proto.OwnerAddress = SerializationSupport.UniqueAddressToProto(init.Owner); foreach (var address in init.Seen) { proto.Seen.Add(SerializationSupport.AddressToProto(address)); } break; } return(proto); }
private Proto.Msg.Read ReadToProto(Read read) { var proto = new Proto.Msg.Read { Key = read.Key }; if (!(read.FromNode is null)) { proto.FromNode = SerializationSupport.UniqueAddressToProto(read.FromNode); } return(proto); }
private Proto.Msg.Write WriteToProto(Write write) { var proto = new Proto.Msg.Write { Key = write.Key, Envelope = DataEnvelopeToProto(write.Envelope), }; if (!(write.FromNode is null)) { proto.FromNode = SerializationSupport.UniqueAddressToProto(write.FromNode); } return(proto); }
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 override object FromBinary(byte[] bytes, string manifest) { switch (manifest) { case DataEnvelopeManifest: return(DataEnvelopeFromBinary(bytes)); case WriteManifest: return(WriteFromBinary(bytes)); case WriteAckManifest: return(WriteAck.Instance); case ReadManifest: return(ReadFromBinary(bytes)); case ReadResultManifest: return(ReadResultFromBinary(bytes)); case DeltaPropagationManifest: return(DeltaPropagationFromBinary(bytes)); case StatusManifest: return(StatusFromBinary(bytes)); case GetManifest: return(GetFromBinary(bytes)); case GetSuccessManifest: return(GetSuccessFromBinary(bytes)); case DurableDataEnvelopeManifest: return(DurableDataEnvelopeFromBinary(bytes)); case ChangedManifest: return(ChangedFromBinary(bytes)); case NotFoundManifest: return(NotFoundFromBinary(bytes)); case GetFailureManifest: return(GetFailureFromBinary(bytes)); case SubscribeManifest: return(SubscribeFromBinary(bytes)); case UnsubscribeManifest: return(UnsubscribeFromBinary(bytes)); case GossipManifest: return(GossipFromBinary(SerializationSupport.Decompress(bytes))); case WriteNackManifest: return(WriteNack.Instance); case DeltaNackManifest: return(DeltaNack.Instance); default: throw new ArgumentException($"Unimplemented deserialization of message with manifest '{manifest}' using [{GetType().FullName}]"); } }
private Proto.Msg.DataEnvelope DataEnvelopeToProto(DataEnvelope msg) { var proto = new Proto.Msg.DataEnvelope { Data = this.OtherMessageToProto(msg.Data) }; foreach (var entry in msg.Pruning) { proto.Pruning.Add(PruningToProto(entry.Key, entry.Value)); } if (!msg.DeltaVersions.IsEmpty) { proto.DeltaVersions = SerializationSupport.VersionVectorToProto(msg.DeltaVersions); } return(proto); }
public override byte[] ToBinary(object obj) { switch (obj) { case DataEnvelope envelope: return(DataEnvelopeToProto(envelope).ToByteArray()); case Write write: return(_writeCache.GetOrAdd(write)); case WriteAck _: return(_empty); case Read read: return(_readCache.GetOrAdd(read)); case ReadResult result: return(ReadResultToProto(result).ToByteArray()); case DeltaPropagation propagation: return(DeltaPropagationToProto(propagation).ToByteArray()); case Status status: return(StatusToProto(status).ToByteArray()); case Get get: return(GetToProto(get).ToByteArray()); case GetSuccess success: return(GetSuccessToProto(success).ToByteArray()); case Durable.DurableDataEnvelope envelope: return(DurableDataEnvelopeToProto(envelope).ToByteArray()); case Changed changed: return(ChangedToProto(changed).ToByteArray()); case NotFound found: return(NotFoundToProto(found).ToByteArray()); case GetFailure failure: return(GetFailureToProto(failure).ToByteArray()); case Subscribe subscribe: return(SubscribeToProto(subscribe).ToByteArray()); case Unsubscribe unsubscribe: return(UnsubscribeToProto(unsubscribe).ToByteArray()); case Gossip gossip: return(SerializationSupport.Compress(GossipToProto(gossip))); case WriteNack _: return(_empty); case DeltaNack _: return(_empty); default: throw new ArgumentException($"Can't serialize object of type [{obj.GetType().FullName}] using [{GetType().FullName}]"); } }