org.atmosphere.cache
Class AbstractBroadcasterCache

java.lang.Object
  extended by org.atmosphere.cache.AbstractBroadcasterCache
All Implemented Interfaces:
BroadcasterCache
Direct Known Subclasses:
SessionBroadcasterCache

public abstract class AbstractBroadcasterCache
extends Object
implements BroadcasterCache

Abstract BroadcasterCache which is used to implement headers, query parameters or session based caching.

Author:
Paul Khodchenkov, Jeanfrancois Arcand

Field Summary
protected  List<Object> emptyList
           
protected  List<BroadcasterCacheInspector> inspectors
           
protected  long invalidateCacheInterval
           
protected  boolean isShared
           
protected  List<BroadcasterCacheListener> listeners
           
protected  long maxCacheTime
           
protected  List<CacheMessage> messages
           
protected  Set<String> messagesIds
           
protected  ReadWriteLock readWriteLock
           
protected  ScheduledExecutorService reaper
           
protected  ScheduledFuture scheduledFuture
           
 
Fields inherited from interface org.atmosphere.cpr.BroadcasterCache
DEFAULT, NULL
 
Constructor Summary
AbstractBroadcasterCache()
           
 
Method Summary
 BroadcasterCache addBroadcasterCacheListener(BroadcasterCacheListener l)
          Add a BroadcasterCacheListener
 BroadcasterCache cacheCandidate(String broadcasterId, String uuid)
          Add a AtmosphereResource.uuid() to the list of active AtmosphereResource Message will be cached for the resource associated with the uuid.
 void cleanup()
          Clean resources associated with this instance.
 BroadcasterCache clearCache(String broadcasterId, String uuid, CacheMessage cache)
          Remove the previously cached message.
 void configure(BroadcasterConfig config)
          Configure the cache.
 BroadcasterCache excludeFromCache(String broadcasterId, AtmosphereResource r)
          Allow an application to exclude, or block, an AtmosphereResource to received cached message.
protected  List<Object> get(long cacheHeaderTime)
           
protected  boolean inspect(BroadcastMessage m)
           
 BroadcasterCache inspector(BroadcasterCacheInspector b)
          Add a BroadcasterCacheInspector that will be invoked before a message gets added to the cache.
protected  CacheMessage put(BroadcastMessage message, Long now, String uuid)
           
 BroadcasterCache removeBroadcasterCacheListener(BroadcasterCacheListener l)
          Remove a BroadcasterCacheListener
 AbstractBroadcasterCache setInvalidateCacheInterval(long invalidateCacheInterval)
          Set the delay between cache purges.
 AbstractBroadcasterCache setMaxCacheTime(long maxCacheTime)
          Set the maximum time a message stays alive in the cache.
 void start()
          This method is invoked when the Broadcaster is started.
 void stop()
          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 List<CacheMessage> messages

messagesIds

protected final Set<String> messagesIds

readWriteLock

protected final ReadWriteLock readWriteLock

scheduledFuture

protected ScheduledFuture scheduledFuture

maxCacheTime

protected long maxCacheTime

invalidateCacheInterval

protected long invalidateCacheInterval

reaper

protected ScheduledExecutorService reaper

isShared

protected boolean isShared

inspectors

protected final List<BroadcasterCacheInspector> inspectors

emptyList

protected final List<Object> emptyList

listeners

protected final List<BroadcasterCacheListener> listeners
Constructor Detail

AbstractBroadcasterCache

public AbstractBroadcasterCache()
Method Detail

start

public void start()
Description copied from interface: BroadcasterCache
This method is invoked when the Broadcaster is started.

Specified by:
start in interface BroadcasterCache

cleanup

public void cleanup()
Description copied from interface: BroadcasterCache
Clean 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 a Broadcaster gets destroyed.

Specified by:
cleanup in interface BroadcasterCache

stop

public void stop()
Description copied from interface: BroadcasterCache
This method is invoked when the Broadcaster is stopped.

Specified by:
stop in interface BroadcasterCache

put

protected CacheMessage put(BroadcastMessage message,
                           Long now,
                           String uuid)

get

protected List<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: BroadcasterCache
Add a BroadcasterCacheInspector that will be invoked before a message gets added to the cache.

Specified by:
inspector in interface BroadcasterCache
Parameters:
b - an instance of BroadcasterCacheInspector
Returns:
this

inspect

protected boolean inspect(BroadcastMessage m)

configure

public void configure(BroadcasterConfig config)
Description copied from interface: BroadcasterCache
Configure the cache.

Specified by:
configure in interface BroadcasterCache
Parameters:
config - a BroadcasterConfig

clearCache

public BroadcasterCache clearCache(String broadcasterId,
                                   String uuid,
                                   CacheMessage cache)
Description copied from interface: BroadcasterCache
Remove the previously cached message.

Specified by:
clearCache in interface BroadcasterCache
Parameters:
broadcasterId - The Broadcaster.getID()
uuid - an AtmosphereResource.uuid()
cache - the CacheMessage

excludeFromCache

public BroadcasterCache excludeFromCache(String broadcasterId,
                                         AtmosphereResource r)
Description copied from interface: BroadcasterCache
Allow an application to exclude, or block, an AtmosphereResource to received cached message. No new message will get sent to this client except the ones already cached.

Specified by:
excludeFromCache in interface BroadcasterCache
Parameters:
broadcasterId - The Broadcaster.getID()
r - an AtmosphereResource
Returns:
this

cacheCandidate

public BroadcasterCache cacheCandidate(String broadcasterId,
                                       String uuid)
Description copied from interface: BroadcasterCache
Add a AtmosphereResource.uuid() to the list of active AtmosphereResource Message will be cached for the resource associated with the uuid.

Specified by:
cacheCandidate in interface BroadcasterCache
Parameters:
broadcasterId - The Broadcaster.getID()
uuid - an AtmosphereResource.uuid()
Returns:
this

addBroadcasterCacheListener

public BroadcasterCache addBroadcasterCacheListener(BroadcasterCacheListener l)
Description copied from interface: BroadcasterCache
Add a BroadcasterCacheListener

Specified by:
addBroadcasterCacheListener in interface BroadcasterCache
Parameters:
l - a BroadcasterCacheListener
Returns:
this

removeBroadcasterCacheListener

public BroadcasterCache removeBroadcasterCacheListener(BroadcasterCacheListener l)
Description copied from interface: BroadcasterCache
Remove a BroadcasterCacheListener

Specified by:
removeBroadcasterCacheListener in interface BroadcasterCache
Parameters:
l - a BroadcasterCacheListener
Returns:
this


Copyright © 2014. All Rights Reserved.