org.atmosphere.cache
Class UUIDBroadcasterCache

java.lang.Object
  extended by org.atmosphere.cache.UUIDBroadcasterCache
All Implemented Interfaces:
BroadcasterCache

public class UUIDBroadcasterCache
extends Object
implements BroadcasterCache

An improved BroadcasterCache implementation.

Author:
Paul Khodchenkov, Jeanfrancois Arcand

Nested Class Summary
static class UUIDBroadcasterCache.ClientQueue
           
 
Field Summary
protected  ConcurrentHashMap<String,List<String>> bannedResources
           
protected  List<Object> emptyList
           
protected  List<BroadcasterCacheInspector> inspectors
           
protected  ScheduledExecutorService taskScheduler
           
 
Fields inherited from interface org.atmosphere.cpr.BroadcasterCache
DEFAULT
 
Constructor Summary
UUIDBroadcasterCache()
           
 
Method Summary
 Map<String,Long> activeClients()
           
 CacheMessage addToCache(String broadcasterId, AtmosphereResource r, BroadcastMessage message)
          Start tracking messages associated with AtmosphereResource from the cache
 void clearCache(String broadcasterId, AtmosphereResource r, CacheMessage message)
          Remove the previously cached message.
 void configure(AtmosphereConfig config)
          Configure the cache.
 void excludeFromCache(String broadcasterId, AtmosphereResource r)
          Allow an application to exclude, or block, an AtmosphereResource to received cached message.
 boolean includeInCache(String broadcasterId, AtmosphereResource r)
          Re-allow an AtmosphereResource to receive cached message.
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  void invalidateExpiredEntries()
           
 Map<String,UUIDBroadcasterCache.ClientQueue> messages()
           
 List<Object> retrieveFromCache(String broadcasterId, AtmosphereResource r)
          Retrieve messages associated with AtmosphereResource
 void setClientIdleTime(long clientIdleTime)
           
 void setInvalidateCacheInterval(long invalidateCacheInterval)
           
 void start()
          Start
 void stop()
          Stop
protected  String uuid(AtmosphereResource r)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inspectors

protected final List<BroadcasterCacheInspector> inspectors

taskScheduler

protected ScheduledExecutorService taskScheduler

bannedResources

protected final ConcurrentHashMap<String,List<String>> bannedResources

emptyList

protected final List<Object> emptyList
Constructor Detail

UUIDBroadcasterCache

public UUIDBroadcasterCache()
Method Detail

configure

public void configure(AtmosphereConfig config)
Configure the cache.

Specified by:
configure in interface BroadcasterCache

start

public void start()
Start

Specified by:
start in interface BroadcasterCache

stop

public void stop()
Stop

Specified by:
stop in interface BroadcasterCache

addToCache

public CacheMessage addToCache(String broadcasterId,
                               AtmosphereResource r,
                               BroadcastMessage message)
Start tracking messages associated with AtmosphereResource from the cache

Specified by:
addToCache in interface BroadcasterCache
Parameters:
broadcasterId - The associated Broadcaster#addAtmosphereResource(AtmosphereResource).getID
r - AtmosphereResource
message - BroadcastMessage.
Returns:
The CacheMessage

retrieveFromCache

public List<Object> retrieveFromCache(String broadcasterId,
                                      AtmosphereResource r)
Retrieve messages associated with AtmosphereResource

Specified by:
retrieveFromCache in interface BroadcasterCache
Parameters:
broadcasterId - The associated Broadcaster#addAtmosphereResource(AtmosphereResource).getID
r - AtmosphereResource
Returns:
a List of messages (String).

clearCache

public void clearCache(String broadcasterId,
                       AtmosphereResource r,
                       CacheMessage message)
Remove the previously cached message.

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

inspector

public BroadcasterCache inspector(BroadcasterCacheInspector b)
Add a BroadcasterCacheInspector that will be invoked before a message gets added to the cache.

Specified by:
inspector in interface BroadcasterCache
Returns:
this

uuid

protected String uuid(AtmosphereResource r)

messages

public Map<String,UUIDBroadcasterCache.ClientQueue> messages()

activeClients

public Map<String,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 void excludeFromCache(String broadcasterId,
                             AtmosphereResource r)
Description copied from interface: BroadcasterCache
Allow an application to exclude, or block, an AtmosphereResource to received cached message.

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

includeInCache

public boolean includeInCache(String broadcasterId,
                              AtmosphereResource r)
Description copied from interface: BroadcasterCache
Re-allow an AtmosphereResource to receive cached message.

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


Copyright © 2013. All Rights Reserved.