[seam-commits] Seam SVN: r11342 - branches/community/Seam_2_2/src/remoting/org/jboss/seam/remoting/messaging.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Aug 4 14:37:16 EDT 2009


Author: norman.richards at jboss.com
Date: 2009-08-04 14:37:16 -0400 (Tue, 04 Aug 2009)
New Revision: 11342

Added:
   branches/community/Seam_2_2/src/remoting/org/jboss/seam/remoting/messaging/UserTokens.java
Modified:
   branches/community/Seam_2_2/src/remoting/org/jboss/seam/remoting/messaging/SubscriptionRegistry.java
Log:
JBSEAM-2082

Modified: branches/community/Seam_2_2/src/remoting/org/jboss/seam/remoting/messaging/SubscriptionRegistry.java
===================================================================
--- branches/community/Seam_2_2/src/remoting/org/jboss/seam/remoting/messaging/SubscriptionRegistry.java	2009-08-04 14:57:20 UTC (rev 11341)
+++ branches/community/Seam_2_2/src/remoting/org/jboss/seam/remoting/messaging/SubscriptionRegistry.java	2009-08-04 18:37:16 UTC (rev 11342)
@@ -18,8 +18,6 @@
 import org.jboss.seam.annotations.Name;
 import org.jboss.seam.annotations.Scope;
 import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.contexts.Context;
-import org.jboss.seam.contexts.Contexts;
 import org.jboss.seam.log.LogProvider;
 import org.jboss.seam.log.Logging;
 
@@ -33,9 +31,6 @@
 @Install(value = false, precedence=BUILT_IN)
 public class SubscriptionRegistry
 {
-  public static final String CONTEXT_USER_TOKENS =
-      "org.jboss.seam.remoting.messaging.SubscriptionRegistry.userTokens";
-
   private static final LogProvider log = Logging.getLogProvider(SubscriptionRegistry.class);
 
   private String connectionProvider;
@@ -131,30 +126,35 @@
     }
   }
 
-  /**
-   *
-   * @return Set
-   */
-  public Set getUserTokens()
+  public UserTokens getUserTokens()
   {
-    Context session = Contexts.getSessionContext();
-    if (session.get(CONTEXT_USER_TOKENS) == null)
-    {
-      synchronized(session)
-      {
-        if (session.get(CONTEXT_USER_TOKENS) == null)
-          session.set(CONTEXT_USER_TOKENS, new HashSet<String> ());
-      }
-    }
-    return (Set) session.get(CONTEXT_USER_TOKENS);
+    return (UserTokens) Component.getInstance(UserTokens.class);
   }
 
   public RemoteSubscriber getSubscription(String token)
   {
-    if (!getUserTokens().contains(token))
-      throw new IllegalArgumentException(
-        "Invalid token argument - token not found in Session Context.");
-
+    if (!getUserTokens().contains(token)) {
+      throw new IllegalArgumentException("Invalid token argument - token not found in Session Context.");
+    }
+    
     return subscriptions.get(token);
   }
+  
+  public Set<String> getAllTokens() {
+      return subscriptions.keySet();
+  }
+
+  public void cleanupTokens(Set<String> tokens)
+  {
+       for (String token: tokens) {
+          RemoteSubscriber subscriber = subscriptions.remove(token);
+          if (subscriber!=null) {
+             try {
+                 subscriber.unsubscribe();
+             } catch (Exception e) {
+                log.debug("problem cleaning up subcription", e);
+             }
+          }          
+       }
+  }
 }

Added: branches/community/Seam_2_2/src/remoting/org/jboss/seam/remoting/messaging/UserTokens.java
===================================================================
--- branches/community/Seam_2_2/src/remoting/org/jboss/seam/remoting/messaging/UserTokens.java	                        (rev 0)
+++ branches/community/Seam_2_2/src/remoting/org/jboss/seam/remoting/messaging/UserTokens.java	2009-08-04 18:37:16 UTC (rev 11342)
@@ -0,0 +1,33 @@
+package org.jboss.seam.remoting.messaging;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Destroy;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+
+ at Name("org.jboss.seam.remoting.messaging.SubscriptionRegistry.userTokens")
+ at Scope(ScopeType.SESSION)
+public class UserTokens
+{
+   Set<String> tokens = new HashSet<String>();
+   
+   public void add(String token) {
+      tokens.add(token);
+   }
+   
+   public boolean contains(String token) {
+      return tokens.contains(token); 
+   }
+   
+   public void remove(String token) {
+      tokens.remove(token);
+   }
+   
+   @Destroy 
+   public void cleanUp() {
+       SubscriptionRegistry.instance().cleanupTokens(tokens);
+   }
+}



More information about the seam-commits mailing list