gwt-gae-channel-1.0-20010325

compared with
Current by Bartolomeo Sorrentino
on Oct 11, 2011 17:52.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (34)

View page history
This library simply wraps the client-side JavaScript with GWT bindings to make it accessible in a GWT application, and it doesn't manage telling your client the client ID it should use. That part's up to you, and is described in the documentation for the Channel API.
h2. A Short Sample
The following is a simple example of how to open a channel and receive updates when the channel receives a message.
h2. How To use
 
{code:java}
h3. Declare dependency (available from Artifactory)
 
ChannelFactory.createChannel(token, new ChannelCreatedCallback() {
@Override
public void onChannelCreated(Channel channel) {
channel.open(new SocketListener() {
@Override
public void onOpen() {
Window.alert("Channel opened!");
}
@Override
public void onMessage(String message) {
Window.alert("Received: " + message);
}
@Override
public void onError(SocketError error) {
Window.alert("Error: " + error.getDescription());
}
@Override
public void onClose() {
Window.alert("Channel closed!");
}
});
{code:xml}
<!--
===========================================
CHANNEL API
===========================================
-->
<dependency>
<groupId>gwt-gae-channel</groupId>
<artifactId>gwt-gae-channel</artifactId>
<version>1.0-20010325</version>
</dependency>

{code}


h3. Inherit gwt module

In your GWT descriptor you have to include the following *inherit* declaration

{code:xml|title=GWT module}
<inherits name="com.google.gwt.appengine.channel.Channel"/>
{code}

h3. Create a service that generate a unique token to be associated with the event channel

Each channel is identified by an unique token that should be generated by application itself. In order to do this you have to implement a simple service (e.g. servlet) that accomplish this task

h3. Initialize Event Listener (client side)

{code:java|title=initialize service from client}

private void initEventsManagement() {

// GET CUSTOM TOKEN FROM SERVLET
RequestBuilder request = new RequestBuilder(RequestBuilder.POST, GWT.getModuleBaseURL() + "/service/events/token");

try {
request.sendRequest("",new RequestCallback() {

@Override
public void onResponseReceived(Request req, Response res) {
GWT.log("onResponseReceived " + res.getText() );

// REGISTER CHANNEL FOR GIVEN TOKEN (see below)
registerChannel(res.getText());

}

@Override
public void onError(Request req, Throwable t) {
GWT.log("onError ", t );
}
});
} catch (RequestException e) {
e.printStackTrace();
}
}
});
private void registerChannel( String token ) {
 
GWT.log("Event Module load!");

ChannelFactory.createChannel(token, new ChannelCreatedCallback() {
@Override
public void onChannelCreated(Channel channel) {
channel.open(new SocketListener() {
@Override
public void onOpen() {
GWT.log("Event Channel opened!");
}
@Override
public void onMessage(String message) {
GWT.log("Event Received: " + message);
}
@Override
public void onError(SocketError error) {
GWT.log("Event Channel creation error: " + error.getDescription());
}
@Override
public void onClose() {
GWT.log("Channel closed!");
}
});
}
});
}
{code}
Whenever the server sends a message to your client ID, the onMessage() method will get called with the message that was sent.
h3. Send event (server side)
 
The following is a simple example of how to open a channel and send event to the client listeners when receives a message.
 
{code:java|title=send event from server}

public void sendEvent(String event) {
ChannelService channelService = ChannelServiceFactory.getChannelService();
channelService.sendMessage(new ChannelMessage( token /* the same token generated by application, see above */, event));

}

{code}


h1. Project Summary
{anchor:Project_Summary} h2. Project Information
{anchor:Project_Information}
||Field||Value||
|Name|GWT GAE channel API|
|
h2. Project Organization
{anchor:Project_Organization}
||Field||Value||
|Name|Google, Inc.|
|
h2. Build Information
{anchor:Build_Information}
||Field||Value||
|GroupId|gwt-gae-channel|

h1. Source Repository
{anchor:Source_Repository} h2. Overview
{anchor:Overview} This project uses [Subversion|http://subversion.apache.org/]
to manage its source code. Instructions on Subversion use can be found at [http://svnbook.red-bean.com/|http://svnbook.red-bean.com/]
.\\
h2. Web Access
{anchor:Web_Access} The following is a link to the online source repository.
{noFormat}
[http://code.google.com/p/gwt-gae-channel/source/browse|http://code.google.com/p/gwt-gae-channel/source/browse]
{noFormat}
h2. Anonymous access
{anchor:Anonymous_access} The source can be checked out anonymously from SVN with this command:
{noFormat}
$ svn checkout http://gwt-gae-channel.googlecode.com/svn/trunk gwt-gae-channel{noFormat}
h2. Developer access
{anchor:Developer_access} Everyone can access the Subversion repository via HTTP, but Committers must checkout the Subversion repository via HTTPS.
{noFormat}
$ svn checkout https://gwt-gae-channel.googlecode.com/svn/trunk gwt-gae-channel{noFormat}
$ svn commit --username your-username -m "A message"{noFormat}
h2. Access from behind a firewall
{anchor:Access_from_behind_a_firewall} For those users who are stuck behind a corporate firewall which is blocking HTTP access to the Subversion repository, you can try to access it via the developer connection:
{noFormat}
$ svn checkout https://gwt-gae-channel.googlecode.com/svn/trunk gwt-gae-channel{noFormat}
h2. Access through a proxy
{anchor:Access_through_a_proxy} The Subversion client can go through a proxy, if you configure it to do so. First, edit your "servers" configuration file to indicate which proxy to use. The file's location depends on your operating system. On Linux or Unix it is located in the directory "~/.subversion". On Windows it is in "%APPDATA%\Subversion". (Try "echo %APPDATA%", note this is a hidden directory.)
There are comments in the file explaining what to do. If you don't have that file, get the latest Subversion client and run any command; this will cause the configuration directory and template files to be created.
Example: Edit the 'servers' file and add something like:

h1. Project Dependencies
{anchor:Project_Dependencies} h2. provided
{anchor:provided} The following is a list of provided dependencies for this project. These dependencies are required to compile the application, but should be provided by default when using the library:

||GroupId||ArtifactId||Version||Classifier||Type||Optional||
|com.google.gwt|gwt-user|2.1.0|-|jar|-|
h1. report.transitivedependencies.title
{anchor:report.transitivedependencies.title} report.transitivedependencies.intro
h1. Project Transitive Dependencies
The following is a list of transitive dependencies for this project. Transitive dependencies are the dependencies of the project dependencies.
h1. Project Dependency Graph
{anchor:Project_Dependency_Graph} h2. Dependency Tree
{anchor:Dependency_Tree} \\
* ** [com.google.gwt:gwt-user:jar|#com.google.gwt_gwt-user_jar]


h2. report.dependencies.graph.tables.title
h2. Dependency File Details
{anchor:report.dependencies.graph.tables.title} {anchor:gwt-gae-channel_gwt-gae-channel_jar} *GWT GAE channel API*
GWT bindings for the App Engine Channel API client
[http://code.google.com/p/gwt-gae-channel/|http://code.google.com/p/gwt-gae-channel/]
{anchor:com.google.gwt_gwt-user_jar} *gwt-user*
Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
[http://code.google.com/webtoolkit/gwt-user/|http://code.google.com/webtoolkit/gwt-user/]