There is a GWT Comet module for StreamHub:
http://code.google.com/p/gwt-comet-streamhub/
StreamHub is a free comet server community. Here is an example of this in action here .
You will need to download the Comet StreamHub server and create a new SubscriptionListener, use the StockDemo example as a starting point, and then create a new JsonPayload for streaming data:
Payload payload = new JsonPayload("AAPL"); payload.addField("bid", "88.84"); payload.addField("ask", "88.86"); server.publish("AAPL", payload); ...
Download the JAR from the Google code site, add it to your GWT class path and add include to your GWT module:
<inherits name="com.google.gwt.json.JSON" /> <inherits name="com.streamhub.StreamHubGWTAdapter" />
Connect and subscribe to your GWT code:
StreamHubGWTAdapter streamhub = new StreamHubGWTAdapter(); streamhub.connect("http://localhost:7979/"); StreamHubGWTUpdateListener listener = new StockListener(); streamhub.subscribe("AAPL", listener); streamhub.subscribe("IBM", listener); streamhub.subscribe("GOOG", listener); ...
Then process the updates as you like in the update listener (also in the GWT code):
public class StockListener implements StreamHubGWTUpdateListener { public void onUpdate(String topic, JSONObject update) { String bid = ((JSONString)update.get("bid")).stringValue(); String ask = ((JSONString)update.get("ask")).stringValue(); String symbol = topic; ... } }
Remember to include streamhub-min.js in the main HTML page of GWT projects.
Corehpf
source share