public final class InMemoryInboxStorage extends AbstractStorage<io.spine.server.delivery.InboxMessageId,io.spine.server.delivery.InboxMessage,InboxReadRequest> implements InboxStorage, io.spine.logging.Logging
Inbox
.
Mutating operations are made synchronized
to avoid simultaneous updates
of the same records. That allows to operate in a concurrency-heavy environment notwithstanding
the thread-safety of the underlying storage.
Constructor and Description |
---|
InMemoryInboxStorage(boolean multitenant) |
Modifier and Type | Method and Description |
---|---|
java.util.Iterator<io.spine.server.delivery.InboxMessageId> |
index()
Returns an iterator over identifiers of records in the storage.
|
java.util.Optional<io.spine.server.delivery.InboxMessage> |
newestMessageToDeliver(io.spine.server.delivery.ShardIndex index)
Finds the newest message to deliver
in the given shard.
|
java.util.Optional<io.spine.server.delivery.InboxMessage> |
read(InboxReadRequest request)
Reads a record from the storage by the specified request.
|
Page<io.spine.server.delivery.InboxMessage> |
readAll(io.spine.server.delivery.ShardIndex index,
int pageSize)
Reads the contents of the storage by the given shard index and returns the first page
of the results.
|
void |
removeAll(java.lang.Iterable<io.spine.server.delivery.InboxMessage> messages)
Removes the passed messages from the storage.
|
void |
write(io.spine.server.delivery.InboxMessage message)
Writes a message to the storage.
|
void |
write(io.spine.server.delivery.InboxMessageId id,
io.spine.server.delivery.InboxMessage record)
Writes a record into the storage.
|
void |
writeAll(java.lang.Iterable<io.spine.server.delivery.InboxMessage> messages)
Writes several messages to the storage.
|
checkNotClosed, checkNotClosed, close, isClosed, isMultitenant, isOpen
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close, isMultitenant, isOpen
public Page<io.spine.server.delivery.InboxMessage> readAll(io.spine.server.delivery.ShardIndex index, int pageSize)
InboxStorage
The older items go first.
readAll
in interface InboxStorage
index
- the shard index to return the results forpageSize
- the maximum number of the elements per pagepublic java.util.Optional<io.spine.server.delivery.InboxMessage> newestMessageToDeliver(io.spine.server.delivery.ShardIndex index)
InboxStorage
newestMessageToDeliver
in interface InboxStorage
index
- the shard index to look inOptional.empty()
if there are no messages to deliver
in the specified shardpublic void write(io.spine.server.delivery.InboxMessage message)
InboxStorage
write
in interface InboxStorage
message
- a message to writepublic void writeAll(java.lang.Iterable<io.spine.server.delivery.InboxMessage> messages)
InboxStorage
writeAll
in interface InboxStorage
messages
- messages to writepublic java.util.Iterator<io.spine.server.delivery.InboxMessageId> index()
Storage
index
in interface Storage<io.spine.server.delivery.InboxMessageId,io.spine.server.delivery.InboxMessage,InboxReadRequest>
public java.util.Optional<io.spine.server.delivery.InboxMessage> read(InboxReadRequest request)
Storage
read
in interface Storage<io.spine.server.delivery.InboxMessageId,io.spine.server.delivery.InboxMessage,InboxReadRequest>
request
- the request to read the recordOptional.empty()
if there is no record matching this requestpublic void write(io.spine.server.delivery.InboxMessageId id, io.spine.server.delivery.InboxMessage record)
Storage
Rewrites it if a record with this ID already exists in the storage.
write
in interface Storage<io.spine.server.delivery.InboxMessageId,io.spine.server.delivery.InboxMessage,InboxReadRequest>
id
- the ID for the recordrecord
- the record to storepublic void removeAll(java.lang.Iterable<io.spine.server.delivery.InboxMessage> messages)
InboxStorage
Does nothing for messages that aren't in the storage already.
removeAll
in interface InboxStorage
messages
- the messages to remove