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 as AutoCloseable 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, the removeAndGetIfPresent will let out access the removed value, and won't close them.

    Since:
    8.3.0
    Author:
    XIMA MEDIA GmbH
    • Method Detail

      • isOpen

        boolean isOpen()
        Checks whether this store manager is still open. If it is not open, all methods will throw an IllegalStateException. See AutoCloseable.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.