On Tue, Sep 4, 2012 at 8:29 PM,  <[email protected]> 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 <[email protected]>
> Authored: Tue Sep 4 20:27:45 2012 +0200
> Committer: Emond Papegaaij <[email protected]>
> 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

Reply via email to