Package org.rostore.v2.container.async
Class AsyncContainer
java.lang.Object
org.rostore.v2.container.async.AsyncContainer
- All Implemented Interfaces:
AutoCloseable
,Closeable
A representation of the rostore container.
This is a heavy object that manages ContainerShard
array.
It must be closed once it is not used anymore. The closed instance can be safely disposed and should not be reused.
This class manages asynchronous operations on the shards and can only be closed if all the operations are over.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this entity and all related blocksvoid
closeIfIdle
(long idleMillis) Will close the instance in case no active key operation has been observed for the given time.<T> DataWithRecord
<T> Gets a value based on key from container.<T> DataWithRecord
<T> get
(int sessionId, byte[] key, Function<InputStream, T> valueDeserializer) Gets a value based on key from container.<T> DataWithRecord
<T> Gets a value based on key from container.<T extends OutputStream>
voidgetAsync
(int sessionId, byte[] key, AsyncStream<T> asyncStream) Gets a value based on key from container.getShardExecutorByIndex
(int shardIndex) getShardExecutorByKey
(byte[] key) Provides a status of this entityboolean
isIdle()
list
(int sessionId, byte[] startWithKey, byte[] continuationKey, int maxNumber, int maxSize) List the keys in the containerList the keys in the containerlistAsync
(int sessionId, byte[] startWithKey, byte[] continuationKey, int maxNumber, int maxSize) List the keys in the containervoid
notifyIdle
(ContainerShardExecutor containerShardExecutor) put
(int sessionId, byte[] key, Consumer<OutputStream> valueOutputStream) Puts a key-value pair to container.void
put
(int sessionId, byte[] key, Consumer<OutputStream> valueOutputStream, Record record) Puts a key-value pair to container.<T extends InputStream>
voidput
(int sessionId, byte[] key, AsyncStream<T> valueStream, Record record) Puts a key-value pair to the container<T> void
Puts a key-value pair to containerput
(int sessionId, String key, Consumer<OutputStream> valueOutputStream) Puts a key-value pair to container.<T> Record
Puts a key-value pair to container.<T> void
Puts a key-value pair to container.<T extends InputStream>
voidputAsync
(int sessionId, byte[] key, AsyncStream<T> asyncStream) Puts a key-value pair to container.<T extends InputStream>
voidputAsync
(int sessionId, byte[] key, AsyncStream<T> asyncStream, Record record) Puts a key-value pair to container.void
remove()
boolean
Delete a key if one existsboolean
Delete a key if one existsboolean
Delete a key if one existsremoveAsync
(int sessionId, byte[] key, Record record) Delete a key if one existsvoid
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.rostore.v2.media.Closeable
checkOpened
-
Constructor Details
-
AsyncContainer
-
-
Method Details
-
closeIfIdle
public void closeIfIdle(long idleMillis) Will close the instance in case no active key operation has been observed for the given time.- Parameters:
idleMillis
- the number of milliseconds the storage should be idle
-
getContainer
- Returns:
-
waitForShutdown
public void waitForShutdown() -
isIdle
public boolean isIdle() -
notifyIdle
-
getAsyncContainers
-
put
public <T extends InputStream> void put(int sessionId, byte[] key, AsyncStream<T> valueStream, Record record) Puts a key-value pair to the container- Type Parameters:
T
- the type of the data- Parameters:
sessionId
- the id of the sessionkey
- the key datavalueStream
- the stream with the value datarecord
- the properties of the key-value pair (ttl, options, versions)
-
put
Puts a key-value pair to container- Type Parameters:
T
- the type of the data- Parameters:
sessionId
- the id of the sessionkey
- the key datavalue
- the value object, that will be deserialized byBinaryMapper
record
- the properties of the key-value pair (ttl, options, versions)
-
put
Puts a key-value pair to container.The version is set to 0 (non-versioned), ttl is set to 0 (eternal)
- Type Parameters:
T
- the type of the data- Parameters:
sessionId
- the id of the sessionkey
- the key datavalue
- the value object, that will be deserialized byBinaryMapper
-
put
Puts a key-value pair to container.- Type Parameters:
T
- the type of the data- Parameters:
sessionId
- the id of the sessionkey
- the key datavalue
- the value object, that will be deserialized byBinaryMapper
record
- the properties of the key-value pair (ttl, options, versions)
-
put
Puts a key-value pair to container.The version is set to 0 (non-versioned), ttl is set to 0 (eternal)
- Parameters:
sessionId
- the id of the sessionkey
- the key stringvalueOutputStream
- a consumer that should provide an OutputStream with the value
-
put
Puts a key-value pair to container.The version is set to 0 (non-versioned), ttl is set to 0 (eternal)
- Parameters:
sessionId
- the id of the sessionkey
- the key datavalueOutputStream
- a consumer that should provide an OutputStream with the value
-
put
Puts a key-value pair to container.- Parameters:
sessionId
- the id of the sessionkey
- the key datavalueOutputStream
- a consumer that should provide an OutputStream with the valuerecord
- the properties of the key-value pair (ttl, options, versions)
-
putAsync
Puts a key-value pair to container.The version is set to 0 (non-versioned), ttl is set to 0 (eternal)
- Type Parameters:
T
- the subtype of the InputStream to read value- Parameters:
sessionId
- the id of the sessionkey
- the key dataasyncStream
- an async stream on the basis of InputStream to read from
-
putAsync
public <T extends InputStream> void putAsync(int sessionId, byte[] key, AsyncStream<T> asyncStream, Record record) Puts a key-value pair to container.- Type Parameters:
T
- the subtype of the InputStream to read value- Parameters:
sessionId
- the id of the sessionkey
- the key dataasyncStream
- an async stream on the basis of InputStream to read fromrecord
- the properties of the key-value pair (ttl, options, versions)
-
getAsync
public <T extends OutputStream> void getAsync(int sessionId, byte[] key, AsyncStream<T> asyncStream) Gets a value based on key from container.- Type Parameters:
T
- the subtype of the OutputStream to read value- Parameters:
sessionId
- the id of the sessionkey
- the key dataasyncStream
- an async stream on the basis of OutputStream to read the value from
-
get
Gets a value based on key from container.- Type Parameters:
T
- the value class- Parameters:
sessionId
- the id of the sessionkey
- the key dataclazz
- an expected class of the value object- Returns:
- the value transformed by
BinaryMapper
-
get
Gets a value based on key from container.- Type Parameters:
T
- the value class- Parameters:
sessionId
- the id of the sessionkey
- the key stringclazz
- an expected class of the value object- Returns:
- the value transformed by
BinaryMapper
-
get
public <T> DataWithRecord<T> get(int sessionId, byte[] key, Function<InputStream, T> valueDeserializer) Gets a value based on key from container.- Type Parameters:
T
- the value class- Parameters:
sessionId
- the id of the sessionkey
- the key datavalueDeserializer
- a function that transforms the value input stream to the java object- Returns:
- the value transformed by the supplied deserializer
-
list
public KeyList list(int sessionId, byte[] startWithKey, byte[] continuationKey, int maxNumber, int maxSize) List the keys in the container- Parameters:
sessionId
- the session idstartWithKey
- prefix of the keys to returncontinuationKey
- the key to start with (used for pagination)maxNumber
- the maximum number of entries to returnmaxSize
- the maximum size of the returned list- Returns:
- a list of keys
-
list
public StringKeyList list(int sessionId, String startWithKey, String continuationKey, int maxNumber, int maxSize) List the keys in the container- Parameters:
sessionId
- the session idstartWithKey
- prefix of the keys to returncontinuationKey
- the key to start with (used for pagination)maxNumber
- the maximum number of entries to returnmaxSize
- the maximum size of the returned list- Returns:
- a list of keys
-
listAsync
public Future<KeyList> listAsync(int sessionId, byte[] startWithKey, byte[] continuationKey, int maxNumber, int maxSize) List the keys in the container- Parameters:
sessionId
- the session idstartWithKey
- prefix of the keys to returncontinuationKey
- the key to start with (used for pagination)maxNumber
- the maximum number of entries to returnmaxSize
- the maximum size of the returned list- Returns:
- a future to return the list of keys
-
remove
Delete a key if one exists- Parameters:
sessionId
- the session idkey
- the key binaryrecord
- metadata, mainly for options and version- Returns:
true
if deletion has been successfully executed
-
remove
Delete a key if one exists- Parameters:
sessionId
- the session idkey
- the key binary- Returns:
true
if deletion has been successfully executed
-
remove
Delete a key if one exists- Parameters:
sessionId
- the session idkey
- the key string- Returns:
true
if deletion has been successfully executed
-
removeAsync
Delete a key if one exists- Parameters:
sessionId
- the session idkey
- the key's binary- Returns:
- a future for boolean,
true
if deletion has been successfully executed
-
getShardExecutorByKey
-
getShardExecutorByIndex
-
close
public void close()Description copied from interface:Closeable
Closes this entity and all related blocks- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
remove
public void remove() -
getStatus
Description copied from interface:Closeable
Provides a status of this entity
-