Skip to content

Commit

Permalink
Small optimization, synchronize only when perRequestFilters are defined
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Nov 19, 2012
1 parent 7bdfa64 commit 978ec4c
Showing 1 changed file with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -704,28 +704,26 @@ protected Object perRequestFilter(AtmosphereResource r, Entry msg) {

Object finalMsg = msg.message;

if (AtmosphereResourceImpl.class.isAssignableFrom(r.getClass())) {
synchronized (r) {
if (isAtmosphereResourceValid(r)) {
if (bc.hasPerRequestFilters()) {
BroadcastAction a = bc.filter(r, msg.message, msg.originalMessage);
if (a.action() == BroadcastAction.ACTION.ABORT) {
return null;
}
if (a.message() != msg.originalMessage) {
finalMsg = a.message();
}
if (isAtmosphereResourceValid(r)) {
if (bc.hasPerRequestFilters()) {
synchronized (r) {
BroadcastAction a = bc.filter(r, msg.message, msg.originalMessage);
if (a.action() == BroadcastAction.ACTION.ABORT) {
return null;
}
if (a.message() != msg.originalMessage) {
finalMsg = a.message();
}
} else {
// The resource is no longer valid.
removeAtmosphereResource(r);
BroadcasterFactory.getDefault().removeAllAtmosphereResource(r);
}

if (cacheStrategy == BroadcasterCache.STRATEGY.AFTER_FILTER) {
trackBroadcastMessage(r, finalMsg);
}
}
} else {
// The resource is no longer valid.
removeAtmosphereResource(r);
BroadcasterFactory.getDefault().removeAllAtmosphereResource(r);
}

if (cacheStrategy == BroadcasterCache.STRATEGY.AFTER_FILTER) {
trackBroadcastMessage(r, finalMsg);
}
return finalMsg;
}
Expand Down

0 comments on commit 978ec4c

Please sign in to comment.