Interface IResourceStoreManager
-
- All Superinterfaces:
AutoCloseable
public interface IResourceStoreManager extends AutoCloseable
A resource store manager. This is not intended to be used as a cache for potentially large amounts of data, use e.g. EHCache or Guava's cache implementation for that. It is intended to be a manager for short-lived (e.g. view scoped beans) computed resources such asAutoCloseable
or file references that need to be released when the lifecycle of the object holding this manager ends.A store manager lets you access different typed stores for different types of keys and values. There are two store variants: a "normal" store and a versioned store. A normal store allows associating a single value with a key. A versioned store allows binds the liveness of a value to a version. For example, the key could be a file, the version the last modified date of the file, and the value some data computed from the file contents, such as a thumbnail or the dimensions of an image. The versioned store will automatically discard stale values and reloads them when the version changes.
Unless a method explicitly states otherwise, all values that implement
AutoCloseable
will be closed either when they are removed from the store, or when the manager is closed, whichever comes first. In particular, theremoveAndGetIfPresent
will let out access the removed value, and won't close them.- Since:
- 8.3.0
- Author:
- XIMA MEDIA GmbH
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
IResourceStoreManager.IResourceStore<Key,Value>
Manages values associated with a certain type of key.static interface
IResourceStoreManager.IResourceStoreBase<Key,Value>
Manages values associated with a certain type of key.static interface
IResourceStoreManager.IResourceStoreWithLoader<Key,Value>
Same asIResourceStoreManager.IResourceStore
, but with a bound loader that does not need to be specified each time when requesting a value for a key.static interface
IResourceStoreManager.IVersionedResourceStore<Key,Value>
Manages values associated with a certain type of key.static interface
IResourceStoreManager.IVersionedResourceStoreBase<Key,Value>
Manages values associated with a certain type of key.static interface
IResourceStoreManager.IVersionedResourceStoreWithLoader<Key,Value>
Same asIResourceStoreManager.IVersionedResourceStore
, but with a bound loader that does not need to be specified each time when requesting a value for a key.static interface
IResourceStoreManager.IVersionedResourceStoreWithLoaderAndVersionExtractor<Key,Value>
Same asIResourceStoreManager.IVersionedResourceStore
, but with a loader and bound version extractor that do not need to be specified each time when requesting a value for a key.static interface
IResourceStoreManager.IVersionedResourceStoreWithLoaderBase<Key,Value>
Same asIResourceStoreManager.IVersionedResourceStore
, but with a bound loader that does not need to be specified each time when requesting a value for a key.static interface
IResourceStoreManager.IVersionedResourceStoreWithVersionExtractor<Key,Value>
Same asIResourceStoreManager.IVersionedResourceStore
, but with a bound version extractor that does not need to be specified each time when requesting a value for a key.static interface
IResourceStoreManager.IVersionedResourceStoreWithVersionExtractorBase<Key,Value>
Same asIResourceStoreManager.IVersionedResourceStore
, but with a bound version extractor that does not need to be specified each time when requesting a value for a key.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description boolean
isOpen()
Checks whether this store manager is still open.<Key,Value>
IResourceStoreManager.IResourceStore<Key,Value>storeFor(Class<Key> keyType, Class<Value> valueType)
Gets a store for the given key and value types, which can be used to associate a value with a particular key.default <Key,Value>
IResourceStoreManager.IResourceStore<Key,Value>storeFor(Key key, Class<Value> valueType)
Gets a store for the given key and value types, which can be used to associate a value with a particular key.<Key,Value>
IResourceStoreManager.IVersionedResourceStore<Key,Value>versionedStoreFor(Class<Key> keyType, Class<Value> valueType)
Gets a versioned store for the given key and value types, which can be used to associate a value with a particular key and version.default <Key,Value>
IResourceStoreManager.IVersionedResourceStore<Key,Value>versionedStoreFor(Key key, Class<Value> valueType)
Gets a versioned store for the given key and value types, which can be used to associate a value with a particular key and version.-
Methods inherited from interface java.lang.AutoCloseable
close
-
-
-
-
Method Detail
-
isOpen
boolean isOpen()
Checks whether this store manager is still open. If it is not open, all methods will throw anIllegalStateException
. SeeAutoCloseable.close()
.- Returns:
- True if the store manager is still open, false otherwise.
-
storeFor
default <Key,Value> IResourceStoreManager.IResourceStore<Key,Value> storeFor(Key key, Class<Value> valueType)
Gets a store for the given key and value types, which can be used to associate a value with a particular key. Multiple calls to this method with the same type will return the same store.This method does the same as
storeFor(Class, Class)
, but with the key type inferred from the key instance. This helps to avoid unchecked warnings when the key type has type parameters.- Type Parameters:
Key
- The type of the key.Value
- The type of the value.- Parameters:
key
- An instance of the key type.valueType
- The type of the associated value.- Returns:
- The store for associating values with keys.
-
storeFor
<Key,Value> IResourceStoreManager.IResourceStore<Key,Value> storeFor(Class<Key> keyType, Class<Value> valueType)
Gets a store for the given key and value types, which can be used to associate a value with a particular key. Multiple calls to this method with the same type will return the same store.- Type Parameters:
Key
- The type of the key.Value
- The type of the value.- Parameters:
keyType
- The type of the key.valueType
- The type of the associated value.- Returns:
- The store for associating values with keys.
-
versionedStoreFor
default <Key,Value> IResourceStoreManager.IVersionedResourceStore<Key,Value> versionedStoreFor(Key key, Class<Value> valueType)
Gets a versioned store for the given key and value types, which can be used to associate a value with a particular key and version. When the version changes, the existing value will be considered stale and removed; and a new value will be loaded using the configured loader. Multiple calls to this method with the same type will return the same store.This method does the same as
versionedStoreFor(Class, Class)
, but with the key type inferred from the key instance. This helps to avoid unchecked warnings when the key type has type parameters.- Type Parameters:
Key
- The type of the key.Value
- The type of the value.- Parameters:
key
- An instance of the key type.valueType
- The type of the associated value.- Returns:
- The store for associating values with keys.
-
versionedStoreFor
<Key,Value> IResourceStoreManager.IVersionedResourceStore<Key,Value> versionedStoreFor(Class<Key> keyType, Class<Value> valueType)
Gets a versioned store for the given key and value types, which can be used to associate a value with a particular key and version. When the version changes, the existing value will be considered stale and removed; and a new value will be loaded using the configured loader. Multiple calls to this method with the same type will return the same store.- Type Parameters:
Key
- The type of the key.Value
- The type of the value.- Parameters:
keyType
- The type of the key.valueType
- The type of the associated value.- Returns:
- The store for associating values with keys.
-
-