Hey WCP folks,

I've just started using wicket-contrib-push, and I feel a bit at home with
all these comments with my name as the author :-)

I would like to discuss the design with you. For the moment there interfaces
implemented by both timer and comet implementations, but it's not that easy
to switch. Indeed if you look at the examples they are very implementation
dependent.

So my proposition is to introduce another interface, called IPushService,
which would allow both to publish and receive events. You would have a timer
and cometd based implementations for the moment, but you could rely on the
interface only the interface for push related operations.

I attach a patch on current code base with an implementation of what I'm
thinking about, it may help you better see what I mean.

WDYT?

Xavier
--
Xavier Hanin - Independent Java Consultant
Manage your dependencies with Ivy!
http://incubator.apache.org/ivy/
Index: D:/users/xavier/documents/wkspace/sourceforge/wicket-stuff/wicket-contrib-push/.project
===================================================================
--- D:/users/xavier/documents/wkspace/sourceforge/wicket-stuff/wicket-contrib-push/.project	(revision 2113)
+++ D:/users/xavier/documents/wkspace/sourceforge/wicket-stuff/wicket-contrib-push/.project	(working copy)
@@ -1,5 +1,5 @@
 <projectDescription>
-  <name>push</name>
+  <name>wicketstuff-push</name>
   <comment>An integration project for server side pushing in Wicket</comment>
   <projects/>
   <buildSpec>
Index: D:/users/xavier/documents/wkspace/sourceforge/wicket-stuff/wicket-contrib-push/src/main/java/org/wicketstuff/push/timer/TimerPushService.java
===================================================================
--- D:/users/xavier/documents/wkspace/sourceforge/wicket-stuff/wicket-contrib-push/src/main/java/org/wicketstuff/push/timer/TimerPushService.java	(revision 0)
+++ D:/users/xavier/documents/wkspace/sourceforge/wicket-stuff/wicket-contrib-push/src/main/java/org/wicketstuff/push/timer/TimerPushService.java	(revision 0)
@@ -0,0 +1,35 @@
+package org.wicketstuff.push.timer;
+
+import java.util.Map;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.util.time.Duration;
+import org.wicketstuff.push.IPushBehavior;
+import org.wicketstuff.push.IPushPublisher;
+import org.wicketstuff.push.IPushService;
+import org.wicketstuff.push.IPushTarget;
+import org.wicketstuff.push.PushEvent;
+
+public class TimerPushService implements IPushService {
+	private Duration duration;
+	private IPushPublisher publisher = new TimerPushPublisher();
+
+	public TimerPushService(Duration duration) {
+		this.duration = duration;
+	}
+
+	public void addPushBehavior(Component component, String channel, final IPushBehavior delegate) {
+		component.add(new TimerPushBehavior(duration, channel) {
+			private static final long serialVersionUID = 1L;
+
+			public void onEvent(String channel, Map<String, String> datas, IPushTarget target) {
+				delegate.onEvent(channel, datas, target);
+			}
+		});
+	}
+
+	public void publish(PushEvent event) {
+		publisher.publish(event);
+	}
+
+}

Property changes on: D:\users\xavier\documents\wkspace\sourceforge\wicket-stuff\wicket-contrib-push\src\main\java\org\wicketstuff\push\timer\TimerPushService.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: D:/users/xavier/documents/wkspace/sourceforge/wicket-stuff/wicket-contrib-push/src/main/java/org/wicketstuff/push/IPushService.java
===================================================================
--- D:/users/xavier/documents/wkspace/sourceforge/wicket-stuff/wicket-contrib-push/src/main/java/org/wicketstuff/push/IPushService.java	(revision 0)
+++ D:/users/xavier/documents/wkspace/sourceforge/wicket-stuff/wicket-contrib-push/src/main/java/org/wicketstuff/push/IPushService.java	(revision 0)
@@ -0,0 +1,57 @@
+package org.wicketstuff.push;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Page;
+import org.wicketstuff.push.cometd.CometdPushService;
+import org.wicketstuff.push.timer.TimerPushService;
+
+/**
+ * A service providing push facility in wicket based applications.
+ * <p>
+ * Implementation of this interface are the basis of a push implementation.
+ * You usually store one IPushService implementation in your application instance,
+ * and then delegate all your push related operations to this service, 
+ * allowing very easy switching between push implementations.
+ * <p>
+ * Here is how you usually use an IPushService implementation:
+ * <pre>
+ *  IPushService pushService = MyApplication.get().getPushService();
+ * 	// I want to send an event when i click a button
+ *  [...]
+ *  	onClick(AjaxRequestTarget target){
+ *  		pushService.publish(new PushEvent("channel"));
+ *  	}
+ *  [...]
+ *  
+ *  // All pages listening this event should add
+ *  [...]
+ *  	pushService.addPushBehavior(this, "channel", new IPushBehavior() {
+ *  		public void onEvent(String channel, Map datas, IPushTarget target){
+        		target.[...]
+        	}
+ *  	});
+ *  [...]
+ * </pre> 
+ * 
+ * @author Xavier Hanin
+ * 
+ * @see TimerPushService
+ * @see CometdPushService
+ * @see IPushTarget
+ */
+public interface IPushService extends IPushPublisher {
+	/**
+	 * Adds a behavior to the given component so that it will be notified of
+	 * [EMAIL PROTECTED] PushEvent}s.
+	 * <p>
+	 * Usually the component if a [EMAIL PROTECTED] Page}, even if it's not mandatory.
+	 * Indeed the components reacting to the event are defined in the [EMAIL PROTECTED] IPushBehavior},
+	 * by calling [EMAIL PROTECTED] IPushTarget} methods. Hence any component on the page
+	 * can serve as the host of the behavior, as soon as it is visible.
+	 * 
+	 * @param component the component to which the behavior should be added
+	 * @param channel the channel for which the behavior should be notified
+	 * @param behavior the [EMAIL PROTECTED] IPushBehavior} which should be notified of [EMAIL PROTECTED] PushEvent}s
+	 */
+	void addPushBehavior(Component component, String channel, IPushBehavior behavior);
+}

Property changes on: D:\users\xavier\documents\wkspace\sourceforge\wicket-stuff\wicket-contrib-push\src\main\java\org\wicketstuff\push\IPushService.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: D:/users/xavier/documents/wkspace/sourceforge/wicket-stuff/wicket-contrib-push/src/main/java/org/wicketstuff/push/cometd/CometdPushService.java
===================================================================
--- D:/users/xavier/documents/wkspace/sourceforge/wicket-stuff/wicket-contrib-push/src/main/java/org/wicketstuff/push/cometd/CometdPushService.java	(revision 0)
+++ D:/users/xavier/documents/wkspace/sourceforge/wicket-stuff/wicket-contrib-push/src/main/java/org/wicketstuff/push/cometd/CometdPushService.java	(revision 0)
@@ -0,0 +1,37 @@
+package org.wicketstuff.push.cometd;
+
+import java.util.Map;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.protocol.http.WebApplication;
+import org.wicketstuff.push.IPushBehavior;
+import org.wicketstuff.push.IPushPublisher;
+import org.wicketstuff.push.IPushService;
+import org.wicketstuff.push.IPushTarget;
+import org.wicketstuff.push.PushEvent;
+
+public class CometdPushService implements IPushService {
+	private IPushPublisher publisher;
+	
+	public CometdPushService(WebApplication application) {
+		publisher = new CometdPublisher(application);
+	}
+
+	public void addPushBehavior(Component component, String channel, final IPushBehavior delegate) {
+		component.add(new CometdBehavior(channel) {
+			public void onEvent(String channel, Map<String, String> datas, IPushTarget target) {
+				delegate.onEvent(channel, datas, target);
+			}
+		});
+	}
+
+	public void publish(PushEvent event) {
+		// to avoid using implementation specific events, 
+		// we set the proxy data here
+		// not sure what it is used for though, so this may not be 
+		// the proper way to do
+		event.addData("proxy", "true");
+		publisher.publish(event);
+	}
+
+}

Property changes on: D:\users\xavier\documents\wkspace\sourceforge\wicket-stuff\wicket-contrib-push\src\main\java\org\wicketstuff\push\cometd\CometdPushService.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: D:/users/xavier/documents/wkspace/sourceforge/wicket-stuff/wicket-contrib-push/pom.xml
===================================================================
--- D:/users/xavier/documents/wkspace/sourceforge/wicket-stuff/wicket-contrib-push/pom.xml	(revision 2113)
+++ D:/users/xavier/documents/wkspace/sourceforge/wicket-stuff/wicket-contrib-push/pom.xml	(working copy)
@@ -76,7 +76,7 @@
 		</dependency>
 		<dependency>
 			<groupId>org.wicketstuff</groupId>
-			<artifactId>dojo</artifactId>
+			<artifactId>wicketstuff-dojo</artifactId>
 			<version>1.3.0-SNAPSHOT</version>
 		</dependency>
 	    <dependency>
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to