You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by pa...@apache.org on 2012/09/04 20:29:17 UTC
git commit: WICKET-4729: support multiple tabs with the same page
Updated Branches:
refs/heads/master c0c9635d9 -> 659ee9b33
WICKET-4729: support multiple tabs with the same page
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/659ee9b3
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/659ee9b3
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/659ee9b3
Branch: refs/heads/master
Commit: 659ee9b337944a461bef400aedbe5f71a5abccf2
Parents: c0c9635
Author: Emond Papegaaij <pa...@apache.org>
Authored: Tue Sep 4 20:27:45 2012 +0200
Committer: Emond Papegaaij <pa...@apache.org>
Committed: Tue Sep 4 20:27:56 2012 +0200
----------------------------------------------------------------------
.../wicket/atmosphere/AtmosphereBehavior.java | 17 +++++-
.../org/apache/wicket/atmosphere/EventBus.java | 44 +++++++++++++--
2 files changed, 54 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/659ee9b3/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java
index 3f574bb..f4641bd 100644
--- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java
+++ b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java
@@ -18,9 +18,11 @@ package org.apache.wicket.atmosphere;
import javax.servlet.http.HttpServletRequest;
+import org.apache.wicket.Application;
import org.apache.wicket.Component;
import org.apache.wicket.IResourceListener;
import org.apache.wicket.MetaDataKey;
+import org.apache.wicket.Session;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.ajax.json.JSONException;
import org.apache.wicket.ajax.json.JSONObject;
@@ -66,13 +68,25 @@ public class AtmosphereBehavior extends Behavior
private static final long serialVersionUID = 1L;
+ private String applicationKey;
+
+ private String sessionId;
+
private Component component;
+
/**
* Construct.
*/
public AtmosphereBehavior()
{
+ applicationKey = Application.get().getApplicationKey();
+ sessionId = Session.get().getId();
+ }
+
+ private EventBus findEventBus()
+ {
+ return EventBus.get(Application.get(applicationKey));
}
@Override
@@ -97,7 +111,7 @@ public class AtmosphereBehavior extends Behavior
Meteor meteor = Meteor.build(request.getContainerRequest());
String uuid = getUUID(meteor.getAtmosphereResource());
component.getPage().setMetaData(ATMOSPHERE_UUID, uuid);
- EventBus.get().registerPage(uuid, component.getPage());
+ findEventBus().registerPage(uuid, component.getPage());
// Add us to the listener list.
meteor.addListener(this);
@@ -169,6 +183,7 @@ public class AtmosphereBehavior extends Behavior
log.info(String.format("%s connection dropped from ip %s:%s", transport == null
? "websocket" : transport, req.getRemoteAddr(), req.getRemotePort()));
}
+ findEventBus().unregisterConnection(getUUID(event.getResource()));
}
@Override
http://git-wip-us.apache.org/repos/asf/wicket/blob/659ee9b3/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 2a0dfd4..794cf28 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
@@ -19,6 +19,7 @@ package org.apache.wicket.atmosphere;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
+import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
@@ -38,11 +39,10 @@ import org.atmosphere.cpr.BroadcasterFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.BiMap;
import com.google.common.collect.Collections2;
-import com.google.common.collect.HashBiMap;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Iterators;
+import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
/**
@@ -74,7 +74,16 @@ public class EventBus implements UnboundListener
*/
public static EventBus get()
{
- return Application.get().getMetaData(EVENT_BUS_KEY);
+ return get(Application.get());
+ }
+
+ /**
+ * @param application
+ * @return the {@code EventBus} registered for the given Wicket application.
+ */
+ public static EventBus get(Application application)
+ {
+ return application.getMetaData(EVENT_BUS_KEY);
}
private WebApplication application;
@@ -83,7 +92,7 @@ public class EventBus implements UnboundListener
private Multimap<PageKey, EventSubscription> subscriptions = HashMultimap.create();
- private BiMap<String, PageKey> trackedPages = HashBiMap.create();
+ private Map<String, PageKey> trackedPages = Maps.newHashMap();
/**
* Creates and registers an {@code EventBus} for the given application. The first broadcaster
@@ -125,7 +134,7 @@ public class EventBus implements UnboundListener
PageKey pageKey = new PageKey(page.getPageId(), Session.get().getId());
if (oldPage != null && !oldPage.equals(pageKey))
subscriptions.removeAll(oldPage);
- trackedPages.forcePut(trackingId, pageKey);
+ trackedPages.put(trackingId, pageKey);
log.info("registered page {} for session {}",
new Object[] { pageKey.getPageId(), pageKey.getSessionId() });
}
@@ -150,7 +159,26 @@ public class EventBus implements UnboundListener
subscription.getBehaviorIndex() == null ? "" : ":" +
subscription.getBehaviorIndex() });
}
- subscriptions.put(new PageKey(page.getPageId(), Session.get().getId()), subscription);
+ PageKey pageKey = new PageKey(page.getPageId(), Session.get().getId());
+ if (!subscriptions.containsEntry(pageKey, subscription))
+ {
+ subscriptions.put(pageKey, subscription);
+ }
+ }
+
+ /**
+ * Unregisters all subscriptions for the given tracking id.
+ *
+ * @param trackingId
+ */
+ public synchronized void unregisterConnection(String trackingId)
+ {
+ PageKey pageKey = trackedPages.remove(trackingId);
+ if (log.isInfoEnabled() && pageKey != null)
+ {
+ log.info("unregistering page {} for session {}", new Object[] { pageKey.getPageId(),
+ pageKey.getSessionId() });
+ }
}
/**
@@ -167,6 +195,10 @@ public class EventBus implements UnboundListener
{
for (AtmosphereResource resource : broadcaster.getAtmosphereResources())
{
+ if (resource.isCancelled())
+ {
+ System.out.println("cancelled");
+ }
ThreadContext.detach();
ThreadContext.setApplication(application);
PageKey key;
Re: git commit: WICKET-4729: support multiple tabs with the same page
Posted by Martin Grigorov <mg...@apache.org>.
On Tue, Sep 4, 2012 at 8:54 PM, Emond Papegaaij
<em...@gmail.com> wrote:
> You read all the commits, don't you? :) That line shouldn't have been
Yes, this saves me time later when debugging problems :-) And keeps me
up-to-date.
> there, I often use System.out.println for temporary debug lines,
> because it stands out of the rest of the logging due to the missing
> timestamp etc. I've removed it.
I've noticed ;-)
>
> On Tue, Sep 4, 2012 at 8:41 PM, Martin Grigorov <mg...@apache.org> wrote:
>> On Tue, Sep 4, 2012 at 8:29 PM, <pa...@apache.org> wrote:
>>> Updated Branches:
>>> refs/heads/master c0c9635d9 -> 659ee9b33
>>>
>>>
>>> WICKET-4729: support multiple tabs with the same page
>>>
>>>
>>> Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
>>> Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/659ee9b3
>>> Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/659ee9b3
>>> Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/659ee9b3
>>>
>>> Branch: refs/heads/master
>>> Commit: 659ee9b337944a461bef400aedbe5f71a5abccf2
>>> Parents: c0c9635
>>> Author: Emond Papegaaij <pa...@apache.org>
>>> Authored: Tue Sep 4 20:27:45 2012 +0200
>>> Committer: Emond Papegaaij <pa...@apache.org>
>>> Committed: Tue Sep 4 20:27:56 2012 +0200
>>>
>>> ----------------------------------------------------------------------
>>> .../wicket/atmosphere/AtmosphereBehavior.java | 17 +++++-
>>> .../org/apache/wicket/atmosphere/EventBus.java | 44 +++++++++++++--
>>> 2 files changed, 54 insertions(+), 7 deletions(-)
>>> ----------------------------------------------------------------------
>>>
>>>
>>> http://git-wip-us.apache.org/repos/asf/wicket/blob/659ee9b3/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java
>>> ----------------------------------------------------------------------
>>> diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java
>>> index 3f574bb..f4641bd 100644
>>> --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java
>>> +++ b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java
>>> @@ -18,9 +18,11 @@ package org.apache.wicket.atmosphere;
>>>
>>> import javax.servlet.http.HttpServletRequest;
>>>
>>> +import org.apache.wicket.Application;
>>> import org.apache.wicket.Component;
>>> import org.apache.wicket.IResourceListener;
>>> import org.apache.wicket.MetaDataKey;
>>> +import org.apache.wicket.Session;
>>> import org.apache.wicket.WicketRuntimeException;
>>> import org.apache.wicket.ajax.json.JSONException;
>>> import org.apache.wicket.ajax.json.JSONObject;
>>> @@ -66,13 +68,25 @@ public class AtmosphereBehavior extends Behavior
>>>
>>> private static final long serialVersionUID = 1L;
>>>
>>> + private String applicationKey;
>>> +
>>> + private String sessionId;
>>> +
>>> private Component component;
>>>
>>> +
>>> /**
>>> * Construct.
>>> */
>>> public AtmosphereBehavior()
>>> {
>>> + applicationKey = Application.get().getApplicationKey();
>>> + sessionId = Session.get().getId();
>>> + }
>>> +
>>> + private EventBus findEventBus()
>>> + {
>>> + return EventBus.get(Application.get(applicationKey));
>>> }
>>>
>>> @Override
>>> @@ -97,7 +111,7 @@ public class AtmosphereBehavior extends Behavior
>>> Meteor meteor = Meteor.build(request.getContainerRequest());
>>> String uuid = getUUID(meteor.getAtmosphereResource());
>>> component.getPage().setMetaData(ATMOSPHERE_UUID, uuid);
>>> - EventBus.get().registerPage(uuid, component.getPage());
>>> + findEventBus().registerPage(uuid, component.getPage());
>>>
>>> // Add us to the listener list.
>>> meteor.addListener(this);
>>> @@ -169,6 +183,7 @@ public class AtmosphereBehavior extends Behavior
>>> log.info(String.format("%s connection dropped from ip %s:%s", transport == null
>>> ? "websocket" : transport, req.getRemoteAddr(), req.getRemotePort()));
>>> }
>>> + findEventBus().unregisterConnection(getUUID(event.getResource()));
>>> }
>>>
>>> @Override
>>>
>>> http://git-wip-us.apache.org/repos/asf/wicket/blob/659ee9b3/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 2a0dfd4..794cf28 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
>>> @@ -19,6 +19,7 @@ package org.apache.wicket.atmosphere;
>>> import java.util.Collection;
>>> import java.util.Collections;
>>> import java.util.Iterator;
>>> +import java.util.Map;
>>>
>>> import javax.servlet.http.HttpServletRequest;
>>> import javax.servlet.http.HttpServletRequestWrapper;
>>> @@ -38,11 +39,10 @@ import org.atmosphere.cpr.BroadcasterFactory;
>>> import org.slf4j.Logger;
>>> import org.slf4j.LoggerFactory;
>>>
>>> -import com.google.common.collect.BiMap;
>>> import com.google.common.collect.Collections2;
>>> -import com.google.common.collect.HashBiMap;
>>> import com.google.common.collect.HashMultimap;
>>> import com.google.common.collect.Iterators;
>>> +import com.google.common.collect.Maps;
>>> import com.google.common.collect.Multimap;
>>>
>>> /**
>>> @@ -74,7 +74,16 @@ public class EventBus implements UnboundListener
>>> */
>>> public static EventBus get()
>>> {
>>> - return Application.get().getMetaData(EVENT_BUS_KEY);
>>> + return get(Application.get());
>>> + }
>>> +
>>> + /**
>>> + * @param application
>>> + * @return the {@code EventBus} registered for the given Wicket application.
>>> + */
>>> + public static EventBus get(Application application)
>>> + {
>>> + return application.getMetaData(EVENT_BUS_KEY);
>>> }
>>>
>>> private WebApplication application;
>>> @@ -83,7 +92,7 @@ public class EventBus implements UnboundListener
>>>
>>> private Multimap<PageKey, EventSubscription> subscriptions = HashMultimap.create();
>>>
>>> - private BiMap<String, PageKey> trackedPages = HashBiMap.create();
>>> + private Map<String, PageKey> trackedPages = Maps.newHashMap();
>>>
>>> /**
>>> * Creates and registers an {@code EventBus} for the given application. The first broadcaster
>>> @@ -125,7 +134,7 @@ public class EventBus implements UnboundListener
>>> PageKey pageKey = new PageKey(page.getPageId(), Session.get().getId());
>>> if (oldPage != null && !oldPage.equals(pageKey))
>>> subscriptions.removeAll(oldPage);
>>> - trackedPages.forcePut(trackingId, pageKey);
>>> + trackedPages.put(trackingId, pageKey);
>>> log.info("registered page {} for session {}",
>>> new Object[] { pageKey.getPageId(), pageKey.getSessionId() });
>>> }
>>> @@ -150,7 +159,26 @@ public class EventBus implements UnboundListener
>>> subscription.getBehaviorIndex() == null ? "" : ":" +
>>> subscription.getBehaviorIndex() });
>>> }
>>> - subscriptions.put(new PageKey(page.getPageId(), Session.get().getId()), subscription);
>>> + PageKey pageKey = new PageKey(page.getPageId(), Session.get().getId());
>>> + if (!subscriptions.containsEntry(pageKey, subscription))
>>> + {
>>> + subscriptions.put(pageKey, subscription);
>>> + }
>>> + }
>>> +
>>> + /**
>>> + * Unregisters all subscriptions for the given tracking id.
>>> + *
>>> + * @param trackingId
>>> + */
>>> + public synchronized void unregisterConnection(String trackingId)
>>> + {
>>> + PageKey pageKey = trackedPages.remove(trackingId);
>>> + if (log.isInfoEnabled() && pageKey != null)
>>> + {
>>> + log.info("unregistering page {} for session {}", new Object[] { pageKey.getPageId(),
>>> + pageKey.getSessionId() });
>>> + }
>>> }
>>>
>>> /**
>>> @@ -167,6 +195,10 @@ public class EventBus implements UnboundListener
>>> {
>>> for (AtmosphereResource resource : broadcaster.getAtmosphereResources())
>>> {
>>> + if (resource.isCancelled())
>>> + {
>>> + System.out.println("cancelled");
>>
>> SLF4J ? ;-) ^^
>>
>>> + }
>>> ThreadContext.detach();
>>> ThreadContext.setApplication(application);
>>> PageKey key;
>>>
>>
>>
>>
>> --
>> Martin Grigorov
>> jWeekend
>> Training, Consulting, Development
>> http://jWeekend.com
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com
Re: git commit: WICKET-4729: support multiple tabs with the same page
Posted by Emond Papegaaij <em...@gmail.com>.
You read all the commits, don't you? :) That line shouldn't have been
there, I often use System.out.println for temporary debug lines,
because it stands out of the rest of the logging due to the missing
timestamp etc. I've removed it.
On Tue, Sep 4, 2012 at 8:41 PM, Martin Grigorov <mg...@apache.org> wrote:
> On Tue, Sep 4, 2012 at 8:29 PM, <pa...@apache.org> wrote:
>> Updated Branches:
>> refs/heads/master c0c9635d9 -> 659ee9b33
>>
>>
>> WICKET-4729: support multiple tabs with the same page
>>
>>
>> Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/659ee9b3
>> Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/659ee9b3
>> Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/659ee9b3
>>
>> Branch: refs/heads/master
>> Commit: 659ee9b337944a461bef400aedbe5f71a5abccf2
>> Parents: c0c9635
>> Author: Emond Papegaaij <pa...@apache.org>
>> Authored: Tue Sep 4 20:27:45 2012 +0200
>> Committer: Emond Papegaaij <pa...@apache.org>
>> Committed: Tue Sep 4 20:27:56 2012 +0200
>>
>> ----------------------------------------------------------------------
>> .../wicket/atmosphere/AtmosphereBehavior.java | 17 +++++-
>> .../org/apache/wicket/atmosphere/EventBus.java | 44 +++++++++++++--
>> 2 files changed, 54 insertions(+), 7 deletions(-)
>> ----------------------------------------------------------------------
>>
>>
>> http://git-wip-us.apache.org/repos/asf/wicket/blob/659ee9b3/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java
>> ----------------------------------------------------------------------
>> diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java
>> index 3f574bb..f4641bd 100644
>> --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java
>> +++ b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java
>> @@ -18,9 +18,11 @@ package org.apache.wicket.atmosphere;
>>
>> import javax.servlet.http.HttpServletRequest;
>>
>> +import org.apache.wicket.Application;
>> import org.apache.wicket.Component;
>> import org.apache.wicket.IResourceListener;
>> import org.apache.wicket.MetaDataKey;
>> +import org.apache.wicket.Session;
>> import org.apache.wicket.WicketRuntimeException;
>> import org.apache.wicket.ajax.json.JSONException;
>> import org.apache.wicket.ajax.json.JSONObject;
>> @@ -66,13 +68,25 @@ public class AtmosphereBehavior extends Behavior
>>
>> private static final long serialVersionUID = 1L;
>>
>> + private String applicationKey;
>> +
>> + private String sessionId;
>> +
>> private Component component;
>>
>> +
>> /**
>> * Construct.
>> */
>> public AtmosphereBehavior()
>> {
>> + applicationKey = Application.get().getApplicationKey();
>> + sessionId = Session.get().getId();
>> + }
>> +
>> + private EventBus findEventBus()
>> + {
>> + return EventBus.get(Application.get(applicationKey));
>> }
>>
>> @Override
>> @@ -97,7 +111,7 @@ public class AtmosphereBehavior extends Behavior
>> Meteor meteor = Meteor.build(request.getContainerRequest());
>> String uuid = getUUID(meteor.getAtmosphereResource());
>> component.getPage().setMetaData(ATMOSPHERE_UUID, uuid);
>> - EventBus.get().registerPage(uuid, component.getPage());
>> + findEventBus().registerPage(uuid, component.getPage());
>>
>> // Add us to the listener list.
>> meteor.addListener(this);
>> @@ -169,6 +183,7 @@ public class AtmosphereBehavior extends Behavior
>> log.info(String.format("%s connection dropped from ip %s:%s", transport == null
>> ? "websocket" : transport, req.getRemoteAddr(), req.getRemotePort()));
>> }
>> + findEventBus().unregisterConnection(getUUID(event.getResource()));
>> }
>>
>> @Override
>>
>> http://git-wip-us.apache.org/repos/asf/wicket/blob/659ee9b3/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 2a0dfd4..794cf28 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
>> @@ -19,6 +19,7 @@ package org.apache.wicket.atmosphere;
>> import java.util.Collection;
>> import java.util.Collections;
>> import java.util.Iterator;
>> +import java.util.Map;
>>
>> import javax.servlet.http.HttpServletRequest;
>> import javax.servlet.http.HttpServletRequestWrapper;
>> @@ -38,11 +39,10 @@ import org.atmosphere.cpr.BroadcasterFactory;
>> import org.slf4j.Logger;
>> import org.slf4j.LoggerFactory;
>>
>> -import com.google.common.collect.BiMap;
>> import com.google.common.collect.Collections2;
>> -import com.google.common.collect.HashBiMap;
>> import com.google.common.collect.HashMultimap;
>> import com.google.common.collect.Iterators;
>> +import com.google.common.collect.Maps;
>> import com.google.common.collect.Multimap;
>>
>> /**
>> @@ -74,7 +74,16 @@ public class EventBus implements UnboundListener
>> */
>> public static EventBus get()
>> {
>> - return Application.get().getMetaData(EVENT_BUS_KEY);
>> + return get(Application.get());
>> + }
>> +
>> + /**
>> + * @param application
>> + * @return the {@code EventBus} registered for the given Wicket application.
>> + */
>> + public static EventBus get(Application application)
>> + {
>> + return application.getMetaData(EVENT_BUS_KEY);
>> }
>>
>> private WebApplication application;
>> @@ -83,7 +92,7 @@ public class EventBus implements UnboundListener
>>
>> private Multimap<PageKey, EventSubscription> subscriptions = HashMultimap.create();
>>
>> - private BiMap<String, PageKey> trackedPages = HashBiMap.create();
>> + private Map<String, PageKey> trackedPages = Maps.newHashMap();
>>
>> /**
>> * Creates and registers an {@code EventBus} for the given application. The first broadcaster
>> @@ -125,7 +134,7 @@ public class EventBus implements UnboundListener
>> PageKey pageKey = new PageKey(page.getPageId(), Session.get().getId());
>> if (oldPage != null && !oldPage.equals(pageKey))
>> subscriptions.removeAll(oldPage);
>> - trackedPages.forcePut(trackingId, pageKey);
>> + trackedPages.put(trackingId, pageKey);
>> log.info("registered page {} for session {}",
>> new Object[] { pageKey.getPageId(), pageKey.getSessionId() });
>> }
>> @@ -150,7 +159,26 @@ public class EventBus implements UnboundListener
>> subscription.getBehaviorIndex() == null ? "" : ":" +
>> subscription.getBehaviorIndex() });
>> }
>> - subscriptions.put(new PageKey(page.getPageId(), Session.get().getId()), subscription);
>> + PageKey pageKey = new PageKey(page.getPageId(), Session.get().getId());
>> + if (!subscriptions.containsEntry(pageKey, subscription))
>> + {
>> + subscriptions.put(pageKey, subscription);
>> + }
>> + }
>> +
>> + /**
>> + * Unregisters all subscriptions for the given tracking id.
>> + *
>> + * @param trackingId
>> + */
>> + public synchronized void unregisterConnection(String trackingId)
>> + {
>> + PageKey pageKey = trackedPages.remove(trackingId);
>> + if (log.isInfoEnabled() && pageKey != null)
>> + {
>> + log.info("unregistering page {} for session {}", new Object[] { pageKey.getPageId(),
>> + pageKey.getSessionId() });
>> + }
>> }
>>
>> /**
>> @@ -167,6 +195,10 @@ public class EventBus implements UnboundListener
>> {
>> for (AtmosphereResource resource : broadcaster.getAtmosphereResources())
>> {
>> + if (resource.isCancelled())
>> + {
>> + System.out.println("cancelled");
>
> SLF4J ? ;-) ^^
>
>> + }
>> ThreadContext.detach();
>> ThreadContext.setApplication(application);
>> PageKey key;
>>
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
Re: git commit: WICKET-4729: support multiple tabs with the same page
Posted by Martin Grigorov <mg...@apache.org>.
On Tue, Sep 4, 2012 at 8:29 PM, <pa...@apache.org> wrote:
> Updated Branches:
> refs/heads/master c0c9635d9 -> 659ee9b33
>
>
> WICKET-4729: support multiple tabs with the same page
>
>
> Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
> Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/659ee9b3
> Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/659ee9b3
> Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/659ee9b3
>
> Branch: refs/heads/master
> Commit: 659ee9b337944a461bef400aedbe5f71a5abccf2
> Parents: c0c9635
> Author: Emond Papegaaij <pa...@apache.org>
> Authored: Tue Sep 4 20:27:45 2012 +0200
> Committer: Emond Papegaaij <pa...@apache.org>
> Committed: Tue Sep 4 20:27:56 2012 +0200
>
> ----------------------------------------------------------------------
> .../wicket/atmosphere/AtmosphereBehavior.java | 17 +++++-
> .../org/apache/wicket/atmosphere/EventBus.java | 44 +++++++++++++--
> 2 files changed, 54 insertions(+), 7 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/wicket/blob/659ee9b3/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java
> ----------------------------------------------------------------------
> diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java
> index 3f574bb..f4641bd 100644
> --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java
> +++ b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java
> @@ -18,9 +18,11 @@ package org.apache.wicket.atmosphere;
>
> import javax.servlet.http.HttpServletRequest;
>
> +import org.apache.wicket.Application;
> import org.apache.wicket.Component;
> import org.apache.wicket.IResourceListener;
> import org.apache.wicket.MetaDataKey;
> +import org.apache.wicket.Session;
> import org.apache.wicket.WicketRuntimeException;
> import org.apache.wicket.ajax.json.JSONException;
> import org.apache.wicket.ajax.json.JSONObject;
> @@ -66,13 +68,25 @@ public class AtmosphereBehavior extends Behavior
>
> private static final long serialVersionUID = 1L;
>
> + private String applicationKey;
> +
> + private String sessionId;
> +
> private Component component;
>
> +
> /**
> * Construct.
> */
> public AtmosphereBehavior()
> {
> + applicationKey = Application.get().getApplicationKey();
> + sessionId = Session.get().getId();
> + }
> +
> + private EventBus findEventBus()
> + {
> + return EventBus.get(Application.get(applicationKey));
> }
>
> @Override
> @@ -97,7 +111,7 @@ public class AtmosphereBehavior extends Behavior
> Meteor meteor = Meteor.build(request.getContainerRequest());
> String uuid = getUUID(meteor.getAtmosphereResource());
> component.getPage().setMetaData(ATMOSPHERE_UUID, uuid);
> - EventBus.get().registerPage(uuid, component.getPage());
> + findEventBus().registerPage(uuid, component.getPage());
>
> // Add us to the listener list.
> meteor.addListener(this);
> @@ -169,6 +183,7 @@ public class AtmosphereBehavior extends Behavior
> log.info(String.format("%s connection dropped from ip %s:%s", transport == null
> ? "websocket" : transport, req.getRemoteAddr(), req.getRemotePort()));
> }
> + findEventBus().unregisterConnection(getUUID(event.getResource()));
> }
>
> @Override
>
> http://git-wip-us.apache.org/repos/asf/wicket/blob/659ee9b3/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 2a0dfd4..794cf28 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
> @@ -19,6 +19,7 @@ package org.apache.wicket.atmosphere;
> import java.util.Collection;
> import java.util.Collections;
> import java.util.Iterator;
> +import java.util.Map;
>
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletRequestWrapper;
> @@ -38,11 +39,10 @@ import org.atmosphere.cpr.BroadcasterFactory;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> -import com.google.common.collect.BiMap;
> import com.google.common.collect.Collections2;
> -import com.google.common.collect.HashBiMap;
> import com.google.common.collect.HashMultimap;
> import com.google.common.collect.Iterators;
> +import com.google.common.collect.Maps;
> import com.google.common.collect.Multimap;
>
> /**
> @@ -74,7 +74,16 @@ public class EventBus implements UnboundListener
> */
> public static EventBus get()
> {
> - return Application.get().getMetaData(EVENT_BUS_KEY);
> + return get(Application.get());
> + }
> +
> + /**
> + * @param application
> + * @return the {@code EventBus} registered for the given Wicket application.
> + */
> + public static EventBus get(Application application)
> + {
> + return application.getMetaData(EVENT_BUS_KEY);
> }
>
> private WebApplication application;
> @@ -83,7 +92,7 @@ public class EventBus implements UnboundListener
>
> private Multimap<PageKey, EventSubscription> subscriptions = HashMultimap.create();
>
> - private BiMap<String, PageKey> trackedPages = HashBiMap.create();
> + private Map<String, PageKey> trackedPages = Maps.newHashMap();
>
> /**
> * Creates and registers an {@code EventBus} for the given application. The first broadcaster
> @@ -125,7 +134,7 @@ public class EventBus implements UnboundListener
> PageKey pageKey = new PageKey(page.getPageId(), Session.get().getId());
> if (oldPage != null && !oldPage.equals(pageKey))
> subscriptions.removeAll(oldPage);
> - trackedPages.forcePut(trackingId, pageKey);
> + trackedPages.put(trackingId, pageKey);
> log.info("registered page {} for session {}",
> new Object[] { pageKey.getPageId(), pageKey.getSessionId() });
> }
> @@ -150,7 +159,26 @@ public class EventBus implements UnboundListener
> subscription.getBehaviorIndex() == null ? "" : ":" +
> subscription.getBehaviorIndex() });
> }
> - subscriptions.put(new PageKey(page.getPageId(), Session.get().getId()), subscription);
> + PageKey pageKey = new PageKey(page.getPageId(), Session.get().getId());
> + if (!subscriptions.containsEntry(pageKey, subscription))
> + {
> + subscriptions.put(pageKey, subscription);
> + }
> + }
> +
> + /**
> + * Unregisters all subscriptions for the given tracking id.
> + *
> + * @param trackingId
> + */
> + public synchronized void unregisterConnection(String trackingId)
> + {
> + PageKey pageKey = trackedPages.remove(trackingId);
> + if (log.isInfoEnabled() && pageKey != null)
> + {
> + log.info("unregistering page {} for session {}", new Object[] { pageKey.getPageId(),
> + pageKey.getSessionId() });
> + }
> }
>
> /**
> @@ -167,6 +195,10 @@ public class EventBus implements UnboundListener
> {
> for (AtmosphereResource resource : broadcaster.getAtmosphereResources())
> {
> + if (resource.isCancelled())
> + {
> + System.out.println("cancelled");
SLF4J ? ;-) ^^
> + }
> ThreadContext.detach();
> ThreadContext.setApplication(application);
> PageKey key;
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com