Package org.atmosphere.cache
Class UUIDBroadcasterCache
- java.lang.Object
-
- org.atmosphere.cache.UUIDBroadcasterCache
-
- All Implemented Interfaces:
BroadcasterCache,AtmosphereConfigAware
public class UUIDBroadcasterCache extends java.lang.Object implements BroadcasterCache
An improvedBroadcasterCacheimplementation that is based on the unique identifier (UUID) that allAtmosphereResources have.- Author:
- Paul Khodchenkov, Jeanfrancois Arcand
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<java.lang.Object>emptyListprotected java.util.List<BroadcasterCacheInspector>inspectorsprotected java.util.List<BroadcasterCacheListener>listenersprotected java.util.concurrent.ScheduledExecutorServicetaskScheduler-
Fields inherited from interface org.atmosphere.cpr.BroadcasterCache
DEFAULT, NULL
-
-
Constructor Summary
Constructors Constructor Description UUIDBroadcasterCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.Long>activeClients()BroadcasterCacheaddBroadcasterCacheListener(BroadcasterCacheListener l)Add aBroadcasterCacheListenerCacheMessageaddToCache(java.lang.String broadcasterId, java.lang.String uuid, BroadcastMessage message)Start tracking messages associated withAtmosphereResourcefrom the cache.BroadcasterCachecacheCandidate(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 message)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 booleaninspect(BroadcastMessage m)BroadcasterCacheinspector(BroadcasterCacheInspector b)Add aBroadcasterCacheInspectorthat will be invoked before a message gets added to the cache.java.util.List<BroadcasterCacheInspector>inspectors()protected voidinvalidateExpiredEntries()java.util.List<BroadcasterCacheListener>listeners()java.util.Map<java.lang.String,java.util.concurrent.ConcurrentLinkedQueue<CacheMessage>>messages()BroadcasterCacheremoveBroadcasterCacheListener(BroadcasterCacheListener l)Remove aBroadcasterCacheListenerjava.util.List<java.lang.Object>retrieveFromCache(java.lang.String broadcasterId, java.lang.String uuid)Retrieve messages associated withAtmosphereResource.voidsetClientIdleTime(long clientIdleTime)voidsetInvalidateCacheInterval(long invalidateCacheInterval)voidstart()This method is invoked when the Broadcaster is started.voidstop()This method is invoked when the Broadcaster is stopped.java.lang.StringtoString()protected java.lang.Stringuuid(AtmosphereResource r)
-
-
-
Field Detail
-
inspectors
protected final java.util.List<BroadcasterCacheInspector> inspectors
-
taskScheduler
protected java.util.concurrent.ScheduledExecutorService taskScheduler
-
emptyList
protected final java.util.List<java.lang.Object> emptyList
-
listeners
protected final java.util.List<BroadcasterCacheListener> listeners
-
-
Method Detail
-
configure
public void configure(AtmosphereConfig config)
Description copied from interface:AtmosphereConfigAwareConfigure an AtmosphereFramework object.- Specified by:
configurein interfaceAtmosphereConfigAware- Parameters:
config-AtmosphereConfig
-
start
public void start()
Description copied from interface:BroadcasterCacheThis method is invoked when the Broadcaster is started.- Specified by:
startin interfaceBroadcasterCache
-
stop
public void stop()
Description copied from interface:BroadcasterCacheThis method is invoked when the Broadcaster is stopped.- Specified by:
stopin 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
-
addToCache
public CacheMessage addToCache(java.lang.String broadcasterId, java.lang.String uuid, BroadcastMessage message)
Description copied from interface:BroadcasterCacheStart tracking messages associated withAtmosphereResourcefrom the cache.- Specified by:
addToCachein interfaceBroadcasterCache- Parameters:
broadcasterId- The associated {@link Broadcaster#addAtmosphereResource(AtmosphereResource).getID}uuid-AtmosphereResource.uuid()message-BroadcastMessage.- Returns:
- The
CacheMessage
-
retrieveFromCache
public java.util.List<java.lang.Object> retrieveFromCache(java.lang.String broadcasterId, java.lang.String uuid)Description copied from interface:BroadcasterCacheRetrieve messages associated withAtmosphereResource.- Specified by:
retrieveFromCachein interfaceBroadcasterCache- Parameters:
broadcasterId- The associated {@link org.atmosphere.cpr.Broadcaster#addAtmosphereResource(org.atmosphere.cpr.AtmosphereResource).getID}uuid-AtmosphereResource- Returns:
- a
Listof messages (String).
-
clearCache
public BroadcasterCache clearCache(java.lang.String broadcasterId, java.lang.String uuid, CacheMessage message)
Description copied from interface:BroadcasterCacheRemove the previously cached message.- Specified by:
clearCachein interfaceBroadcasterCache- Parameters:
broadcasterId- TheBroadcaster.getID()uuid- anAtmosphereResource.uuid()message- theCacheMessage
-
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
-
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
-
uuid
protected java.lang.String uuid(AtmosphereResource r)
-
messages
public java.util.Map<java.lang.String,java.util.concurrent.ConcurrentLinkedQueue<CacheMessage>> messages()
-
activeClients
public java.util.Map<java.lang.String,java.lang.Long> activeClients()
-
inspect
protected boolean inspect(BroadcastMessage m)
-
setInvalidateCacheInterval
public void setInvalidateCacheInterval(long invalidateCacheInterval)
-
setClientIdleTime
public void setClientIdleTime(long clientIdleTime)
-
invalidateExpiredEntries
protected void invalidateExpiredEntries()
-
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
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
listeners
public java.util.List<BroadcasterCacheListener> listeners()
-
inspectors
public java.util.List<BroadcasterCacheInspector> inspectors()
-
-