public class StorageServiceImpl extends java.lang.Object implements StorageService, CanReleaseResources
| Modifier and Type | Field and Description |
|---|---|
protected java.util.Map<java.lang.Class<?>,ExpirationCache<java.lang.Object,?>> |
caches |
protected java.util.concurrent.ScheduledExecutorService |
cleanupExecutor |
protected static long |
DEFAULT_CLEANUP_INTERVAL_NANOS |
protected static java.util.Map<java.lang.Class<?>,java.util.function.Supplier<ExpirationCache<java.lang.Object,?>>> |
defaultCacheSuppliers |
protected EventPublisher |
publisher |
| Constructor and Description |
|---|
StorageServiceImpl(EventPublisher publisher) |
StorageServiceImpl(long cleanupIntervalNanos,
EventPublisher publisher) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear(java.lang.Class<?> itemClass)
Clears all items of the given item class.
|
void |
clearAll()
Clears all items from the storage service.
|
boolean |
exists(java.lang.Class<?> itemClass,
java.lang.Object key)
Indicates whether an item exists under the given item class and key.
|
<V> V |
get(java.lang.Class<V> itemClass,
@NonNull java.lang.Object key)
Gets an item stored in the storage service.
|
<V> V |
get(java.lang.Class<V> itemClass,
@NonNull java.lang.Object key,
boolean registerDataAccess)
Gets an item stored in the storage service.
|
java.util.List<Pair<java.lang.String,java.lang.Object>> |
getSnapshotState() |
protected void |
initCleanupThread(long cleanupIntervalNanos) |
<V> void |
registerItemClassIfAbsent(java.lang.Class<V> itemClass,
boolean isRenewableExpiration,
long timeToLiveNanos,
@Nullable ShouldDisposeFunc<V> shouldDisposeFunc,
@Nullable ItemDisposalFunc<V> itemDisposalFunc)
Registers a new item class with the storage service.
|
void |
releaseResources()
An object that implements this interface should release all acquired resources assuming it may
be disposed at any time.
|
void |
remove(java.lang.Class<?> itemClass,
java.lang.Object key)
Removes an item stored under the given item class.
|
protected void |
removeExpiredItems() |
<V> void |
set(java.lang.Object key,
V value)
Stores an item in the storage service under the given item class.
|
int |
size(java.lang.Class<?> itemClass) |
protected static final long DEFAULT_CLEANUP_INTERVAL_NANOS
protected static final java.util.Map<java.lang.Class<?>,java.util.function.Supplier<ExpirationCache<java.lang.Object,?>>> defaultCacheSuppliers
protected final EventPublisher publisher
protected final java.util.Map<java.lang.Class<?>,ExpirationCache<java.lang.Object,?>> caches
protected final java.util.concurrent.ScheduledExecutorService cleanupExecutor
public StorageServiceImpl(EventPublisher publisher)
public StorageServiceImpl(long cleanupIntervalNanos,
EventPublisher publisher)
protected void initCleanupThread(long cleanupIntervalNanos)
protected void removeExpiredItems()
public <V> void registerItemClassIfAbsent(java.lang.Class<V> itemClass,
boolean isRenewableExpiration,
long timeToLiveNanos,
@Nullable ShouldDisposeFunc<V> shouldDisposeFunc,
@Nullable ItemDisposalFunc<V> itemDisposalFunc)
StorageServiceregisterItemClassIfAbsent in interface StorageServiceV - the type of item that will be stored under the item class.itemClass - the class of the item that will be stored, eg `CustomEndpointInfo.class`.isRenewableExpiration - controls whether the item's expiration should be renewed if the item is fetched,
regardless of whether it is already expired or not.timeToLiveNanos - how long an item should be stored before being considered expired, in nanoseconds.shouldDisposeFunc - a function defining whether an item should be disposed if expired. If null is passed,
the item will always be disposed if expired.itemDisposalFunc - a function defining how to dispose of an item when it is removed. If null is
passed, the item will be removed without performing any additional operations.public <V> void set(java.lang.Object key,
V value)
StorageServiceset in interface StorageServiceV - the type of the item being retrieved.key - the key for the item, eg "custom-endpoint.cluster-custom-XYZ.us-east-2.rds.amazonaws.com:5432".value - the item to store.public <V> V get(java.lang.Class<V> itemClass,
@NonNull java.lang.Object key)
StorageServiceget in interface StorageServiceV - the type of the item being retrieved.itemClass - the expected class of the item being retrieved, eg `CustomEndpointInfo.class`.key - the key for the item, eg "custom-endpoint.cluster-custom-XYZ.us-east-2.rds.amazonaws.com:5432".public <V> V get(java.lang.Class<V> itemClass,
@NonNull java.lang.Object key,
boolean registerDataAccess)
StorageServiceget in interface StorageServiceV - the type of the item being retrieved.itemClass - the expected class of the item being retrieved, eg `CustomEndpointInfo.class`.key - the key for the item, eg "custom-endpoint.cluster-custom-XYZ.us-east-2.rds.amazonaws.com:5432".registerDataAccess - true if accessing cached data requires registering data access.public boolean exists(java.lang.Class<?> itemClass,
java.lang.Object key)
StorageServiceexists in interface StorageServiceitemClass - the class of the item.key - the key for the item, eg "custom-endpoint.cluster-custom-XYZ.us-east-2.rds.amazonaws.com:5432".public void remove(java.lang.Class<?> itemClass,
java.lang.Object key)
StorageServiceremove in interface StorageServiceitemClass - the class of the item.key - the key for the item, eg "custom-endpoint.cluster-custom-XYZ.us-east-2.rds.amazonaws.com:5432".public void clear(java.lang.Class<?> itemClass)
StorageServiceclear in interface StorageServiceitemClass - the class of the items to clear.public void clearAll()
StorageServiceclearAll in interface StorageServicepublic void releaseResources()
CanReleaseResourcesCalling this method does NOT mean that an object is disposing and there won't be any further calls. An object should keep its functional state after calling this method.
releaseResources in interface CanReleaseResourcespublic int size(java.lang.Class<?> itemClass)
size in interface StorageServicepublic java.util.List<Pair<java.lang.String,java.lang.Object>> getSnapshotState()
getSnapshotState in interface StateSnapshotProvider