Skip to content

Commit

Permalink
Fix for #192 Allow multiple instance of the same BroadcastFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Feb 21, 2012
1 parent 5bd1059 commit 9bc20f8
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ public ExecutorService getAsyncWriteService() {
* @return true if added.
*/
public boolean addFilter(BroadcastFilter e) {
if (filters.contains(e) || checkDuplicateFilter(e)) return false;
logDuplicateFilter(e);
if (filters.contains(e)) return false;

if (e instanceof BroadcastFilterLifecycle) {
((BroadcastFilterLifecycle) e).init();
Expand All @@ -327,13 +328,12 @@ public boolean addFilter(BroadcastFilter e) {
return filters.offer(e);
}

private boolean checkDuplicateFilter(BroadcastFilter e) {
private void logDuplicateFilter(BroadcastFilter e) {
for (BroadcastFilter f : filters) {
if (f.getClass().isAssignableFrom(e.getClass())) {
return true;
logger.trace("Duplicate Filter instance {}", f.getClass());
}
}
return false;
}

public void destroy() {
Expand Down Expand Up @@ -455,15 +455,15 @@ protected BroadcastAction filter(Object object) {
/**
* Invoke {@link BroadcastFilter} in the other they were added, with a unique {@link javax.servlet.http.HttpServletRequest}
*
* @param request {@link javax.servlet.http.HttpServletRequest}
* @param object the broadcasted object.
* @param r {@link AtmosphereResource}
* @param object the broadcasted object.
* @return BroadcastAction that tell Atmosphere to invoke the next filter or not.
*/
protected BroadcastAction filter(HttpServletRequest request, HttpServletResponse response, Object object) {
BroadcastAction transformed = new BroadcastAction(object);
protected BroadcastAction filter(AtmosphereResource<?,?> r, Object message, Object originalMessage) {
BroadcastAction transformed = new BroadcastAction(originalMessage);
for (PerRequestBroadcastFilter mf : perRequestFilters) {
synchronized (mf) {
transformed = mf.filter(request, response, transformed.message());
transformed = mf.filter(r, message, transformed.message());
if (transformed == null || transformed.action() == BroadcastAction.ACTION.ABORT) {
return transformed;
}
Expand Down

0 comments on commit 9bc20f8

Please sign in to comment.