Author: nbelaevski
Date: 2010-10-11 12:13:31 -0400 (Mon, 11 Oct 2010)
New Revision: 19521
Added:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushSessionTrackerImpl.java
Modified:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/AtmospherePushHandler.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushSessionImpl.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushSessionTracker.java
branches/RF-7817/push-redesign/src/main/resources/META-INF/resources/org.richfaces/push.js
Log:
https://jira.jboss.org/browse/RF-7817
Modified:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/AtmospherePushHandler.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/AtmospherePushHandler.java 2010-10-11
16:06:07 UTC (rev 19520)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/AtmospherePushHandler.java 2010-10-11
16:13:31 UTC (rev 19521)
@@ -62,7 +62,7 @@
public AtmospherePushHandler(MessagesContextImpl messagesContext) {
super();
- pushTracker = new PushSessionTracker(Executors.newFixedThreadPool(1),
messagesContext);
+ pushTracker = new PushSessionTrackerImpl(Executors.newFixedThreadPool(1),
messagesContext);
}
/* (non-Javadoc)
Modified:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushSessionImpl.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushSessionImpl.java 2010-10-11
16:06:07 UTC (rev 19520)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushSessionImpl.java 2010-10-11
16:13:31 UTC (rev 19521)
@@ -46,7 +46,7 @@
private AtomicReference<Request> requestRef =
new AtomicReference<Request>();
- private PushSessionTracker pushTracker;
+ private PushSessionTrackerImpl pushTracker;
private volatile long expirationTime;
@@ -93,7 +93,7 @@
}
};
- public PushSessionImpl(PushSessionTracker pushTracker) {
+ public PushSessionImpl(PushSessionTrackerImpl pushTracker) {
super();
this.pushTracker = pushTracker;
resetExpirationTime();
Modified:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushSessionTracker.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushSessionTracker.java 2010-10-11
16:06:07 UTC (rev 19520)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushSessionTracker.java 2010-10-11
16:13:31 UTC (rev 19521)
@@ -21,82 +21,20 @@
*/
package org.richfaces.application.impl;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.DelayQueue;
-import java.util.concurrent.ExecutorService;
-
import org.richfaces.application.push.SubscriptionContext;
-import com.google.common.collect.MapMaker;
-
/**
* @author Nick Belaevski
*
*/
-public class PushSessionTracker {
+public interface PushSessionTracker {
- private final class SessionsExpirationRunnable implements Runnable {
- public void run() {
- while (true) {
- try {
- PushSessionImpl pushSession = expirationQueue.take();
- pushSessionMap.remove(pushSession.getId());
- pushSession.destroy();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
+ public PushSessionImpl createPushSession();
- }
- }
-
- private SubscriptionContext subscriptionContext;
-
- private ConcurrentMap<String, PushSessionImpl> pushSessionMap = new
MapMaker().makeMap();
-
- private DelayQueue<PushSessionImpl> expirationQueue = new
DelayQueue<PushSessionImpl>();
-
- public PushSessionTracker(ExecutorService executorService, SubscriptionContext
subscriptionContext) {
- executorService.submit(new SessionsExpirationRunnable());
-
- this.subscriptionContext = subscriptionContext;
- }
-
- public PushSessionImpl createPushSession() {
- PushSessionImpl pushSession = new PushSessionImpl(this);
- while (true) {
- String uuid = UUID.randomUUID().toString();
- pushSession.setId(uuid);
- if (pushSessionMap.putIfAbsent(uuid, pushSession) == null) {
- expirationQueue.put(pushSession);
-
- return pushSession;
- }
- }
- }
-
- public PushSessionImpl getPushSession(String id) {
- return pushSessionMap.get(id);
- }
+ public PushSessionImpl getPushSession(String id);
- public void removePushSession(String id) {
- PushSessionImpl session = pushSessionMap.remove(id);
- if (session != null) {
- expirationQueue.remove(session);
- }
- }
-
- void onRequestConnected(PushSessionImpl pushSession) {
- expirationQueue.remove(pushSession);
- }
-
- void onRequestDisconnected(PushSessionImpl pushSession) {
- expirationQueue.add(pushSession);
- }
-
- public SubscriptionContext getSubscriptionContext() {
- return subscriptionContext;
- }
-}
+ public void removePushSession(String id);
+
+ public SubscriptionContext getSubscriptionContext();
+
+}
\ No newline at end of file
Copied:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushSessionTrackerImpl.java
(from rev 19520,
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushSessionTracker.java)
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushSessionTrackerImpl.java
(rev 0)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushSessionTrackerImpl.java 2010-10-11
16:13:31 UTC (rev 19521)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.application.impl;
+
+import java.util.UUID;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.DelayQueue;
+import java.util.concurrent.ExecutorService;
+
+import org.richfaces.application.push.SubscriptionContext;
+
+import com.google.common.collect.MapMaker;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class PushSessionTrackerImpl implements PushSessionTracker {
+
+ private final class SessionsExpirationRunnable implements Runnable {
+ public void run() {
+ while (true) {
+ try {
+ PushSessionImpl pushSession = expirationQueue.take();
+ pushSessionMap.remove(pushSession.getId());
+ pushSession.destroy();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ }
+ }
+
+ private SubscriptionContext subscriptionContext;
+
+ private ConcurrentMap<String, PushSessionImpl> pushSessionMap = new
MapMaker().makeMap();
+
+ private DelayQueue<PushSessionImpl> expirationQueue = new
DelayQueue<PushSessionImpl>();
+
+ public PushSessionTrackerImpl(ExecutorService executorService, SubscriptionContext
subscriptionContext) {
+ executorService.submit(new SessionsExpirationRunnable());
+
+ this.subscriptionContext = subscriptionContext;
+ }
+
+ public PushSessionImpl createPushSession() {
+ PushSessionImpl pushSession = new PushSessionImpl(this);
+ while (true) {
+ String uuid = UUID.randomUUID().toString();
+ pushSession.setId(uuid);
+ if (pushSessionMap.putIfAbsent(uuid, pushSession) == null) {
+ expirationQueue.put(pushSession);
+
+ return pushSession;
+ }
+ }
+ }
+
+ public PushSessionImpl getPushSession(String id) {
+ return pushSessionMap.get(id);
+ }
+
+ public void removePushSession(String id) {
+ PushSessionImpl session = pushSessionMap.remove(id);
+ if (session != null) {
+ expirationQueue.remove(session);
+ }
+ }
+
+ void onRequestConnected(PushSessionImpl pushSession) {
+ expirationQueue.remove(pushSession);
+ }
+
+ void onRequestDisconnected(PushSessionImpl pushSession) {
+ expirationQueue.add(pushSession);
+ }
+
+ public SubscriptionContext getSubscriptionContext() {
+ return subscriptionContext;
+ }
+}
Modified:
branches/RF-7817/push-redesign/src/main/resources/META-INF/resources/org.richfaces/push.js
===================================================================
---
branches/RF-7817/push-redesign/src/main/resources/META-INF/resources/org.richfaces/push.js 2010-10-11
16:06:07 UTC (rev 19520)
+++
branches/RF-7817/push-redesign/src/main/resources/META-INF/resources/org.richfaces/push.js 2010-10-11
16:13:31 UTC (rev 19521)
@@ -7,8 +7,13 @@
__callback: function(response) {
var dataString = response.responseBody.replace(suspendMessageEndMarker,
"");
if (dataString) {
- var data = jQuery.parseJSON(dataString);
- alert(data[0].data);
+ var messages = jQuery.parseJSON(dataString);
+ if (messages) {
+ for (var i = 0; i < messages.length; i++) {
+ var message = messages[i];
+ alert(message.data);
+ }
+ }
}
},