class ObjectFramework::Memory::Storage
Thread-safe storage adapter. Writes publish their complete snapshot atomically; a competing commit raises Conflict without automatic retry. Data is lost when the storage is closed or the process exits.
Public Class Methods
Source
# File lib/object_framework/memory/storage.rb, line 10 def initialize @mutex, @tables, @revision, @closed = Mutex.new, {}, 0, false end
Public Instance Methods
Source
# File lib/object_framework/memory/storage.rb, line 17 def begin_transaction(mode:) @mutex.synchronize do raise Unavailable, "Storage is closed" if @closed Transaction.new(storage: self, tables: @tables.transform_values(&:dup), revision: @revision, mode:) end end
Opens an independent snapshot in :read or :write mode. The caller must close the transaction; Application#invoke owns this lifecycle when the adapter is installed in an application.
Source
# File lib/object_framework/memory/storage.rb, line 34 def close @mutex.synchronize { @closed = true; @tables = {} } end
Source
# File lib/object_framework/memory/storage.rb, line 24 def publish(tables, revision:) @mutex.synchronize do raise Unavailable, "Storage is closed" if @closed raise Conflict, "Snapshot revision changed" unless revision == @revision # Publishing the whole table set under one lock makes multi-row commits atomic. @tables = tables.transform_values { |rows| rows.dup.freeze }.freeze @revision += 1 end end