Skip to content

Commit

Permalink
Port fix for #766
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Jan 14, 2013
1 parent 4a5ef54 commit 4b8f5b6
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

/**
Expand All @@ -80,10 +81,9 @@ public abstract class AbstractBroadcasterCache implements BroadcasterCache {
protected static final Logger logger = LoggerFactory.getLogger(AbstractBroadcasterCache.class);

protected final List<CachedMessage> queue = Collections.synchronizedList(new LinkedList<CachedMessage>());

protected ScheduledExecutorService reaper = Executors.newSingleThreadScheduledExecutor();

protected int maxCachedinMs = 1000 * 5 * 60;
protected ScheduledFuture scheduledFuture;

public AbstractBroadcasterCache() {
}
Expand All @@ -92,7 +92,7 @@ public AbstractBroadcasterCache() {
* {@inheritDoc}
*/
public final void start() {
reaper.scheduleAtFixedRate(new Runnable() {
scheduledFuture = reaper.scheduleAtFixedRate(new Runnable() {

public void run() {
synchronized (AbstractBroadcasterCache.this) {
Expand All @@ -115,6 +115,11 @@ public void run() {
}

public void setExecutorService(ScheduledExecutorService reaper){
if (scheduledFuture != null) {
scheduledFuture.cancel(false);
scheduledFuture = null;
}

if (reaper != null) {
stop();
}
Expand Down Expand Up @@ -218,10 +223,10 @@ public final synchronized List<Object> retrieveFromCache(String id, AtmosphereRe

return l;
}

/**
* Get the number of messages which are currently in the cache.
*
*
* @return the number of messages which are currently in the cache
*/
public int getQueueDepth() {
Expand Down

0 comments on commit 4b8f5b6

Please sign in to comment.