using Connected.Entities.Consistency; namespace Connected.Entities.Concurrency; /// /// This entity is primarly used when cached in memory and access to the entity is frequent with /// updates. The ensures that threads don't overwrite /// values from other threads by using the property. /// /// /// While ensures database consistency, /// ensures application consistency. The is not thread safe but ensures /// that any writes are rejected if the thread tries to write entity with invalid property value. /// /// public interface IConcurrentEntity : IConsistentEntity where TPrimaryKey : notnull { /// /// The synchronization value used when comparing if the write to the entity is made with the latest /// version. Entities are immutable but they can be replaced in Cache with newer instances. The cache tipically /// ensures that entities can't be overwritten with out of date values. /// /// /// In Queue messages, all messages are stored in memory and multiple threads perform dequeue. Since dequeue means /// overwriting some data and since the entities are immutable (except this entity and only the property) the operaton results with overwriting the entire /// entity in cache. If two or more thready do it in the same time, they could accidentally overwrite values from /// each other. The cache ensures that the current entity has the same value as the updating entity. If the write /// occurred in the mean time it would result incrementing the value which would cause any subsequent /// writes with the same originating entity would fail. /// int Sync { get; set; } }