Class AbstractAssetManager<K,V>
java.lang.Object
com.inductiveautomation.ignition.common.lifecycle.AbstractLifecycle
com.inductiveautomation.perspective.gateway.assets.AbstractAssetManager<K,V>
- Type Parameters:
K
- The type of key for the asset cacheV
- The type of value for the asset cache
- Direct Known Subclasses:
FontManagerImpl
,IconManagerImpl
,ThemeManagerImpl
Base class for managing static assets. During
setup()
files from the injected asset's defaults will be
moved to the respective assets directory in the system home directory
even if
they do exist. Uses a FileWatcher
to react to changes to the injected asset directory under the perspective
modules directory of the system home directory. Changes in the watched asset directory will cause the in memory
cache to be updated. Extensions of this class must override generateKey(Path)
and
parseValue(Path)
so that this class may update its cache with the appropriate entry.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Path
protected final Object
protected final PerspectiveContext
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractAssetManager
(PerspectiveContext perspectiveContext, String asset) AbstractAssetManager
(PerspectiveContext perspectiveContext, String asset, FileFilter fileFilter) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
copyInputStreamToPath
(InputStream is, Path pathTo) protected void
copyInputStreamToPath
(String name, byte[] defaultAssetData, byte[] defaultAssetDigest, byte[] existingAssetDigest) protected CopyOption[]
copyOptions
(byte[] existingAssetDigest, byte[] currentExistingAssetDigest) generateKey
(Path path) Generate a cache key for the givenPath
getCache()
Fetch a copy of the cachegetCachedValue
(K key) Fetch the cached value associated with a keyOptional<com.inductiveautomation.ignition.common.gson.JsonObject>
getDigestFor
(K assetKey) If the assetKey exists in the cache and it's been hashed, the digest may be retrieved for the asset nameprotected void
Invoked within a synchronized block, that holds onto the cache lock, when there is a create, modify, or delete watch event.protected void
protected void
parseValue
(Path path) Parse the cache value for the givenPath
void
setup()
Setup the Asset Manager.Methods inherited from class com.inductiveautomation.ignition.common.lifecycle.AbstractLifecycle
isRunning, shutdown, startup
-
Field Details
-
perspectiveContext
-
assetPath
-
cacheLock
-
-
Constructor Details
-
AbstractAssetManager
-
AbstractAssetManager
public AbstractAssetManager(@Nonnull PerspectiveContext perspectiveContext, @Nonnull String asset, @Nonnull FileFilter fileFilter)
-
-
Method Details
-
getCache
Fetch a copy of the cache- Returns:
- A copy of the cache
-
getCachedValue
Fetch the cached value associated with a key- Parameters:
key
- The cache key- Returns:
- An
Optional
containing the cached value associated with the given key, or an empty Optional of there is no such cached value associated with the given key
-
copyInputStreamToPath
protected void copyInputStreamToPath(@Nonnull InputStream is, @Nonnull Path pathTo) throws IOException - Throws:
IOException
-
copyOptions
protected CopyOption[] copyOptions(@Nonnull byte[] existingAssetDigest, @Nonnull byte[] currentExistingAssetDigest) -
copyInputStreamToPath
protected void copyInputStreamToPath(@Nonnull String name, @Nonnull byte[] defaultAssetData, @Nonnull byte[] defaultAssetDigest, @Nullable byte[] existingAssetDigest) throws IOException - Throws:
IOException
-
getDigestCopy
- Returns:
- a copy of the digests object, if present, otherwise empty optional
-
getDigestFor
If the assetKey exists in the cache and it's been hashed, the digest may be retrieved for the asset name- Parameters:
assetKey
- the name of the asset being cached, generally the filename of the asset- Returns:
- optional containing the digest for the named asset
-
setup
public void setup()Setup the Asset Manager. Copies any defaults into the asset home directory. Should be run beforeAbstractLifecycle.startup()
-
onStartup
protected void onStartup()- Specified by:
onStartup
in classAbstractLifecycle
-
onShutdown
protected void onShutdown()- Specified by:
onShutdown
in classAbstractLifecycle
-
generateKey
Generate a cache key for the givenPath
-
parseValue
Parse the cache value for the givenPath
-
onCacheChanged
protected void onCacheChanged()Invoked within a synchronized block, that holds onto the cache lock, when there is a create, modify, or delete watch event. Invoked immediately following modification of the cache, the cache values and digest will be updated prior to being called. Override this method to update any cache local to the subclass.
-