|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.streamhub.client.StreamHubGWTAdapter
public class StreamHubGWTAdapter
The main class for connecting to a StreamHub Push Server and subscribing to topics.
Example of the adapter in use:
StreamHubGWTAdapter hub = new StreamHubGWTAdapter();
hub.connect("http://push.example.com/");
hub.subscribe("GOOG", updateListener);
hub.unsubscribe("GOOG");
hub.disconnect();
The source code for the adapter and examples is available at: GWT Comet StreamHub on Google Code.
| Constructor Summary | |
|---|---|
StreamHubGWTAdapter()
Creates a new un-connected StreamHub GWT adapter |
|
| Method Summary | |
|---|---|
void |
connect(FailoverParameters failoverParameters)
Connects to the server with advanced failover configuration. |
void |
connect(String url)
Connects to the server |
void |
disconnect()
Disconnects from the StreamHub server. |
static void |
onUpdate(String topic,
com.google.gwt.core.client.JavaScriptObject update)
This method is called internally everytime an update is received to a subscribed topic. |
void |
publish(String topic,
com.google.gwt.json.client.JSONObject jsonObject)
Publishes data on a particular topic. |
void |
subscribe(String[] topics,
StreamHubGWTUpdateListener listener)
Subscribes to an array of topics in a single request to the StreamHub server. |
void |
subscribe(String topic,
StreamHubGWTUpdateListener listener)
Subscribes to a particular topic. |
void |
unsubscribe(String topic)
Unsubscribes from a particular topic |
void |
unsubscribe(String[] topics)
Unsubscribes from an array of topics |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public StreamHubGWTAdapter()
| Method Detail |
|---|
public static void onUpdate(String topic,
com.google.gwt.core.client.JavaScriptObject update)
StreamHubGWTUpdateListener
that has been added via a call to subscribe(String, StreamHubGWTUpdateListener).
It is useful for testing without connecting to a real server.
topic - the topic on which the update was receivedupdate - the fields received in the updatepublic void connect(String url)
url - the URL of the server to connect to e.g. http://localhost:7979/.
The trailing slash is important.public void connect(FailoverParameters failoverParameters)
failoverParameters - the failover configuration parametersFailoverParameters
public void subscribe(String topic,
StreamHubGWTUpdateListener listener)
StreamHubGWTUpdateListener will
be notified of any updates on this topic.
topic - the topic to subscribe tolistener - the listener to receive updates on this topicsubscribe(String[], StreamHubGWTUpdateListener),
StreamHubGWTUpdateListener
public void subscribe(String[] topics,
StreamHubGWTUpdateListener listener)
subscribe(String, StreamHubGWTUpdateListener)
where multiple topics are used as it reduces the number of HTTP requests involved. The StreamHubGWTUpdateListener will
be notified of updates on any of the topics.
topics - the topics to subscribe tolistener - the listener to receive updates on ay of the topicssubscribe(String, StreamHubGWTUpdateListener),
StreamHubGWTUpdateListenerpublic void unsubscribe(String topic)
topic - the topic to unsubscribe frompublic void unsubscribe(String[] topics)
topics - the topics to unsubscribe from
public void publish(String topic,
com.google.gwt.json.client.JSONObject jsonObject)
jsonObject will be
sent back to the server. The server may choose to publish this data to all
subscribed clients or instead return a custom response to this client.
Example of publishing data:
// Connect
StreamHubGWTAdapter hub = new StreamHubGWTAdapter();
hub.connect("http://push.example.com/");
// Create some data to publish
JSONObject payload = new JSONObject();
payload.put("Name", new JSONString("GWT-Fan"));
payload.put("Message", new JSONString("GWT is cool!"));
// Publish the data
hub.publish("ChatRoom", payload);
topic - the topic to publish the data onjsonObject - the data to publishpublic void disconnect()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||