public class MappingStoreService extends Object implements StoreService
StoreService depending on the stored value class.
Can acquire an instance through create() and configure it afterwards.
Can be used like this to suppress storing certain entities:
DiscordClient client = new DiscordClientBuilder(token)
.setStoreService(MappingStoreService.create()
.setMapping(new NoOpStoreService(), MessageBean.class)
.setFallback(new JdkStoreService()))
.build();
| Modifier and Type | Method and Description |
|---|---|
static MappingStoreService |
create()
Obtain a new
MappingStoreService instance that can be further configured using
setMapping(StoreService, Class) to set a new delegate StoreService and
setFallback(StoreService) to provide a fallback if the value class is not defined elsewhere. |
Mono<Void> |
dispose()
This is a lifecycle method called to signal that a store should dispose of any resources due to
an abrupt close (hard reconnect or disconnect).
|
boolean |
hasGenericStores()
This is used to check if this service can provide generic stores.
|
boolean |
hasLongObjStores()
This is used to check if this service can provide long-object stores.
|
void |
init(StoreContext context)
This is a lifecycle method called to signal that a store should allocate any necessary resources.
|
<K extends Comparable<K>,V> |
provideGenericStore(Class<K> keyClass,
Class<V> valueClass)
This is called to provide a new store instance for the provided configuration.
|
<V> LongObjStore<V> |
provideLongObjStore(Class<V> valueClass)
This is called to provide a new store instance with a long key and object values.
|
MappingStoreService |
setFallback(StoreService storeService)
Set the fallback
StoreService to use if no mapping was previously defined for a given type. |
MappingStoreService |
setMapping(StoreService storeService,
Class<?> valueClass)
Set a new delegate
StoreService for the given value class. |
MappingStoreService |
setMappings(StoreService storeService,
Class<?>... valueClasses)
Set a new delegate
StoreService for multiple given value classes. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitorderpublic static MappingStoreService create()
MappingStoreService instance that can be further configured using
setMapping(StoreService, Class) to set a new delegate StoreService and
setFallback(StoreService) to provide a fallback if the value class is not defined elsewhere.NoOpStoreService as fallback for all types, can be configured.public MappingStoreService setMapping(StoreService storeService, Class<?> valueClass)
StoreService for the given value class.storeService - the service to use for the valuesvalueClass - the value class to map to the given serviceMappingStoreService with updated propertiespublic MappingStoreService setMappings(StoreService storeService, Class<?>... valueClasses)
StoreService for multiple given value classes.storeService - the service to use for the valuesvalueClasses - the list of value classes to map to the given serviceMappingStoreService with updated propertiespublic MappingStoreService setFallback(@Nullable StoreService storeService)
StoreService to use if no mapping was previously defined for a given type.storeService - the fallback serviceMappingStoreService with updated propertiespublic boolean hasGenericStores()
StoreServicehasGenericStores in interface StoreServiceStorepublic <K extends Comparable<K>,V> Store<K,V> provideGenericStore(Class<K> keyClass, Class<V> valueClass)
StoreServiceprovideGenericStore in interface StoreServiceK - The key type which provides a 1:1 mapping to the value type. This type is also expected to be
Comparable in order to allow for range operations.V - The value type, these follow
JavaBean conventions.keyClass - The class of the keys.valueClass - The class of the values.public boolean hasLongObjStores()
StoreServicehasLongObjStores in interface StoreServiceLongObjStorepublic <V> LongObjStore<V> provideLongObjStore(Class<V> valueClass)
StoreServiceprovideLongObjStore in interface StoreServiceV - The value type, these follow
JavaBean conventions.valueClass - The class of the values.public void init(StoreContext context)
StoreServiceinit in interface StoreServicecontext - Some context about the environment which this service is being utilized in.public Mono<Void> dispose()
StoreServicedispose in interface StoreService