You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2014/08/14 13:31:54 UTC

[1/2] git commit: WICKET-5619 ConcurrentModificationException may occur when calling EventBus.post()

Repository: wicket
Updated Branches:
  refs/heads/wicket-atmosphere-tester c9a0b8fc1 -> 2a123aebd


WICKET-5619 ConcurrentModificationException may occur when calling EventBus.post()

Use Iterables#filter() as suggested at com.google.common.collect.Collections2#filter


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/18f269e1
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/18f269e1
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/18f269e1

Branch: refs/heads/wicket-atmosphere-tester
Commit: 18f269e13b4c6f14ede7b44a495c2f0782d1a0f6
Parents: f0eb015
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Thu Aug 14 13:28:44 2014 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Thu Aug 14 13:28:44 2014 +0200

----------------------------------------------------------------------
 .../atmosphere/AtmosphereRequestHandler.java     |  9 +++++----
 .../wicket/atmosphere/AtmosphereWebRequest.java  |  8 ++++----
 .../org/apache/wicket/atmosphere/EventBus.java   | 19 +++++++++++--------
 3 files changed, 20 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/18f269e1/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestHandler.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestHandler.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestHandler.java
index 8824468..3ba143d 100644
--- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestHandler.java
+++ b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestHandler.java
@@ -16,7 +16,7 @@
  */
 package org.apache.wicket.atmosphere;
 
-import java.util.Collection;
+import java.util.Iterator;
 
 import org.apache.wicket.Component;
 import org.apache.wicket.Page;
@@ -44,7 +44,7 @@ public class AtmosphereRequestHandler implements IRequestHandler
 
 	private final AtmosphereEvent event;
 
-	private final Collection<EventSubscription> subscriptions;
+	private final Iterator<EventSubscription> subscriptions;
 
 	private final EventSubscriptionInvoker eventSubscriptionInvoker;
 
@@ -58,7 +58,7 @@ public class AtmosphereRequestHandler implements IRequestHandler
 	 * @param event
 	 * @param eventSubscriptionInvoker
 	 */
-	public AtmosphereRequestHandler(PageKey pageKey, Collection<EventSubscription> subscriptions,
+	public AtmosphereRequestHandler(PageKey pageKey, Iterator<EventSubscription> subscriptions,
 		AtmosphereEvent event, EventSubscriptionInvoker eventSubscriptionInvoker)
 	{
 		this.pageKey = pageKey;
@@ -78,8 +78,9 @@ public class AtmosphereRequestHandler implements IRequestHandler
 
 	private void executeHandlers(AjaxRequestTarget target, Page page)
 	{
-		for (EventSubscription curSubscription : subscriptions)
+		while (subscriptions.hasNext())
 		{
+			EventSubscription curSubscription = subscriptions.next();
 			if (curSubscription.getContextAwareFilter().apply(event))
 			{
 				String componentPath = curSubscription.getComponentPath();

http://git-wip-us.apache.org/repos/asf/wicket/blob/18f269e1/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereWebRequest.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereWebRequest.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereWebRequest.java
index eb8f5c1..b373983 100644
--- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereWebRequest.java
+++ b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereWebRequest.java
@@ -17,7 +17,7 @@
 package org.apache.wicket.atmosphere;
 
 import java.nio.charset.Charset;
-import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 
@@ -47,12 +47,12 @@ class AtmosphereWebRequest extends ServletWebRequest
 
 	private final PageKey pageKey;
 
-	private final Collection<EventSubscription> subscriptions;
+	private final Iterator<EventSubscription> subscriptions;
 
 	private final AtmosphereEvent event;
 
 	AtmosphereWebRequest(ServletWebRequest wrappedRequest, PageKey pageKey,
-		Collection<EventSubscription> subscriptions, AtmosphereEvent event)
+		Iterator<EventSubscription> subscriptions, AtmosphereEvent event)
 	{
 		super(wrappedRequest.getContainerRequest(), wrappedRequest.getFilterPrefix());
 		this.wrappedRequest = wrappedRequest;
@@ -66,7 +66,7 @@ class AtmosphereWebRequest extends ServletWebRequest
 		return pageKey;
 	}
 
-	public Collection<EventSubscription> getSubscriptions()
+	public Iterator<EventSubscription> getSubscriptions()
 	{
 		return subscriptions;
 	}

http://git-wip-us.apache.org/repos/asf/wicket/blob/18f269e1/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java
index a87a9c5..80837b8 100644
--- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java
+++ b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java
@@ -17,7 +17,6 @@
 package org.apache.wicket.atmosphere;
 
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -48,9 +47,9 @@ import org.atmosphere.cpr.BroadcasterFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.collect.Collections2;
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Multimap;
 
@@ -380,21 +379,25 @@ public class EventBus implements UnboundListener
 		ThreadContext.detach();
 		ThreadContext.setApplication(application);
 		PageKey key;
-		Collection<EventSubscription> subscriptionsForPage;
+		Iterable<EventSubscription> subscriptionsForPage;
 		synchronized (this)
 		{
 			key = trackedPages.get(resource.uuid());
-			subscriptionsForPage = Collections2.filter(
-				Collections.unmodifiableCollection(subscriptions.get(key)), new EventFilter(event));
+			Collection<EventSubscription> eventSubscriptions = subscriptions.get(key);
+			subscriptionsForPage = Iterables.filter(eventSubscriptions, new EventFilter(event));
 		}
 		if (key == null)
 			broadcaster.removeAtmosphereResource(resource);
-		else if (!subscriptionsForPage.isEmpty())
-			post(resource, key, subscriptionsForPage, event);
+		else
+		{
+			Iterator<EventSubscription> iterator = subscriptionsForPage.iterator();
+			if (iterator.hasNext())
+				post(resource, key, iterator, event);
+		}
 	}
 
 	private void post(AtmosphereResource resource, PageKey pageKey,
-		Collection<EventSubscription> subscriptionsForPage, AtmosphereEvent event)
+		Iterator<EventSubscription> subscriptionsForPage, AtmosphereEvent event)
 	{
 		String filterPath = WebApplication.get()
 			.getWicketFilter()


[2/2] git commit: Merge branch 'wicket-6.x' into wicket-atmosphere-tester

Posted by mg...@apache.org.
Merge branch 'wicket-6.x' into wicket-atmosphere-tester


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/2a123aeb
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/2a123aeb
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/2a123aeb

Branch: refs/heads/wicket-atmosphere-tester
Commit: 2a123aebd33e52376d26c83167552612230f0be5
Parents: c9a0b8f 18f269e
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Thu Aug 14 13:31:43 2014 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Thu Aug 14 13:31:43 2014 +0200

----------------------------------------------------------------------
 .../atmosphere/AtmosphereRequestHandler.java     |  9 +++++----
 .../wicket/atmosphere/AtmosphereWebRequest.java  |  8 ++++----
 .../org/apache/wicket/atmosphere/EventBus.java   | 19 +++++++++++--------
 3 files changed, 20 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/2a123aeb/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java
----------------------------------------------------------------------
diff --cc wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java
index e60ca01,80837b8..d3e9c32
--- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java
+++ b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java
@@@ -399,13 -383,17 +398,17 @@@ public class EventBus implements Unboun
  		synchronized (this)
  		{
  			key = trackedPages.get(resource.uuid());
- 			subscriptionsForPage = Collections2.filter(
- 				Collections.unmodifiableCollection(subscriptions.get(key)), new EventFilter(event));
+ 			Collection<EventSubscription> eventSubscriptions = subscriptions.get(key);
+ 			subscriptionsForPage = Iterables.filter(eventSubscriptions, new EventFilter(event));
  		}
  		if (key == null)
 -			broadcaster.removeAtmosphereResource(resource);
 +			getBroadcaster().removeAtmosphereResource(resource);
- 		else if (!subscriptionsForPage.isEmpty())
- 			post(resource, key, subscriptionsForPage, event);
+ 		else
+ 		{
+ 			Iterator<EventSubscription> iterator = subscriptionsForPage.iterator();
+ 			if (iterator.hasNext())
+ 				post(resource, key, iterator, event);
+ 		}
  	}
  
  	private void post(AtmosphereResource resource, PageKey pageKey,