org.atmosphere.cache
Class AbstractBroadcasterCache

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

public abstract class AbstractBroadcasterCache
extends Object
implements BroadcasterCache

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

Author:
Jeanfrancois Arcand

Nested Class Summary
protected static class AbstractBroadcasterCache.CachedMessage
           
 
Nested classes/interfaces inherited from interface org.atmosphere.cpr.BroadcasterCache
BroadcasterCache.STRATEGY
 
Field Summary
protected  int maxCachedinMs
           
protected  List<AbstractBroadcasterCache.CachedMessage> queue
           
protected  ScheduledExecutorService reaper
           
 
Fields inherited from interface org.atmosphere.cpr.BroadcasterCache
BROADCASTER_CACHE_TRACKER
 
Constructor Summary
AbstractBroadcasterCache()
           
 
Method Summary
 void addToCache(String id, AtmosphereResource resource, Object object)
          Start tracking messages associated with AtmosphereResource from the cache
abstract  void cache(String id, AtmosphereResource r, AbstractBroadcasterCache.CachedMessage cm)
          Cache the last message broadcasted.
 int getMaxCachedinMs()
          Get the maximum time a broadcasted message can stay cached.
 List<Object> retrieveFromCache(String id, AtmosphereResource r)
          Retrieve messages associated with AtmosphereResource
abstract  AbstractBroadcasterCache.CachedMessage retrieveLastMessage(String id, AtmosphereResource r)
          Return the last message broadcasted to the AtmosphereResource.
 void setExecutorService(ScheduledExecutorService reaper)
           
 void setMaxCachedinMs(int maxCachedinMs)
          Set the maximum time a broadcasted message can stay cached.
 void start()
          Start
 void stop()
          Stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

queue

protected final List<AbstractBroadcasterCache.CachedMessage> queue

reaper

protected ScheduledExecutorService reaper

maxCachedinMs

protected int maxCachedinMs
Constructor Detail

AbstractBroadcasterCache

public AbstractBroadcasterCache()
Method Detail

start

public final void start()
Start

Specified by:
start in interface BroadcasterCache

setExecutorService

public void setExecutorService(ScheduledExecutorService reaper)

stop

public final void stop()
Stop

Specified by:
stop in interface BroadcasterCache

addToCache

public final void addToCache(String id,
                             AtmosphereResource resource,
                             Object object)
Start tracking messages associated with AtmosphereResource from the cache

Specified by:
addToCache in interface BroadcasterCache
resource - AtmosphereResource
object - a broadcasted message.

cache

public abstract void cache(String id,
                           AtmosphereResource r,
                           AbstractBroadcasterCache.CachedMessage cm)
Cache the last message broadcasted.

Parameters:
r - AtmosphereResource.
cm - AbstractBroadcasterCache.CachedMessage

retrieveLastMessage

public abstract AbstractBroadcasterCache.CachedMessage retrieveLastMessage(String id,
                                                                           AtmosphereResource r)
Return the last message broadcasted to the AtmosphereResource.

Parameters:
r - AtmosphereResource.
Returns:
a AbstractBroadcasterCache.CachedMessage, or null if not matched.

retrieveFromCache

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

Specified by:
retrieveFromCache in interface BroadcasterCache
r - AtmosphereResource
Returns:
a List of messages (String).

getMaxCachedinMs

public int getMaxCachedinMs()
Get the maximum time a broadcasted message can stay cached.

Returns:
Get the maximum time a broadcasted message can stay cached.

setMaxCachedinMs

public void setMaxCachedinMs(int maxCachedinMs)
Set the maximum time a broadcasted message can stay cached.

Parameters:
maxCachedinMs - time in milliseconds


Copyright © 2012. All Rights Reserved.