public class CacheManagerImpl extends Object implements ICacheManager, IShutdownListener, IConfigListener, IDependenciesListener, IOptionsListener
ICacheManager.CreateCompletionCallback
Constructor and Description |
---|
CacheManagerImpl(IAggregator aggregator,
long stamp)
Starts up the cache.
|
Modifier and Type | Method and Description |
---|---|
void |
clearCache()
Clears the cache
|
void |
configLoaded(IConfig config,
long sequence)
This method is called when the config is loaded/reloaded, after the
config has been modified by any registered
IConfigModifier
services. |
void |
createCacheFileAsync(String fileNamePrefix,
InputStream is,
ICacheManager.CreateCompletionCallback callback)
Utility method to create a cache file on an asynchronous thread.
|
void |
createCacheFileAsync(String fileNamePrefix,
Reader reader,
ICacheManager.CreateCompletionCallback callback)
Utility method to create a cache file on an asynchronous thread.
|
void |
createNamedCacheFileAsync(String filename,
InputStream is,
ICacheManager.CreateCompletionCallback callback)
Utility method to create a cache file on an asynchronous thread.
|
void |
createNamedCacheFileAsync(String fileNamePrefix,
Reader reader,
ICacheManager.CreateCompletionCallback callback)
Utility method to create a cache file on an asynchronous thread.
|
void |
deleteFileDelayed(String fname)
Utility method to asynchronously delete cache files after a delay
period specified by
IOptions.getDeleteDelay() . |
void |
dependenciesLoaded(IDependencies deps,
long sequence)
This method is called when dependencies are loaded/reloaded/validated.
|
void |
dumpCache(Writer writer,
Pattern filter)
Outputs the string representation of the cache to the specified
writer, filtered using the specified regular expression pattern
|
void |
externalizeCacheObjectAsync(String fileNamePrefix,
Object object,
ICacheManager.CreateCompletionCallback callback)
Utility method to externalize an object on an asynchronous thread.
|
ICache |
getCache()
Returns the current cache object
|
File |
getCacheDir()
Returns the
File object for the cache directory. |
protected void |
notifyInit()
Notify listeners that the cache manager is initialized.
|
void |
optionsUpdated(IOptions options,
long sequence)
This method is called when the options are loaded/changed.
|
void |
serializeCache()
Serializes the specified cache object to the sepecified directory.
|
void |
shutdown(IAggregator aggregator)
This method is called from within the aggregator's
GenericServlet.destroy() method to notify listeners that the servlet
is shutting down. |
public CacheManagerImpl(IAggregator aggregator, long stamp) throws IOException
aggregator
- the aggregator instance this cache manager belongs tostamp
- a time stamp used to determine if the cache should be cleared.
The cache should be cleared if the time stamp is later than
the one associated with the cached resources.IOException
public void clearCache()
ICacheManager
clearCache
in interface ICacheManager
public void dumpCache(Writer writer, Pattern filter) throws IOException
ICacheManager
dumpCache
in interface ICacheManager
writer
- The writer object to output tofilter
- The regular expression filter, or nullIOException
public void shutdown(IAggregator aggregator)
IShutdownListener
GenericServlet.destroy()
method to notify listeners that the servlet
is shutting down.shutdown
in interface IShutdownListener
aggregator
- The aggregator that is shutting downpublic File getCacheDir()
ICacheManager
File
object for the cache directory.getCacheDir
in interface ICacheManager
public ICache getCache()
ICacheManager
getCache
in interface ICacheManager
public void serializeCache()
serializeCache
in interface ICacheManager
public void createCacheFileAsync(String fileNamePrefix, Reader reader, ICacheManager.CreateCompletionCallback callback)
ICacheManager
createCacheFileAsync
in interface ICacheManager
fileNamePrefix
- The prefix to use for the generated file namereader
- The Reader
to read the file contents fromcallback
- The completion callbackpublic void createCacheFileAsync(String fileNamePrefix, InputStream is, ICacheManager.CreateCompletionCallback callback)
ICacheManager
createCacheFileAsync
in interface ICacheManager
fileNamePrefix
- The prefix to use for the generated file nameis
- The InputStream
to read the file contents fromcallback
- The completion callbackpublic void externalizeCacheObjectAsync(String fileNamePrefix, Object object, ICacheManager.CreateCompletionCallback callback)
ICacheManager
externalizeCacheObjectAsync
in interface ICacheManager
fileNamePrefix
- The prefix to use for the generated file nameobject
- The object to externalizecallback
- The completion callbackpublic void createNamedCacheFileAsync(String filename, InputStream is, ICacheManager.CreateCompletionCallback callback)
ICacheManager
createNamedCacheFileAsync
in interface ICacheManager
filename
- The filename of the cache file. The cache file with the
specified name will be created in the cache directory. The
filename may not include a path componentis
- The InputStream
to read the file contents fromcallback
- The completion callbackpublic void createNamedCacheFileAsync(String fileNamePrefix, Reader reader, ICacheManager.CreateCompletionCallback callback)
ICacheManager
createNamedCacheFileAsync
in interface ICacheManager
fileNamePrefix
- The filename of the cache file. The cache file with the
specified name will be created in the cache directory. The
filename may not include a path componentreader
- The Reader
to read the file contents fromcallback
- The completion callbackpublic void deleteFileDelayed(String fname)
ICacheManager
IOptions.getDeleteDelay()
. The idea is
to delay deleting the cache file long enough so that any threads
which may be using the file at the time this method is called have
finished with it and no longer need it. Note that the file may be
deleted before the delay time has expired if the aggregator is
shutdown before the delay time has expireddeleteFileDelayed
in interface ICacheManager
fname
- The name of the cache file to delete.public void optionsUpdated(IOptions options, long sequence)
IOptionsListener
optionsUpdated
in interface IOptionsListener
options
- The new options. Note that changes to the options may occur
in-place, using the same IOptions object with updated values,
or may result in a new object instance. This interface does not
specify which approach is used by an implementation.sequence
- The sequence number. Notifications for different listener
events (options, config, dependencies) that have the same
cause have the same sequence number. The sequence number is
incremented for subsequent event causes, but there is no
guarantee about the the values for subsequent notifications
other than that they will be increasing.public void dependenciesLoaded(IDependencies deps, long sequence)
IDependenciesListener
IDependencies.getLastModified()
to detect when the dependencies
have changed.dependenciesLoaded
in interface IDependenciesListener
deps
- The dependencies object. Note that changes to the dependencies
may occur in-place, using the same IDependencies object with
updated values, or may result in a new IDependencies object.
This interface does not specify which approach is used by an
implementation.sequence
- The sequence number. Notifications for different listener
events (options, config, dependencies) that have the same cause
have the same sequence number. Notifications resulting from
servlet initialization have the sequence number 1. The sequence
number is incremented for subsequent event causes, but there
is no guarantee about the the values for subsequent notifications
other than that they will be increasing.public void configLoaded(IConfig config, long sequence)
IConfigListener
IConfigModifier
services.configLoaded
in interface IConfigListener
config
- The new config object. In order to detect and react to config
changes, you can save the value returned from
IConfig.toString()
and compare it with the value
returned in subsequent configLoaded events.sequence
- The sequence number. Notifications for different listener
events (options, config, dependencies) that have the same
cause have the same sequence number. Notifications resulting
from servlet initialization have the sequence number 1. The
sequence number is incremented for subsequent event causes,
but there is no guarantee about the the values for subsequent
notifications other than that they will be increasing.protected void notifyInit()
Copyright © 2011-2015 IBM. All Rights Reserved.