Class AsyncContainer

java.lang.Object
org.rostore.v2.container.async.AsyncContainer
All Implemented Interfaces:
AutoCloseable, Closeable

public class AsyncContainer extends Object implements 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 Details

  • 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

      public Container getContainer()
      Returns:
    • waitForShutdown

      public void waitForShutdown()
    • isIdle

      public boolean isIdle()
    • notifyIdle

      public void notifyIdle(ContainerShardExecutor containerShardExecutor)
    • getAsyncContainers

      public AsyncContainers 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 session
      key - the key data
      valueStream - the stream with the value data
      record - the properties of the key-value pair (ttl, options, versions)
    • put

      public <T> void put(int sessionId, byte[] key, T value, Record record)
      Puts a key-value pair to container
      Type Parameters:
      T - the type of the data
      Parameters:
      sessionId - the id of the session
      key - the key data
      value - the value object, that will be deserialized by BinaryMapper
      record - the properties of the key-value pair (ttl, options, versions)
    • put

      public <T> Record put(int sessionId, String key, T value)
      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 session
      key - the key data
      value - the value object, that will be deserialized by BinaryMapper
    • put

      public <T> void put(int sessionId, String key, T value, Record record)
      Puts a key-value pair to container.
      Type Parameters:
      T - the type of the data
      Parameters:
      sessionId - the id of the session
      key - the key data
      value - the value object, that will be deserialized by BinaryMapper
      record - the properties of the key-value pair (ttl, options, versions)
    • put

      public Record put(int sessionId, String key, Consumer<OutputStream> valueOutputStream)
      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 session
      key - the key string
      valueOutputStream - a consumer that should provide an OutputStream with the value
    • put

      public Record put(int sessionId, byte[] key, Consumer<OutputStream> valueOutputStream)
      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 session
      key - the key data
      valueOutputStream - a consumer that should provide an OutputStream with the value
    • put

      public void put(int sessionId, byte[] key, Consumer<OutputStream> valueOutputStream, Record record)
      Puts a key-value pair to container.
      Parameters:
      sessionId - the id of the session
      key - the key data
      valueOutputStream - a consumer that should provide an OutputStream with the value
      record - the properties of the key-value pair (ttl, options, versions)
    • putAsync

      public <T extends InputStream> void putAsync(int sessionId, byte[] key, AsyncStream<T> asyncStream)
      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 session
      key - the key data
      asyncStream - 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 session
      key - the key data
      asyncStream - an async stream on the basis of InputStream to read from
      record - 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 session
      key - the key data
      asyncStream - an async stream on the basis of OutputStream to read the value from
    • get

      public <T> DataWithRecord<T> get(int sessionId, byte[] key, Class<T> clazz)
      Gets a value based on key from container.
      Type Parameters:
      T - the value class
      Parameters:
      sessionId - the id of the session
      key - the key data
      clazz - an expected class of the value object
      Returns:
      the value transformed by BinaryMapper
    • get

      public <T> DataWithRecord<T> get(int sessionId, String key, Class<T> clazz)
      Gets a value based on key from container.
      Type Parameters:
      T - the value class
      Parameters:
      sessionId - the id of the session
      key - the key string
      clazz - 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 session
      key - the key data
      valueDeserializer - 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 id
      startWithKey - prefix of the keys to return
      continuationKey - the key to start with (used for pagination)
      maxNumber - the maximum number of entries to return
      maxSize - 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 id
      startWithKey - prefix of the keys to return
      continuationKey - the key to start with (used for pagination)
      maxNumber - the maximum number of entries to return
      maxSize - 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 id
      startWithKey - prefix of the keys to return
      continuationKey - the key to start with (used for pagination)
      maxNumber - the maximum number of entries to return
      maxSize - the maximum size of the returned list
      Returns:
      a future to return the list of keys
    • remove

      public boolean remove(int sessionId, byte[] key, Record record)
      Delete a key if one exists
      Parameters:
      sessionId - the session id
      key - the key binary
      record - metadata, mainly for options and version
      Returns:
      true if deletion has been successfully executed
    • remove

      public boolean remove(int sessionId, String key)
      Delete a key if one exists
      Parameters:
      sessionId - the session id
      key - the key binary
      Returns:
      true if deletion has been successfully executed
    • remove

      public boolean remove(int sessionId, String key, Record record)
      Delete a key if one exists
      Parameters:
      sessionId - the session id
      key - the key string
      Returns:
      true if deletion has been successfully executed
    • removeAsync

      public Future<Boolean> removeAsync(int sessionId, byte[] key, Record record)
      Delete a key if one exists
      Parameters:
      sessionId - the session id
      key - the key's binary
      Returns:
      a future for boolean, true if deletion has been successfully executed
    • getShardExecutorByKey

      public ContainerShardExecutor getShardExecutorByKey(byte[] key)
    • getShardExecutorByIndex

      public ContainerShardExecutor getShardExecutorByIndex(int shardIndex)
    • close

      public void close()
      Description copied from interface: Closeable
      Closes this entity and all related blocks
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • remove

      public void remove()
    • getStatus

      public Status getStatus()
      Description copied from interface: Closeable
      Provides a status of this entity
      Specified by:
      getStatus in interface Closeable
      Returns:
      the status