Author: nbelaevski
Date: 2010-09-13 20:39:12 -0400 (Mon, 13 Sep 2010)
New Revision: 19181
Added:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/Message.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/SubscribersActivityListener.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/MessagePublisher.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/MessageSerializer.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/MessageTransformer.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/PushHandler.java
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/DefaultMessageSerializer.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/SubscriberActivityData.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/component/Subscription.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/component/SubscriptionImpl.java
Removed:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/MessageAttributes.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/PushMessage.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/webapp/PushAtmosphereHandler.java
Modified:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/MessageFilter.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/SubscriberKey.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/TopicKey.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/PushPublisherContext.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushPublisherContextImpl.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushSubscriberContextImpl.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/component/PushSubscriberContext.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/renderkit/html/PushRenderer.java
branches/RF-7817/push-redesign/src/main/java/org/richfaces/webapp/PushServlet.java
branches/RF-7817/push-redesign/src/main/resources/META-INF/resources/org.richfaces/push.js
Log:
https://jira.jboss.org/browse/RF-7817
Added: branches/RF-7817/push-redesign/src/main/java/org/richfaces/Message.java
===================================================================
--- branches/RF-7817/push-redesign/src/main/java/org/richfaces/Message.java
(rev 0)
+++ branches/RF-7817/push-redesign/src/main/java/org/richfaces/Message.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -0,0 +1,89 @@
+/*
+ * 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;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class Message {
+
+ private TopicKey topicKey;
+
+ private Map<String, Object> attributes = null;
+
+ private Object data;
+
+ public Message(TopicKey topicKey) {
+ super();
+ this.topicKey = topicKey;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+
+ public void addAttribute(String key, Object value) {
+ if (attributes == null) {
+ attributes = new HashMap<String, Object>();
+ }
+
+ attributes.put(key, value);
+ }
+
+ public void removeAttribute(String key) {
+ if (attributes != null) {
+ attributes.remove(key);
+ }
+ }
+
+ public Map<String, Object> getAttributes() {
+ if (attributes == null) {
+ attributes = new HashMap<String, Object>();
+ }
+
+ return attributes;
+ }
+
+ public Object getAttribute(String key) {
+ if (attributes != null) {
+ return attributes.get(key);
+ }
+
+ return null;
+ }
+
+ public boolean hasAttributes() {
+ return attributes != null && !attributes.isEmpty();
+ }
+
+ public TopicKey getTopicKey() {
+ return topicKey;
+ }
+}
Deleted:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/MessageAttributes.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/MessageAttributes.java 2010-09-13
23:04:21 UTC (rev 19180)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/MessageAttributes.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -1,40 +0,0 @@
-/*
- * 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;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class MessageAttributes {
-
- private TopicKey topic;
-
- public TopicKey getTopic() {
- return topic;
- }
-
- public void setTopic(TopicKey topic) {
- this.topic = topic;
- }
-
-}
Modified: branches/RF-7817/push-redesign/src/main/java/org/richfaces/MessageFilter.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/MessageFilter.java 2010-09-13
23:04:21 UTC (rev 19180)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/MessageFilter.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -27,6 +27,6 @@
*/
public interface MessageFilter {
- public boolean accept(MessageAttributes attributes, Object message);
+ public boolean accept(Message message);
}
Modified: branches/RF-7817/push-redesign/src/main/java/org/richfaces/SubscriberKey.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/SubscriberKey.java 2010-09-13
23:04:21 UTC (rev 19180)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/SubscriberKey.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -34,6 +34,11 @@
*/
public SubscriberKey(String uuid) {
super();
+
+ if (uuid == null) {
+ throw new NullPointerException();
+ }
+
this.uuid = uuid;
}
Added:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/SubscribersActivityListener.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/SubscribersActivityListener.java
(rev 0)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/SubscribersActivityListener.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface SubscribersActivityListener {
+
+ public void onRequestStarted(SubscriberKey subscriberKey);
+
+ public void onRequestFinished(SubscriberKey subscriberKey);
+
+}
Modified: branches/RF-7817/push-redesign/src/main/java/org/richfaces/TopicKey.java
===================================================================
--- branches/RF-7817/push-redesign/src/main/java/org/richfaces/TopicKey.java 2010-09-13
23:04:21 UTC (rev 19180)
+++ branches/RF-7817/push-redesign/src/main/java/org/richfaces/TopicKey.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -31,6 +31,11 @@
public TopicKey(String topicName) {
super();
+
+ if (topicName == null) {
+ throw new NullPointerException();
+ }
+
this.topicName = topicName;
}
Added:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/MessagePublisher.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/MessagePublisher.java
(rev 0)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/MessagePublisher.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+import org.richfaces.TopicKey;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface MessagePublisher {
+
+ public void publish(TopicKey topicKey, String messageData);
+
+}
Added:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/MessageSerializer.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/MessageSerializer.java
(rev 0)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/MessageSerializer.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+import org.richfaces.Message;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface MessageSerializer {
+
+ public String serialize(Message message);
+
+}
Added:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/MessageTransformer.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/MessageTransformer.java
(rev 0)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/MessageTransformer.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+import org.richfaces.Message;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface MessageTransformer {
+
+ public Message transform(Message o);
+
+}
Added:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/PushHandler.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/PushHandler.java
(rev 0)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/PushHandler.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class PushHandler<T> {
+
+ public abstract void connect(T request);
+
+ public abstract void disconnect(T request);
+
+}
Deleted:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/PushMessage.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/PushMessage.java 2010-09-13
23:04:21 UTC (rev 19180)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/PushMessage.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -1,50 +0,0 @@
-/*
- * 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;
-
-import org.richfaces.TopicKey;
-
-/**
- * @author Nick Belaevski
- *
- */
-public final class PushMessage {
-
- private TopicKey topicKey;
-
- private Object data;
-
- public PushMessage(TopicKey topicKey, Object data) {
- super();
- this.topicKey = topicKey;
- this.data = data;
- }
-
- public TopicKey getTopicKey() {
- return topicKey;
- }
-
- public Object getData() {
- return data;
- }
-
-}
Modified:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/PushPublisherContext.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/PushPublisherContext.java 2010-09-13
23:04:21 UTC (rev 19180)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/PushPublisherContext.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -21,8 +21,7 @@
*/
package org.richfaces.application;
-import org.richfaces.DeliveryMode;
-import org.richfaces.MessageAttributes;
+import org.richfaces.Message;
import org.richfaces.TopicKey;
@@ -32,6 +31,10 @@
*/
public interface PushPublisherContext {
+ public static final String PUBLISHER_ATTRIBUTE_NAME =
"__org_richfaces_PushPublisherContext";
+
+ public static final String PUBLISHER_EL_EXPRESSION = "#{" +
PUBLISHER_ATTRIBUTE_NAME + "}";
+
//TODO - return Future?
//TODO - use topic key?
public void publish(TopicKey topic, Object message);
@@ -39,6 +42,14 @@
//TODO - return Future?
//TODO - use topic key?
//TODO - priority?
- public void publish(MessageAttributes attributes, Object message, long ttl,
DeliveryMode deliveryMode);
+ public void publish(Message message);
+
+ public abstract void removeMessageTransformer(MessageTransformer transformer);
+
+ public abstract void addMessageTransformer(MessageTransformer transformer);
+
+ public abstract MessageSerializer getMessageSerializer();
+
+ public abstract void setMessageSerializer(MessageSerializer serializer);
}
Added:
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
(rev 0)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/AtmospherePushHandler.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -0,0 +1,119 @@
+/*
+ * 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 static org.richfaces.application.PushPublisherContext.PUBLISHER_ATTRIBUTE_NAME;
+import static org.richfaces.component.PushSubscriberContext.SUBSCRIBER_ATTRIBUTE_NAME;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.atmosphere.cpr.AtmosphereHandler;
+import org.atmosphere.cpr.AtmosphereResource;
+import org.atmosphere.cpr.AtmosphereResourceEvent;
+import org.atmosphere.cpr.AtmosphereServlet.AtmosphereHandlerWrapper;
+import org.atmosphere.cpr.Broadcaster;
+import org.atmosphere.cpr.DefaultBroadcaster;
+import org.richfaces.SubscriberKey;
+import org.richfaces.TopicKey;
+import org.richfaces.application.MessagePublisher;
+import org.richfaces.application.PushPublisherContext;
+import org.richfaces.component.PushSubscriberContext;
+import org.richfaces.component.Subscription;
+
+import com.google.common.base.Function;
+import com.google.common.collect.MapMaker;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class AtmospherePushHandler implements AtmosphereHandler<HttpServletRequest,
HttpServletResponse>, MessagePublisher {
+
+ private PushSubscriberContext subscriberContext;
+
+ private PushPublisherContext publisherContext;
+
+ private Map<TopicKey, Broadcaster> broadcasters = new
MapMaker().makeComputingMap(new Function<TopicKey, Broadcaster>() {
+ public Broadcaster apply(TopicKey from) {
+ return new DefaultBroadcaster(from.getTopicName());
+ };
+ });
+
+ public AtmospherePushHandler(ServletContext servletContext) {
+ super();
+
+ subscriberContext = new PushSubscriberContextImpl();
+ publisherContext = new PushPublisherContextImpl(this);
+
+ servletContext.setAttribute(SUBSCRIBER_ATTRIBUTE_NAME, subscriberContext);
+ servletContext.setAttribute(PUBLISHER_ATTRIBUTE_NAME, publisherContext);
+ }
+
+ protected SubscriberKey getSubscriberKey(AtmosphereResource<HttpServletRequest,
HttpServletResponse> resource) {
+ return new SubscriberKey(resource.getRequest().getParameter("pid"));
+ }
+
+ public void publish(TopicKey topicKey, String message) {
+ Broadcaster broadcaster = broadcasters.get(topicKey);
+ broadcaster.broadcast(message);
+ }
+
+ public void onRequest(AtmosphereResource<HttpServletRequest,
HttpServletResponse> resource) throws IOException {
+ SubscriberKey subscriberKey = getSubscriberKey(resource);
+
+ Subscription[] subscriptions =
subscriberContext.getSubscriptions(subscriberKey);
+ if (subscriptions == null) {
+ //TODO - handle
+ }
+
+ subscriberContext.onRequestStarted(subscriberKey);
+
+ //TODO - ONLY FOR TESTING!!!
+ Broadcaster broadcaster = broadcasters.get(subscriptions[0].getTopicKey());
+ broadcaster.addAtmosphereResource(resource);
+
+ //TODO - review
+ resource.getAtmosphereConfig().mapBroadcasterToAtmosphereHandler(broadcaster, new
AtmosphereHandlerWrapper(this, broadcaster));
+
+ resource.suspend();
+ }
+
+ public void onStateChange(AtmosphereResourceEvent<HttpServletRequest,
HttpServletResponse> event)
+ throws IOException {
+
+ if (event.isCancelled()) {
+ SubscriberKey subscriberKey = getSubscriberKey(event.getResource());
+ subscriberContext.onRequestFinished(subscriberKey);
+ } else {
+ PrintWriter responseWriter = event.getResource().getResponse().getWriter();
+ responseWriter.write(event.getMessage().toString());
+ responseWriter.flush();
+ }
+ }
+
+}
Added:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/DefaultMessageSerializer.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/DefaultMessageSerializer.java
(rev 0)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/DefaultMessageSerializer.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -0,0 +1,57 @@
+/*
+ * 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.HashMap;
+import java.util.Map;
+
+import org.ajax4jsf.javascript.ScriptUtils;
+import org.richfaces.Message;
+import org.richfaces.application.MessageSerializer;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class DefaultMessageSerializer implements MessageSerializer {
+
+ public static final String TOPIC_ATTRIBUTE = "topic";
+
+ public static final String ATTRIBUTES_ATTRIBUTE = "attributes";
+
+ public static final String DATA_ATTRIBUTE = "data";
+
+ public String serialize(Message message) {
+ Map<String,Object> dataMap = new HashMap<String, Object>();
+
+ dataMap.put(TOPIC_ATTRIBUTE, message.getTopicKey().getTopicName());
+
+ if (message.hasAttributes()) {
+ dataMap.put(ATTRIBUTES_ATTRIBUTE, message.getAttributes());
+ }
+
+ dataMap.put(DATA_ATTRIBUTE, message.getData());
+
+ return ScriptUtils.toScript(dataMap);
+ }
+
+}
Modified:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushPublisherContextImpl.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushPublisherContextImpl.java 2010-09-13
23:04:21 UTC (rev 19180)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushPublisherContextImpl.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -21,50 +21,80 @@
*/
package org.richfaces.application.impl;
-import javax.faces.bean.ApplicationScoped;
-import javax.faces.bean.ManagedBean;
-import javax.faces.bean.ManagedProperty;
-import javax.faces.context.FacesContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
-import org.atmosphere.cpr.AtmosphereResource;
-import org.richfaces.DeliveryMode;
-import org.richfaces.MessageAttributes;
+import org.richfaces.Message;
import org.richfaces.TopicKey;
+import org.richfaces.application.MessagePublisher;
+import org.richfaces.application.MessageSerializer;
+import org.richfaces.application.MessageTransformer;
import org.richfaces.application.PushPublisherContext;
-import org.richfaces.component.PushSubscriberContext;
/**
* @author Nick Belaevski
*
*/
-@ManagedBean(eager = true, name = "__pushPublisherContext")
-@ApplicationScoped
public class PushPublisherContextImpl implements PushPublisherContext {
- @ManagedProperty(value = "#{__pushSubscriberContext}")
- private PushSubscriberContext<AtmosphereResource<?, ?>>
subscriberContext;
+ private final MessagePublisher publisher;
+
+ private volatile MessageSerializer serializer = new DefaultMessageSerializer();
- public void setSubscriberContext(PushSubscriberContext<AtmosphereResource<?,
?>> subscriberContext) {
- this.subscriberContext = subscriberContext;
+ private List<MessageTransformer> transformers = new
CopyOnWriteArrayList<MessageTransformer>();
+
+ public PushPublisherContextImpl(MessagePublisher publisher) {
+ super();
+ this.publisher = publisher;
}
+
+ public void setMessageSerializer(MessageSerializer serializer) {
+ this.serializer = serializer;
+ }
+
+ public MessageSerializer getMessageSerializer() {
+ return serializer;
+ }
+
+ public void addMessageTransformer(MessageTransformer transformer) {
+ if (!transformers.contains(transformer)) {
+ transformers.add(transformer);
+ }
+ }
- /* (non-Javadoc)
- * @see org.richfaces.application.PushPublisherContext#publish(java.lang.String,
java.lang.Object)
- */
+ public void removeMessageTransformer(MessageTransformer transformer) {
+ transformers.remove(transformer);
+ }
+
+ protected Message getTransformedMessage(Message message) {
+ Message result = message;
+
+ for (MessageTransformer transformer : transformers) {
+ result = transformer.transform(result);
+ if (result == null) {
+ break;
+ }
+ }
+
+ return result;
+ }
+
+ protected void doPublish(Message message) {
+ publisher.publish(message.getTopicKey(), serializer.serialize(message));
+ }
+
public void publish(TopicKey topic, Object message) {
- // TODO Auto-generated method stub
- FacesContext context = FacesContext.getCurrentInstance();
- HttpServletRequest request = (HttpServletRequest)
context.getExternalContext().getRequest();
- HttpServletResponse response = (HttpServletResponse)
context.getExternalContext().getResponse();
+ Message messageObject = new Message(topic);
+ messageObject.setData(message);
+ publish(messageObject);
}
- /* (non-Javadoc)
- * @see
org.richfaces.application.PushPublisherContext#publish(org.richfaces.MessageAttributes,
java.lang.Object, long, org.richfaces.DeliveryMode)
- */
- public void publish(MessageAttributes attributes, Object message, long ttl,
DeliveryMode deliveryMode) {
- throw new UnsupportedOperationException();
+ public void publish(Message message) {
+ Message transformedMessage = getTransformedMessage(message);
+
+ if (transformedMessage != null) {
+ doPublish(transformedMessage);
+ }
}
}
Modified:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushSubscriberContextImpl.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushSubscriberContextImpl.java 2010-09-13
23:04:21 UTC (rev 19180)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/PushSubscriberContextImpl.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -22,75 +22,132 @@
package org.richfaces.application.impl;
import java.util.Collection;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
-import javax.faces.bean.ApplicationScoped;
-import javax.faces.bean.ManagedBean;
-
-import org.atmosphere.cpr.AtmosphereResource;
import org.richfaces.MessageFilter;
import org.richfaces.SubscriberKey;
+import org.richfaces.SubscribersActivityListener;
import org.richfaces.TopicKey;
import org.richfaces.component.PushSubscriberContext;
+import org.richfaces.component.Subscription;
+import org.richfaces.component.SubscriptionImpl;
import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.MapMaker;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Multimaps;
/**
* @author Nick Belaevski
*
*/
-@ApplicationScoped
-@ManagedBean(eager = true, name = "__pushSubscriberContext")
-public class PushSubscriberContextImpl implements
PushSubscriberContext<AtmosphereResource<?, ?>> {
+public class PushSubscriberContextImpl implements PushSubscriberContext,
SubscribersActivityListener {
- private ConcurrentMap<SubscriberKey, TopicKey> subscribers = new
ConcurrentHashMap<SubscriberKey, TopicKey>();
-
- private ConcurrentMap<TopicKey, Collection<AtmosphereResource<?,
?>>> requests = new MapMaker().makeComputingMap(new Function<TopicKey,
Collection<AtmosphereResource<?, ?>>>() {
- public Collection<org.atmosphere.cpr.AtmosphereResource<?,?>>
apply(TopicKey from) {
- return new CopyOnWriteArrayList<AtmosphereResource<?,?>>();
- };
+ /**
+ *
+ */
+ private static final int EXPIRATION_INTERVAL = 5 * 60 * 1000;
+
+ private static final Subscription[] EMPTY_SUBSCRPTION_ARRAY = new Subscription[0];
+
+ private Multimap<SubscriberKey, Subscription> subscriptionsMap =
Multimaps.synchronizedSetMultimap(
+ LinkedHashMultimap.<SubscriberKey, Subscription>create());
+
+ private Map<SubscriberKey, SubscriberActivityData> subscribersActivityMap = new
MapMaker().makeComputingMap(new Function<SubscriberKey, SubscriberActivityData>() {
+
+ public SubscriberActivityData apply(SubscriberKey from) {
+ return new SubscriberActivityData();
+ }
+
});
- public void subscribe(SubscriberKey subscriberKey, TopicKey topicKey) {
- subscribers.put(subscriberKey, topicKey);
+ private ScheduledExecutorService activityExpirationService;
+
+ public PushSubscriberContextImpl() {
+ activityExpirationService = new ScheduledThreadPoolExecutor(1);
+ activityExpirationService.scheduleAtFixedRate(new Runnable() {
+
+ public void run() {
+
+ Iterator<Entry<SubscriberKey, SubscriberActivityData>>
entries = subscribersActivityMap.entrySet().iterator();
+ while (entries.hasNext()) {
+ Entry<SubscriberKey, SubscriberActivityData> entry =
entries.next();
+
+ long lastAccessTime = entry.getValue().getLastAccessTime();
+
+ if (lastAccessTime < 0) {
+ continue;
+ }
+
+ if (System.currentTimeMillis() - lastAccessTime >
EXPIRATION_INTERVAL) {
+ unsubscribe(entry.getKey());
+ }
+ }
+ }
+ }, 0, 1, TimeUnit.SECONDS);
}
-
+
+ protected void onSubscriptionAdded(SubscriberKey subscriberKey, Subscription
subscription) {
+ //force activity data creation
+ subscribersActivityMap.get(subscriberKey);
+ }
+
+ protected void onSubscriptionRemoved(SubscriberKey subscriberKey) {
+ subscribersActivityMap.remove(subscriberKey);
+ }
+
+ public void subscribe(SubscriberKey subscriberKey, TopicKey topic) {
+ Subscription subscription = new SubscriptionImpl(topic, null, false);
+ subscriptionsMap.put(subscriberKey, subscription);
+ onSubscriptionAdded(subscriberKey, subscription);
+ }
+
public void subscribe(SubscriberKey subscriberKey, TopicKey topic, MessageFilter
filter) {
- throw new UnsupportedOperationException();
+ SubscriptionImpl subscription = new SubscriptionImpl(topic, filter, false);
+ subscriptionsMap.put(subscriberKey, subscription);
+ onSubscriptionAdded(subscriberKey, subscription);
}
-
+
public void subscribeDurably(SubscriberKey subscriberKey, TopicKey topic) {
- throw new UnsupportedOperationException();
+ Subscription subscription = new SubscriptionImpl(topic, null, true);
+ subscriptionsMap.put(subscriberKey, subscription);
+ onSubscriptionAdded(subscriberKey, subscription);
}
public void subscribeDurably(SubscriberKey subscriberKey, TopicKey topic,
MessageFilter filter) {
- throw new UnsupportedOperationException();
+ Subscription subscription = new SubscriptionImpl(topic, filter, true);
+ subscriptionsMap.put(subscriberKey, subscription);
+ onSubscriptionAdded(subscriberKey, subscription);
}
-
- public void unsubscribe(SubscriberKey subscriberKey) {
- subscribers.remove(subscriberKey);
- }
-
- public void onConnect(SubscriberKey subscriberKey, AtmosphereResource<?, ?>
resource) {
- TopicKey topicKey = subscribers.get(subscriberKey);
- if (topicKey == null) {
- //TODO - handle
+
+ public Subscription[] getSubscriptions(SubscriberKey subscriberKey) {
+ Collection<Subscription> collection = subscriptionsMap.get(subscriberKey);
+ if (collection == null) {
+ return null;
}
- requests.get(topicKey).add(resource);
+ return collection.toArray(EMPTY_SUBSCRPTION_ARRAY);
}
-
- public void onDisconnect(SubscriberKey subscriberKey, AtmosphereResource<?, ?>
resource) {
- // TODO Auto-generated method stub
-
- TopicKey topicKey = subscribers.get(subscriberKey);
- if (topicKey == null) {
- //TODO - handle
+
+ public void unsubscribe(SubscriberKey subscriberKey) {
+ if (!Iterables.isEmpty(subscriptionsMap.removeAll(subscriberKey))) {
+ onSubscriptionRemoved(subscriberKey);
}
-
- requests.get(topicKey).remove(resource);
+ subscribersActivityMap.remove(subscriberKey);
}
+
+ public void onRequestStarted(SubscriberKey subscriberKey) {
+ subscribersActivityMap.get(subscriberKey).onRequestStarted();
+ }
+
+ public void onRequestFinished(SubscriberKey subscriberKey) {
+ subscribersActivityMap.get(subscriberKey).onRequestFinished();
+ }
}
Added:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/SubscriberActivityData.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/SubscriberActivityData.java
(rev 0)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/application/impl/SubscriberActivityData.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -0,0 +1,51 @@
+/*
+ * 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.concurrent.atomic.AtomicInteger;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+final class SubscriberActivityData {
+
+ private AtomicInteger requestsCount = new AtomicInteger();
+
+ private volatile long lastAccessTime = System.currentTimeMillis();
+
+ public void onRequestStarted() {
+ requestsCount.incrementAndGet();
+
+ lastAccessTime = -1;
+ }
+
+ public void onRequestFinished() {
+ if (requestsCount.decrementAndGet() == 0) {
+ lastAccessTime = System.currentTimeMillis();
+ }
+ }
+
+ public long getLastAccessTime() {
+ return lastAccessTime;
+ }
+}
Modified:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/component/PushSubscriberContext.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/component/PushSubscriberContext.java 2010-09-13
23:04:21 UTC (rev 19180)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/component/PushSubscriberContext.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -30,10 +30,10 @@
* @author Nick Belaevski
*
*/
-public interface PushSubscriberContext<T> {
+public interface PushSubscriberContext {
- public static final String PUSH_PATH = "rf-hub";
-
+ public static final String SUBSCRIBER_ATTRIBUTE_NAME =
"__org_richfaces_PushSubscriberContext";
+
public void subscribe(SubscriberKey subscriberKey, TopicKey topic);
public void subscribe(SubscriberKey subscriberKey, TopicKey topic, MessageFilter
filter);
@@ -44,7 +44,10 @@
public void unsubscribe(SubscriberKey subscriberKey);
- public void onConnect(SubscriberKey subscriberKey, T resource);
-
- public void onDisconnect(SubscriberKey subscriberKey, T resource);
+ public Subscription[] getSubscriptions(SubscriberKey subscriberKey);
+
+ public abstract void onRequestFinished(SubscriberKey subscriberKey);
+
+ public abstract void onRequestStarted(SubscriberKey subscriberKey);
+
}
Added:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/component/Subscription.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/component/Subscription.java
(rev 0)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/component/Subscription.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -0,0 +1,39 @@
+/*
+ * 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.component;
+
+import org.richfaces.MessageFilter;
+import org.richfaces.TopicKey;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface Subscription {
+
+ public abstract TopicKey getTopicKey();
+
+ public abstract MessageFilter getMessageFilter();
+
+ public abstract boolean isDurable();
+
+}
\ No newline at end of file
Added:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/component/SubscriptionImpl.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/component/SubscriptionImpl.java
(rev 0)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/component/SubscriptionImpl.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -0,0 +1,92 @@
+/*
+ * 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.component;
+
+import org.richfaces.MessageFilter;
+import org.richfaces.TopicKey;
+
+public final class SubscriptionImpl implements Subscription {
+
+ private final TopicKey topicKey;
+
+ private final MessageFilter messageFilter;
+
+ private final boolean durability;
+
+ public SubscriptionImpl(TopicKey topicKey, MessageFilter messageFilter, boolean
durability) {
+ super();
+ this.topicKey = topicKey;
+ this.messageFilter = messageFilter;
+ this.durability = durability;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((topicKey == null) ? 0 : topicKey.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ SubscriptionImpl other = (SubscriptionImpl) obj;
+ if (topicKey == null) {
+ if (other.topicKey != null) {
+ return false;
+ }
+ } else if (!topicKey.equals(other.topicKey)) {
+ return false;
+ }
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.Subscription#getTopicKey()
+ */
+ public TopicKey getTopicKey() {
+ return topicKey;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.Subscription#getMessageFilter()
+ */
+ public MessageFilter getMessageFilter() {
+ return messageFilter;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.Subscription#isDurable()
+ */
+ public boolean isDurable() {
+ return durability;
+ }
+}
\ No newline at end of file
Modified:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/renderkit/html/PushRenderer.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/renderkit/html/PushRenderer.java 2010-09-13
23:04:21 UTC (rev 19180)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/renderkit/html/PushRenderer.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -21,6 +21,8 @@
*/
package org.richfaces.renderkit.html;
+import static org.richfaces.component.PushSubscriberContext.SUBSCRIBER_ATTRIBUTE_NAME;
+
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Map;
@@ -68,14 +70,14 @@
private String getPushUrl(FacesContext context, String pushId) {
ExternalContext ec = context.getExternalContext();
- return
MessageFormat.format("{0}://{1}:{2,number,#####}{3}/atmosphere/{4}/?pid={5}",
+ return
MessageFormat.format("{0}://{1}:{2,number,#####}{3}/atmosphere/?pid={4}",
ec.getRequestScheme(), ec.getRequestServerName(),
ec.getRequestServerPort(), ec.getRequestContextPath(),
- PushSubscriberContext.PUSH_PATH, pushId);
+ pushId);
}
private PushSubscriberContext getPushSubscriberContext(FacesContext context) {
- return (PushSubscriberContext)
context.getExternalContext().getApplicationMap().get("__pushSubscriberContext");
+ return (PushSubscriberContext)
context.getExternalContext().getApplicationMap().get(SUBSCRIBER_ATTRIBUTE_NAME);
}
@Override
Deleted:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/webapp/PushAtmosphereHandler.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/webapp/PushAtmosphereHandler.java 2010-09-13
23:04:21 UTC (rev 19180)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/webapp/PushAtmosphereHandler.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -1,72 +0,0 @@
-/*
- * 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.webapp;
-
-import java.io.IOException;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.atmosphere.cpr.AtmosphereHandler;
-import org.atmosphere.cpr.AtmosphereResource;
-import org.atmosphere.cpr.AtmosphereResourceEvent;
-import org.richfaces.SubscriberKey;
-import org.richfaces.component.PushSubscriberContext;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class PushAtmosphereHandler implements AtmosphereHandler<HttpServletRequest,
HttpServletResponse> {
-
- private PushSubscriberContext<AtmosphereResource<?, ?>>
subscriberContext;
-
- public PushAtmosphereHandler(ServletContext servletContext) {
- super();
-
- this.subscriberContext = (PushSubscriberContext<AtmosphereResource<?,
?>>) servletContext.getAttribute("__pushSubscriberContext");
- }
-
- private SubscriberKey getSubscriberKey(HttpServletRequest request) {
- return new SubscriberKey(request.getParameter("pid"));
- }
-
- public void onRequest(AtmosphereResource<HttpServletRequest,
HttpServletResponse> resource) throws IOException {
- // TODO Auto-generated method stub
- subscriberContext.onConnect(getSubscriberKey(resource.getRequest()), resource);
-
- resource.suspend();
- }
-
- public void onStateChange(AtmosphereResourceEvent<HttpServletRequest,
HttpServletResponse> event)
- throws IOException {
- // TODO Auto-generated method stub
-
- if (event.isCancelled()) {
- AtmosphereResource<HttpServletRequest, HttpServletResponse> resource =
event.getResource();
- subscriberContext.onDisconnect(getSubscriberKey(resource.getRequest()),
resource);
- }
- }
-
-
-}
Modified:
branches/RF-7817/push-redesign/src/main/java/org/richfaces/webapp/PushServlet.java
===================================================================
---
branches/RF-7817/push-redesign/src/main/java/org/richfaces/webapp/PushServlet.java 2010-09-13
23:04:21 UTC (rev 19180)
+++
branches/RF-7817/push-redesign/src/main/java/org/richfaces/webapp/PushServlet.java 2010-09-14
00:39:12 UTC (rev 19181)
@@ -29,7 +29,7 @@
import org.atmosphere.cpr.AtmosphereServlet;
import org.atmosphere.cpr.DefaultBroadcaster;
-import org.richfaces.component.PushSubscriberContext;
+import org.richfaces.application.impl.AtmospherePushHandler;
/**
* @author Nick Belaevski
@@ -48,6 +48,8 @@
URISyntaxException {
super.autoDetectAtmosphereHandlers(sc, c);
- addAtmosphereHandler("/atmosphere/" + PushSubscriberContext.PUSH_PATH +
"/*", new PushAtmosphereHandler(sc), new DefaultBroadcaster());
+ addAtmosphereHandler("/atmosphere/*", new AtmospherePushHandler(sc),
new DefaultBroadcaster());
}
+
+
}
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-09-13
23:04:21 UTC (rev 19180)
+++
branches/RF-7817/push-redesign/src/main/resources/META-INF/resources/org.richfaces/push.js 2010-09-14
00:39:12 UTC (rev 19181)
@@ -5,7 +5,8 @@
return {
__callback: function(response) {
- debugger;
+ alert(response.responseBody);
+ response.responseBody = "";
},
connect: function(url, opts) {