Package org.atmosphere.cache
Class AbstractBroadcasterCache
- java.lang.Object
-
- org.atmosphere.cache.AbstractBroadcasterCache
-
- All Implemented Interfaces:
BroadcasterCache,AtmosphereConfigAware
- Direct Known Subclasses:
SessionBroadcasterCache
public abstract class AbstractBroadcasterCache extends java.lang.Object implements BroadcasterCache
AbstractBroadcasterCachewhich is used to implement headers, query parameters or session based caching.- Author:
- Paul Khodchenkov, Jeanfrancois Arcand
-
-
Field Summary
Fields Modifier and Type Field Description protected AtmosphereConfigconfigprotected java.util.List<java.lang.Object>emptyListprotected java.util.List<BroadcasterCacheInspector>inspectorsprotected longinvalidateCacheIntervalprotected booleanisSharedprotected java.util.List<BroadcasterCacheListener>listenersprotected longmaxCacheTimeprotected java.util.List<CacheMessage>messagesprotected java.util.Set<java.lang.String>messagesIdsprotected java.util.concurrent.locks.ReadWriteLockreadWriteLockprotected java.util.concurrent.ScheduledExecutorServicereaperprotected java.util.concurrent.ScheduledFuture<?>scheduledFuture-
Fields inherited from interface org.atmosphere.cpr.BroadcasterCache
DEFAULT, NULL
-
-
Constructor Summary
Constructors Constructor Description AbstractBroadcasterCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BroadcasterCacheaddBroadcasterCacheListener(BroadcasterCacheListener l)Add aBroadcasterCacheListenerBroadcasterCachecacheCandidate(java.lang.String broadcasterId, java.lang.String uuid)Add aAtmosphereResource.uuid()to the list of activeAtmosphereResourceMessage will be cached for the resource associated with the uuid.voidcleanup()Clean resources associated with this instance.BroadcasterCacheclearCache(java.lang.String broadcasterId, java.lang.String uuid, CacheMessage cache)Remove the previously cached message.voidconfigure(AtmosphereConfig config)Configure an AtmosphereFramework object.BroadcasterCacheexcludeFromCache(java.lang.String broadcasterId, AtmosphereResource r)Allow an application to exclude, or block, anAtmosphereResourceto received cached message.protected java.util.List<java.lang.Object>get(long cacheHeaderTime)protected booleaninspect(BroadcastMessage m)BroadcasterCacheinspector(BroadcasterCacheInspector b)Add aBroadcasterCacheInspectorthat will be invoked before a message gets added to the cache.protected CacheMessageput(BroadcastMessage message, java.lang.Long now, java.lang.String uuid)BroadcasterCacheremoveBroadcasterCacheListener(BroadcasterCacheListener l)Remove aBroadcasterCacheListenerAbstractBroadcasterCachesetInvalidateCacheInterval(long invalidateCacheInterval)Set the delay between cache purges.AbstractBroadcasterCachesetMaxCacheTime(long maxCacheTime)Set the maximum time a message stays alive in the cache.voidstart()This method is invoked when the Broadcaster is started.voidstop()This method is invoked when the Broadcaster is stopped.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.atmosphere.cpr.BroadcasterCache
addToCache, retrieveFromCache
-
-
-
-
Field Detail
-
messages
protected final java.util.List<CacheMessage> messages
-
messagesIds
protected final java.util.Set<java.lang.String> messagesIds
-
readWriteLock
protected final java.util.concurrent.locks.ReadWriteLock readWriteLock
-
scheduledFuture
protected java.util.concurrent.ScheduledFuture<?> scheduledFuture
-
maxCacheTime
protected long maxCacheTime
-
invalidateCacheInterval
protected long invalidateCacheInterval
-
reaper
protected java.util.concurrent.ScheduledExecutorService reaper
-
isShared
protected boolean isShared
-
inspectors
protected final java.util.List<BroadcasterCacheInspector> inspectors
-
emptyList
protected final java.util.List<java.lang.Object> emptyList
-
listeners
protected final java.util.List<BroadcasterCacheListener> listeners
-
config
protected AtmosphereConfig config
-
-
Method Detail
-
start
public void start()
Description copied from interface:BroadcasterCacheThis method is invoked when the Broadcaster is started.- Specified by:
startin interfaceBroadcasterCache
-
cleanup
public void cleanup()
Description copied from interface:BroadcasterCacheClean resources associated with this instance. This method is useful when ExecutorServices are shared and some future must be cancelled. This method will always be invoked when aBroadcastergets destroyed.- Specified by:
cleanupin interfaceBroadcasterCache
-
stop
public void stop()
Description copied from interface:BroadcasterCacheThis method is invoked when the Broadcaster is stopped.- Specified by:
stopin interfaceBroadcasterCache
-
put
protected CacheMessage put(BroadcastMessage message, java.lang.Long now, java.lang.String uuid)
-
get
protected java.util.List<java.lang.Object> get(long cacheHeaderTime)
-
setInvalidateCacheInterval
public AbstractBroadcasterCache setInvalidateCacheInterval(long invalidateCacheInterval)
Set the delay between cache purges.- Parameters:
invalidateCacheInterval- the purge interval in milliseconds- Returns:
- this
-
setMaxCacheTime
public AbstractBroadcasterCache setMaxCacheTime(long maxCacheTime)
Set the maximum time a message stays alive in the cache.- Parameters:
maxCacheTime- the maximum time in milliseconds.- Returns:
- this
-
inspector
public BroadcasterCache inspector(BroadcasterCacheInspector b)
Description copied from interface:BroadcasterCacheAdd aBroadcasterCacheInspectorthat will be invoked before a message gets added to the cache.- Specified by:
inspectorin interfaceBroadcasterCache- Parameters:
b- an instance ofBroadcasterCacheInspector- Returns:
- this
-
inspect
protected boolean inspect(BroadcastMessage m)
-
configure
public void configure(AtmosphereConfig config)
Description copied from interface:AtmosphereConfigAwareConfigure an AtmosphereFramework object.- Specified by:
configurein interfaceAtmosphereConfigAware- Parameters:
config-AtmosphereConfig
-
clearCache
public BroadcasterCache clearCache(java.lang.String broadcasterId, java.lang.String uuid, CacheMessage cache)
Description copied from interface:BroadcasterCacheRemove the previously cached message.- Specified by:
clearCachein interfaceBroadcasterCache- Parameters:
broadcasterId- TheBroadcaster.getID()uuid- anAtmosphereResource.uuid()cache- theCacheMessage
-
excludeFromCache
public BroadcasterCache excludeFromCache(java.lang.String broadcasterId, AtmosphereResource r)
Description copied from interface:BroadcasterCacheAllow an application to exclude, or block, anAtmosphereResourceto received cached message. No new message will get sent to this client except the ones already cached.- Specified by:
excludeFromCachein interfaceBroadcasterCache- Parameters:
broadcasterId- TheBroadcaster.getID()r- anAtmosphereResource- Returns:
- this
-
cacheCandidate
public BroadcasterCache cacheCandidate(java.lang.String broadcasterId, java.lang.String uuid)
Description copied from interface:BroadcasterCacheAdd aAtmosphereResource.uuid()to the list of activeAtmosphereResourceMessage will be cached for the resource associated with the uuid.- Specified by:
cacheCandidatein interfaceBroadcasterCache- Parameters:
broadcasterId- TheBroadcaster.getID()uuid- anAtmosphereResource.uuid()- Returns:
- this
-
addBroadcasterCacheListener
public BroadcasterCache addBroadcasterCacheListener(BroadcasterCacheListener l)
Description copied from interface:BroadcasterCacheAdd aBroadcasterCacheListener- Specified by:
addBroadcasterCacheListenerin interfaceBroadcasterCache- Parameters:
l- aBroadcasterCacheListener- Returns:
- this
-
removeBroadcasterCacheListener
public BroadcasterCache removeBroadcasterCacheListener(BroadcasterCacheListener l)
Description copied from interface:BroadcasterCacheRemove aBroadcasterCacheListener- Specified by:
removeBroadcasterCacheListenerin interfaceBroadcasterCache- Parameters:
l- aBroadcasterCacheListener- Returns:
- this
-
-