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 that is based on the unique identifier (UUID) that all AtmosphereResources have.

Author:
Paul Khodchenkov, Jeanfrancois Arcand

Nested Class Summary
static class UUIDBroadcasterCache.ClientQueue
          This class wraps all messages to be delivered to a client.
 
Field Summary
protected  List<Object> emptyList
           
protected  List<BroadcasterCacheInspector> inspectors
           
protected  List<BroadcasterCacheListener> listeners
           
protected  ScheduledExecutorService taskScheduler
           
 
Fields inherited from interface org.atmosphere.cpr.BroadcasterCache
DEFAULT, NULL
 
Constructor Summary
UUIDBroadcasterCache()
           
 
Method Summary
 Map<String,Long> activeClients()
           
 BroadcasterCache addBroadcasterCacheListener(BroadcasterCacheListener l)
          Add a BroadcasterCacheListener
 CacheMessage addToCache(String broadcasterId, String uuid, BroadcastMessage message)
          Start tracking messages associated with AtmosphereResource from the cache.
 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 message)
          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  boolean inspect(BroadcastMessage m)
           
 BroadcasterCache inspector(BroadcasterCacheInspector b)
          Add a BroadcasterCacheInspector that will be invoked before a message gets added to the cache.
 List<BroadcasterCacheInspector> inspectors()
           
protected  void invalidateExpiredEntries()
           
 List<BroadcasterCacheListener> listeners()
           
 Map<String,UUIDBroadcasterCache.ClientQueue> messages()
           
 BroadcasterCache removeBroadcasterCacheListener(BroadcasterCacheListener l)
          Remove a BroadcasterCacheListener
 List<Object> retrieveFromCache(String broadcasterId, String uuid)
          Retrieve messages associated with AtmosphereResource.
 void setClientIdleTime(long clientIdleTime)
           
 void setInvalidateCacheInterval(long invalidateCacheInterval)
           
 void start()
          This method is invoked when the Broadcaster is started.
 void stop()
          This method is invoked when the Broadcaster is stopped.
 String toString()
           
protected  String uuid(AtmosphereResource r)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

inspectors

protected final List<BroadcasterCacheInspector> inspectors

taskScheduler

protected ScheduledExecutorService taskScheduler

emptyList

protected final List<Object> emptyList

listeners

protected final List<BroadcasterCacheListener> listeners
Constructor Detail

UUIDBroadcasterCache

public UUIDBroadcasterCache()
Method Detail

configure

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

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

start

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

Specified by:
start 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

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

addToCache

public CacheMessage addToCache(String broadcasterId,
                               String uuid,
                               BroadcastMessage message)
Description copied from interface: BroadcasterCache
Start tracking messages associated with AtmosphereResource from the cache.

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

retrieveFromCache

public List<Object> retrieveFromCache(String broadcasterId,
                                      String uuid)
Description copied from interface: BroadcasterCache
Retrieve messages associated with AtmosphereResource.

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

clearCache

public BroadcasterCache clearCache(String broadcasterId,
                                   String uuid,
                                   CacheMessage message)
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()
message - the CacheMessage

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

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

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 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

toString

public String toString()
Overrides:
toString in class Object

listeners

public List<BroadcasterCacheListener> listeners()

inspectors

public List<BroadcasterCacheInspector> inspectors()


Copyright © 2014. All rights reserved.