public class MemoryStorageManager<V extends Serializable> extends StorageManager<V> implements Serializable
Modifier and Type | Field and Description |
---|---|
protected BulletConfig |
config |
DEFAULT_NAMESPACE
Constructor and Description |
---|
MemoryStorageManager(BulletConfig config)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
CompletableFuture<Boolean> |
clear(String namespace)
Clears the specified namespace.
|
CompletableFuture<Boolean> |
clear(String namespace,
int partition)
Clears the specified partition under the given namespace.
|
CompletableFuture<Boolean> |
clear(String namespace,
Set<String> ids)
Removes a given set of IDs from the storage under the given namespace.
|
void |
close()
.
|
protected V |
convert(byte[] bytes)
Converts a @
byte[] to a type of the given object. |
protected byte[] |
convert(V object)
Converts an object of the given type to a @
byte[] . |
static <S> Map<String,byte[]> |
fromObjectMap(Map<String,S> input,
Function<S,byte[]> converter)
|
CompletableFuture<V> |
get(String namespace,
String id)
Retrieves data stored for a given String identifier in the given namespace as a
Serializable object. |
CompletableFuture<Map<String,V>> |
getAll(String namespace)
Retrieves all the IDs from the given namespace in the storage as a
Map of IDs to their
Serializable values. |
CompletableFuture<Map<String,V>> |
getAll(String namespace,
Set<String> ids)
Retrieves the values for the provided IDs from the given namespace in the storage as a
Map of IDs to
their Serializable values. |
protected CompletableFuture<Map<String,byte[]>> |
getAllRaw(String namespace)
Retrieves all the IDs from the given namespace in the storage as byte[].
|
protected CompletableFuture<Map<String,byte[]>> |
getAllRaw(String namespace,
Set<String> ids)
Retrieves the values for the provided IDs from the given namespace in the storage as byte[].
|
CompletableFuture<Map<String,String>> |
getAllString(String namespace)
Retrieves all the IDs from the given namespace in the storage as a
Map of IDs to their String values. |
CompletableFuture<Map<String,String>> |
getAllString(String namespace,
Set<String> ids)
Retrieves the values for the provided IDs from the given namespace in the storage as a
Map of IDs to
their String values. |
CompletableFuture<Map<String,V>> |
getPartition(String namespace,
int partition)
Retrieves the IDs stored in the provided partition for the given namespace.
|
protected CompletableFuture<Map<String,byte[]>> |
getPartitionRaw(String namespace,
int partition)
Retrieves the IDs stored in the provided partition for the given namespace.
|
CompletableFuture<Map<String,String>> |
getPartitionString(String namespace,
int partition)
Retrieves the IDs stored in the provided partition for the given namespace.
|
protected CompletableFuture<byte[]> |
getRaw(String namespace,
String id)
Retrieves a given ID from the given namespace in the storage.
|
CompletableFuture<String> |
getString(String namespace,
String id)
Retrieves data stored for a given String identifier in the given namespace as a String.
|
int |
numberOfPartitions(String namespace)
Returns the number of partitions stored in this storage manager for the given namespace.
|
CompletableFuture<Boolean> |
put(String namespace,
String id,
V value)
Stores any
Serializable object for a given String identifier in the given namespace. |
CompletableFuture<Boolean> |
putAll(String namespace,
Map<String,V> data)
Stores a map of IDs and values into the storage in the given namespace.
|
protected CompletableFuture<Boolean> |
putAllRaw(String namespace,
Map<String,byte[]> data)
Stores a map of IDs and values into the storage in the given namespace.
|
CompletableFuture<Boolean> |
putAllString(String namespace,
Map<String,String> data)
Stores a map of IDs and String values into the storage in the given namespace.
|
protected CompletableFuture<Boolean> |
putRaw(String namespace,
String id,
byte[] value)
Store a given ID and value for that ID into the given namespace in the storage.
|
CompletableFuture<Boolean> |
putString(String namespace,
String id,
String value)
Stores a String for a given String identifier in the given namespace.
|
CompletableFuture<V> |
remove(String namespace,
String id)
Retrieves and removes data stored for a given String identifier as a
Serializable object in the given
namespace. |
protected CompletableFuture<byte[]> |
removeRaw(String namespace,
String id)
Removes a given ID from the given namespace in the storage.
|
CompletableFuture<String> |
removeString(String namespace,
String id)
Retrieves and removes data stored for a given String identifier as a String in the given namespace.
|
CompletableFuture<Boolean> |
repartition(String namespace,
int newPartitionCount)
Repartitions the data into the given new number of partitions for the given namespace.
|
static Map<String,byte[]> |
toByteArrayMap(Map<String,String> input)
|
static byte[] |
toBytes(String input)
Converts a
String to a byte[]. |
static <S> Map<String,S> |
toObjectMap(Map<String,byte[]> input,
Function<byte[],S> converter)
|
static String |
toString(byte[] input)
Converts a byte[] input to a String.
|
static Map<String,String> |
toStringMap(Map<String,byte[]> input)
|
CompletableFuture<Boolean> |
wipe()
Removes all the IDs from the storage across all namespaces.
|
apply, clear, clear, clear, from, get, getAll, getAll, getAll, getAllString, getAllString, getDefaultNamespace, getPartition, getString, hash, numberOfPartitions, put, putAll, putAllString, putString, remove, removeString, repartition, retrieveAll
protected BulletConfig config
public MemoryStorageManager(BulletConfig config)
config
- The BulletConfig
to create this manager with.protected CompletableFuture<Boolean> putRaw(String namespace, String id, byte[] value)
namespace
- The namespace to store the entry in.id
- The unique ID to represent this entry.value
- The value to store for this entry.CompletableFuture
that resolves to true if the storage was successful.protected CompletableFuture<byte[]> getRaw(String namespace, String id)
namespace
- The namespace to retrieve from.id
- The unique ID to retrieve from the storage.CompletableFuture
that resolves to the byte[] value for this ID or null if it does not exist.protected CompletableFuture<Map<String,byte[]>> getAllRaw(String namespace)
namespace
- The namespace to retrieve from.CompletableFuture
that resolves to a Map
of IDs to their stored values as byte[].protected CompletableFuture<byte[]> removeRaw(String namespace, String id)
namespace
- The namespace of the ID.id
- The unique ID to remove from the storage.CompletableFuture
that resolves to the byte[] value for this ID or null if it does not exist.public CompletableFuture<Boolean> wipe()
CompletableFuture
that resolves to true if the wipe was successful.public CompletableFuture<Boolean> clear(String namespace)
namespace
- The namespace to clear.CompletableFuture
that resolves to true if the wipe was successful.public CompletableFuture<Boolean> clear(String namespace, Set<String> ids)
namespace
- The namespace that has these IDs.ids
- The set of IDs to remove from the storage for the given namespace.CompletableFuture
that resolves to true if the wipe was successful and throws otherwise.public CompletableFuture<Boolean> putString(String namespace, String id, String value)
namespace
- The namespace to store this value under.id
- The ID to store this value under.value
- The object to store as the value.CompletableFuture
that resolves to true if the store succeeded.public CompletableFuture<String> getString(String namespace, String id)
namespace
- The namespace of the data.id
- The ID of the data.CompletableFuture
that resolves to the data.public CompletableFuture<Boolean> putAllString(String namespace, Map<String,String> data)
namespace
- The namespace to store the entries in.data
- The map of IDs and values to store.CompletableFuture
that resolves to true if the storage was completely successful.public CompletableFuture<Map<String,String>> getAllString(String namespace)
Map
of IDs to their String values.namespace
- The namespace to retrieve from.CompletableFuture
that resolves to a Map
of IDs to their String values.public CompletableFuture<Map<String,String>> getAllString(String namespace, Set<String> ids)
Map
of IDs to
their String values.namespace
- The namespace of the IDs.ids
- The Set
of IDs to retrieve.CompletableFuture
that resolves to a Map
of IDs to their String values.public CompletableFuture<String> removeString(String namespace, String id)
namespace
- The namespace of the data.id
- The ID of the data.CompletableFuture
that resolves to the data.public CompletableFuture<Map<String,String>> getPartitionString(String namespace, int partition)
getAll(String)
namespace
- The namespace to retrieve the IDs from.partition
- The partition number to return.CompletableFuture
that resolves to a Map
of IDs to their stored values as Strings
or null if no data is present.public static byte[] toBytes(String input)
String
to a byte[].input
- The String input.public static String toString(byte[] input)
input
- The byte[] input.public static Map<String,String> toStringMap(Map<String,byte[]> input)
input
- The String to byte[] map.public static Map<String,byte[]> toByteArrayMap(Map<String,String> input)
input
- The String to byte[] map.public void close()
close
in interface AutoCloseable
protected CompletableFuture<Boolean> putAllRaw(String namespace, Map<String,byte[]> data)
putRaw(String, String, byte[])
in parallel.namespace
- The namespace to store the entries in.data
- The map of IDs and values to store.CompletableFuture
that resolves to true if the storage was completely successful.protected CompletableFuture<Map<String,byte[]>> getAllRaw(String namespace, Set<String> ids)
getRaw(String, String)
repeatedly on each of the given IDs in parallel.namespace
- The namespace of the IDs.ids
- The Set
of IDs to retrieve.CompletableFuture
that resolves to a Map
of IDs to their stored values as byte[].public CompletableFuture<Boolean> put(String namespace, String id, V value)
Serializable
object for a given String identifier in the given namespace.namespace
- The namespace to store this value under.id
- The ID to store this value under.value
- The object to store as the value.CompletableFuture
that resolves to true if the store succeeded.public CompletableFuture<V> get(String namespace, String id)
Serializable
object.namespace
- The namespace of the data.id
- The ID of the data.CompletableFuture
that resolves to the data.public CompletableFuture<Boolean> putAll(String namespace, Map<String,V> data)
namespace
- The namespace to store the entries in.data
- The map of IDs and values to store.CompletableFuture
that resolves to true if the storage was completely successful.public CompletableFuture<Map<String,V>> getAll(String namespace)
Map
of IDs to their
Serializable
values.namespace
- The namespace to retrieve from.CompletableFuture
that resolves to a Map
of IDs to their stored values.public CompletableFuture<Map<String,V>> getAll(String namespace, Set<String> ids)
Map
of IDs to
their Serializable
values.namespace
- The namespace of the IDs.ids
- The Set
of IDs to retrieve.CompletableFuture
that resolves to a Map
of IDs to their stored values.public CompletableFuture<V> remove(String namespace, String id)
Serializable
object in the given
namespace.namespace
- The namespace of the data.id
- The ID of the data.CompletableFuture
that resolves to the data.public int numberOfPartitions(String namespace)
namespace
- The namespace whose partitions are being asked for.protected CompletableFuture<Map<String,byte[]>> getPartitionRaw(String namespace, int partition)
getAllRaw(String)
namespace
- The namespace to retrieve the IDs from.partition
- The partition number to return.CompletableFuture
that resolves to a Map
of IDs to their stored values as byte
arrays or null if no data is present.public CompletableFuture<Map<String,V>> getPartition(String namespace, int partition)
getAll(String)
namespace
- The namespace to retrieve the IDs from.partition
- The partition number to return.CompletableFuture
that resolves to a Map
of IDs to their stored values as Serializable
objects or null if no data is present.public CompletableFuture<Boolean> clear(String namespace, int partition)
namespace
- The namespace for the partition.partition
- The partition to clear.CompletableFuture
that resolves to true if the wipe was successful.public CompletableFuture<Boolean> repartition(String namespace, int newPartitionCount)
namespace
- The namespace to repartition.newPartitionCount
- The new number of partitions to use.CompletableFuture
that resolves to true if the repartitioning was successful.protected V convert(byte[] bytes)
byte[]
to a type of the given object. By default, uses SerializerDeserializer
to
deserialize using Java deserialization.bytes
- The byte[] to convert.protected byte[] convert(V object)
byte[]
. By default, uses SerializerDeserializer
to
serialize using Java serialization.object
- The object to convert.public static <S> Map<String,byte[]> fromObjectMap(Map<String,S> input, Function<S,byte[]> converter)
S
- The type to convert from.input
- The String to the given type map.converter
- The Function
that converts from the given type to byte[].public static <S> Map<String,S> toObjectMap(Map<String,byte[]> input, Function<byte[],S> converter)
S
- The type to convert to.input
- The String to byte[] map.converter
- The Function
that converts from byte[] to the given type.Copyright © 2021. All rights reserved.