Skip to content

Instantly share code, notes, and snippets.

@jfarcand
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfarcand/f890b0f8218af3c5d8c6 to your computer and use it in GitHub Desktop.
Save jfarcand/f890b0f8218af3c5d8c6 to your computer and use it in GitHub Desktop.
protected void queueWriteIO(AtmosphereResource r, Deliver deliver, AtomicInteger count) throws InterruptedException {
if (deliver.async) {
// The onStateChange/onRequest may change the isResumed value, hence we need to make sure only one thread flip
// the switch to garantee the Entry will be cached in the order it was broadcasted.
// Without synchronizing we may end up with a out of order BroadcasterCache queue.
if (!bc.getBroadcasterCache().getClass().equals(BroadcasterCache.DEFAULT.getClass().getName())) {
if (r.isResumed() || r.isCancelled()) {
logger.trace("AtmosphereResource {} has been resumed or cancelled, unable to Broadcast message {}", r.uuid(), deliver.message);
/**
* Check in the cache again ##issue
*/
AtmosphereResource r2 = config.resourcesFactory().find(r.uuid());
if (r2 != null && r2.isSuspended() && r.hashCode() != r2.hashCode()) {
// Prevent other Broadcast to happens
removeAtmosphereResource(r2);
checkCachedAndPush(r2, r2.getAtmosphereResourceEvent());
}
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment