org.norther.tammi.spray.media
Class DefaultCachedMediaProvider

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.spray.media.DefaultMediaProvider
          extended by org.norther.tammi.spray.media.DefaultCachedMediaProvider
All Implemented Interfaces:
Serializable, NotificationBroadcaster, NotificationEmitter, Manageable, MBeanDelegate, Refreshable, CacheClient<String,Resource<?>>, CachedMediaProvider, MediaProvider
Direct Known Subclasses:
DefaultServletMediaProvider

public class DefaultCachedMediaProvider
extends DefaultMediaProvider
implements CachedMediaProvider

A cached implementation of MediaProvider.

Version:
$Id: DefaultCachedMediaProvider.java,v 1.8 2009/11/13 16:31:45 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Constructor Summary
DefaultCachedMediaProvider()
          Constructs a new provider.
 
Method Summary
 void clearCached()
          Clears all cached entries without notifying.
 void expireCached(long timestamp)
          Expires all cached entries notifying them about expiration.
 void expireCachedResource(String path)
          Expires a cached media content resource.
 void expireFraction(long timestamp, float fraction)
          Expires the specified fraction of cached entries notifying them about expiration.
 ConcurrentMap<String,Resource<?>> getCache(boolean... create)
          Gets and optionally creates the cache.
 Resource<?> getCachedResource(String path)
          Gets a cached media content resource.
 long getCheckInterval()
          Gets the default interval of checking validity of cached resources.
 long getRefreshed()
          Gets the last refresh timestamp.
 Resource<?> getResource(String path, boolean localized, ServletRequest request, ServletResponse response, FilterChain chain)
          Gets the media content resource.
 ObjectName getSharedCacheName()
          Gets the the shared cache of this client.
 int getSizeLimit()
          Gets the default size limit for resources to be kept in the cache.
 boolean isCachingDisabled()
          Checks whether the caching is disabled.
 void refresh()
          Refreshes the MBean.
 void removeCache()
          Removes the cache.
 void setCachedResource(String path, Resource<?> res)
          Sets a cached media content resource.
 void setCachedResource(String path, Resource<?> res, int freq)
          Sets a cached media content resource with an expiration frequency.
 void setCachingDisabled(boolean flag)
          Sets the caching disabled flag.
 void setCheckInterval(long msecs)
          Sets the default interval of checking validity of cached resources.
 void setSharedCacheName(ObjectName cache)
          Sets the shared cache of this client.
 void setSizeLimit(int limit)
          Sets the default size limit for resources to be kept in the cache.
 
Methods inherited from class org.norther.tammi.spray.media.DefaultMediaProvider
addMediaKey, addMediaKey, clearMediaKeys, getDefaultIndex, getDefaultIndex, getMediaKeys, removeMediaKey, setDefaultIndex, setMediaKeys
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, postmanaged, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unmanaged, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.spray.media.MediaProvider
addMediaKey, addMediaKey, clearMediaKeys, getDefaultIndex, getMediaKeys, removeMediaKey, setDefaultIndex, setMediaKeys
 

Constructor Detail

DefaultCachedMediaProvider

public DefaultCachedMediaProvider()
Constructs a new provider.

Method Detail

isCachingDisabled

public boolean isCachingDisabled()
Description copied from interface: CacheClient
Checks whether the caching is disabled.

Specified by:
isCachingDisabled in interface CacheClient<String,Resource<?>>
Returns:
true if the caching is disabled, true otherwise.

setCachingDisabled

public void setCachingDisabled(boolean flag)
Description copied from interface: CacheClient
Sets the caching disabled flag.

Specified by:
setCachingDisabled in interface CacheClient<String,Resource<?>>
Parameters:
flag - the caching disabled flag.

expireCached

public void expireCached(long timestamp)
Description copied from interface: CacheClient
Expires all cached entries notifying them about expiration.

Specified by:
expireCached in interface CacheClient<String,Resource<?>>
Parameters:
timestamp - the timestamp of the expiration.

expireFraction

public void expireFraction(long timestamp,
                           float fraction)
Description copied from interface: CacheClient
Expires the specified fraction of cached entries notifying them about expiration.

Specified by:
expireFraction in interface CacheClient<String,Resource<?>>
Parameters:
timestamp - the timestamp of the expiration.
fraction - the fraction of entries to expire (0.0..1.0).

clearCached

public void clearCached()
Description copied from interface: CacheClient
Clears all cached entries without notifying.

Specified by:
clearCached in interface CacheClient<String,Resource<?>>

getCache

public ConcurrentMap<String,Resource<?>> getCache(boolean... create)
Description copied from interface: CacheClient
Gets and optionally creates the cache.

Specified by:
getCache in interface CacheClient<String,Resource<?>>
Parameters:
create - true to create a missing cache.
Returns:
the cache or null if disabled.

removeCache

public void removeCache()
Description copied from interface: CacheClient
Removes the cache.

Specified by:
removeCache in interface CacheClient<String,Resource<?>>

getSharedCacheName

public ObjectName getSharedCacheName()
Description copied from interface: CacheClient
Gets the the shared cache of this client.

Specified by:
getSharedCacheName in interface CacheClient<String,Resource<?>>
Returns:
the object name of the shared cache or a query.

setSharedCacheName

public void setSharedCacheName(ObjectName cache)
Description copied from interface: CacheClient
Sets the shared cache of this client. If it is not set, the default one will be used.

Specified by:
setSharedCacheName in interface CacheClient<String,Resource<?>>
Parameters:
cache - the object name of the shared cache or a query.

refresh

public void refresh()
Description copied from interface: Refreshable
Refreshes the MBean.

Specified by:
refresh in interface Refreshable

getRefreshed

public long getRefreshed()
Description copied from interface: Refreshable
Gets the last refresh timestamp.

Specified by:
getRefreshed in interface Refreshable
Returns:
the timestamp of the last refresh.

getResource

public Resource<?> getResource(String path,
                               boolean localized,
                               ServletRequest request,
                               ServletResponse response,
                               FilterChain chain)
                        throws IOException,
                               ConstructionException,
                               AccessDeniedException
Description copied from interface: MediaProvider
Gets the media content resource.

Specified by:
getResource in interface MediaProvider
Overrides:
getResource in class DefaultMediaProvider
Parameters:
path - the content path.
localized - the localization option.
request - the servlet request.
response - the servlet response.
chain - the filter chain.
Returns:
the resource source.
Throws:
IOException - on I/O errors.
ConstructionException - on resource errors.
AccessDeniedException - for access restrictions.

getCheckInterval

public long getCheckInterval()
Description copied from interface: CachedMediaProvider
Gets the default interval of checking validity of cached resources.

Specified by:
getCheckInterval in interface CachedMediaProvider
Returns:
the check interval in milliseconds.

setCheckInterval

public void setCheckInterval(long msecs)
Description copied from interface: CachedMediaProvider
Sets the default interval of checking validity of cached resources.

Specified by:
setCheckInterval in interface CachedMediaProvider
Parameters:
msecs - the check interval in milliseconds (-1 = only once).

getSizeLimit

public int getSizeLimit()
Description copied from interface: CachedMediaProvider
Gets the default size limit for resources to be kept in the cache.

Specified by:
getSizeLimit in interface CachedMediaProvider
Returns:
the limit for a resource size in bytes.

setSizeLimit

public void setSizeLimit(int limit)
Description copied from interface: CachedMediaProvider
Sets the default size limit for resources to be kept in the cache.

Specified by:
setSizeLimit in interface CachedMediaProvider
Parameters:
limit - a limit for a resource size in bytes (-1 = unlimited).

getCachedResource

public Resource<?> getCachedResource(String path)
Description copied from interface: CachedMediaProvider
Gets a cached media content resource.

Specified by:
getCachedResource in interface CachedMediaProvider
Parameters:
path - the content path.
Returns:
the cached resource or null.

setCachedResource

public void setCachedResource(String path,
                              Resource<?> res)
Description copied from interface: CachedMediaProvider
Sets a cached media content resource.

Specified by:
setCachedResource in interface CachedMediaProvider
Parameters:
path - the content path.
res - the cached resource.

setCachedResource

public void setCachedResource(String path,
                              Resource<?> res,
                              int freq)
Description copied from interface: CachedMediaProvider
Sets a cached media content resource with an expiration frequency.

Specified by:
setCachedResource in interface CachedMediaProvider
Parameters:
path - the content path.
res - the cached resource.
freq - the expiration frequency.

expireCachedResource

public void expireCachedResource(String path)
Description copied from interface: CachedMediaProvider
Expires a cached media content resource.

Specified by:
expireCachedResource in interface CachedMediaProvider
Parameters:
path - the content path.


Copyright © 2004 The Norther Organization. All rights reserved.