Package com.codingchili.core.storage
Class JsonMap<Value extends Storable>
java.lang.Object
com.codingchili.core.storage.JsonMap<Value>
- All Implemented Interfaces:
AsyncStorage<Value>
Map backed by a json-file.
Do not use for data that is changing frequently, as this is extremely inefficient. The dirty-state of the map will be checked to determine when the map should be persisted. This is done in intervals specified in plugin configuration.
this map flushes its contents to disk every now and then.
-
Constructor Summary
ConstructorsConstructorDescriptionJsonMap(io.vertx.core.Promise<AsyncStorage<Value>> promise, StorageContext<Value> context)Creates a new possibly shared instance of the JsonMap storage plugin. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidremoves all existing entries from the storage.voidchecks if an entry exists for the given keycontext()Get the context for the storage.voidget an entry with the given key, if the key does not match a value fails with #ValueMissingExceptionvoidset the entry identified by the given key to the given valuevoidputIfAbsent(Value value, io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler)set the entry if it does not already exists.query()initialize the construction of a query.voidRemoves an entry by its key.voidreturns the amount of entries in the storage.voidupdates the value of the given key if a value already exists.voidGet all values contained within the storage as a stream.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.codingchili.core.storage.AsyncStorage
query
-
Constructor Details
-
JsonMap
Creates a new possibly shared instance of the JsonMap storage plugin. It's recommended to use the storage loader instead of invoking this constructor.- Parameters:
promise- completed when the storage is loaded and ready.context- contains metadata about the stored objects.
-
-
Method Details
-
get
Description copied from interface:AsyncStorageget an entry with the given key, if the key does not match a value fails with #ValueMissingException- Specified by:
getin interfaceAsyncStorage<Value extends Storable>- Parameters:
key- a unique key identifying an entryhandler- callback
-
contains
public void contains(String key, io.vertx.core.Handler<io.vertx.core.AsyncResult<Boolean>> handler)Description copied from interface:AsyncStoragechecks if an entry exists for the given key- Specified by:
containsin interfaceAsyncStorage<Value extends Storable>- Parameters:
key- the key to check if sethandler- callback
-
put
Description copied from interface:AsyncStorageset the entry identified by the given key to the given value- Specified by:
putin interfaceAsyncStorage<Value extends Storable>- Parameters:
value- the value to be set for the given keyhandler- callback
-
putIfAbsent
public void putIfAbsent(Value value, io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler)Description copied from interface:AsyncStorageset the entry if it does not already exists. fails with #ValueAlreadyPresentExceptionif the key already has a value.- Specified by:
putIfAbsentin interfaceAsyncStorage<Value extends Storable>- Parameters:
value- the value to be set if the entry does not exist.handler- callback
-
remove
Description copied from interface:AsyncStorageRemoves an entry by its key.- Specified by:
removein interfaceAsyncStorage<Value extends Storable>- Parameters:
key- identifies the entry to be removed.handler- callback
-
update
Description copied from interface:AsyncStorageupdates the value of the given key if a value already exists.- Specified by:
updatein interfaceAsyncStorage<Value extends Storable>- Parameters:
value- the new value of the entryhandler- callback
-
values
Description copied from interface:AsyncStorageGet all values contained within the storage as a stream. Not recommended to use on large maps.- Specified by:
valuesin interfaceAsyncStorage<Value extends Storable>- Parameters:
handler- callback
-
clear
Description copied from interface:AsyncStorageremoves all existing entries from the storage.- Specified by:
clearin interfaceAsyncStorage<Value extends Storable>- Parameters:
handler- callback
-
query
Description copied from interface:AsyncStorageinitialize the construction of a query.- Specified by:
queryin interfaceAsyncStorage<Value extends Storable>- Returns:
- a builder String for constructing the query.
-
context
Description copied from interface:AsyncStorageGet the context for the storage.- Specified by:
contextin interfaceAsyncStorage<Value extends Storable>- Returns:
- a storage context.
-
addIndex
- Specified by:
addIndexin interfaceAsyncStorage<Value extends Storable>- Parameters:
field- the path to the attribute to index, must include the array token in #CoreStrings.STORAGE_ARRAY.
-
size
Description copied from interface:AsyncStoragereturns the amount of entries in the storage.- Specified by:
sizein interfaceAsyncStorage<Value extends Storable>- Parameters:
handler- callback
-