{info:title=Useful Information}
This page has been generated by [maven-confluence-plugin|http://code.google.com/p/maven-confluence-plugin/]
{info}
{toc}
----
{children}
h1. Description
{panel}
The Channel API creates a persistent connection between your application and Google servers, allowing your application to send messages to JavaScript clients in real time without the use of polling. This is useful for applications that are designed to update the user about new information immediately or where user input is immediately broadcast to other users. Some examples include collaborative applications, multi-player games, and chat rooms. In general, using Channel API is a better choice than polling in situations where updates can't be predicted or scripted, such as when relaying information between human users or from events not generated systematically.
{panel}
h2. Introduction
First of all, you should read and be familiar with how to use the App Engine Channel API [java|http://code.google.com/appengine/docs/java/channel/overview.html] on the server-side.
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. How To use
h3. Declare dependency (available from Artifactory)
{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}
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
h2. Project Information
||Field||Value||
|Name|GWT GAE channel API|
|Description|GWT bindings for the App Engine Channel API client|
|Homepage|[http://code.google.com/p/gwt-gae-channel/|http://code.google.com/p/gwt-gae-channel/]
|
h2. Project Organization
||Field||Value||
|Name|Google, Inc.|
|URL|[http://www.google.com|http://www.google.com]
|
h2. Build Information
||Field||Value||
|GroupId|gwt-gae-channel|
|ArtifactId|gwt-gae-channel|
|Version|1.0-20010325|
|Type|jar|
----
h1. Issue Tracking
----
h1. Source Repository
h2. 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
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
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
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}
To commit changes to the repository, execute the following command to commit your changes (svn will prompt you for your password)
{noFormat}
$ svn commit --username your-username -m "A message"{noFormat}
h2. 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
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:
{noFormat}
[global]
http-proxy-host = your.proxy.name
http-proxy-port = 3128
{noFormat}
----
h1. Project Dependencies
h2. 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. 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
h2. Dependency Tree
\\
* ** [com.google.gwt:gwt-user:jar|#com.google.gwt_gwt-user_jar]
h2. Dependency File Details
*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/]
*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/]
This page has been generated by [maven-confluence-plugin|http://code.google.com/p/maven-confluence-plugin/]
{info}
{toc}
----
{children}
h1. Description
{panel}
The Channel API creates a persistent connection between your application and Google servers, allowing your application to send messages to JavaScript clients in real time without the use of polling. This is useful for applications that are designed to update the user about new information immediately or where user input is immediately broadcast to other users. Some examples include collaborative applications, multi-player games, and chat rooms. In general, using Channel API is a better choice than polling in situations where updates can't be predicted or scripted, such as when relaying information between human users or from events not generated systematically.
{panel}
h2. Introduction
First of all, you should read and be familiar with how to use the App Engine Channel API [java|http://code.google.com/appengine/docs/java/channel/overview.html] on the server-side.
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. How To use
h3. Declare dependency (available from Artifactory)
{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}
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
h2. Project Information
||Field||Value||
|Name|GWT GAE channel API|
|Description|GWT bindings for the App Engine Channel API client|
|Homepage|[http://code.google.com/p/gwt-gae-channel/|http://code.google.com/p/gwt-gae-channel/]
|
h2. Project Organization
||Field||Value||
|Name|Google, Inc.|
|URL|[http://www.google.com|http://www.google.com]
|
h2. Build Information
||Field||Value||
|GroupId|gwt-gae-channel|
|ArtifactId|gwt-gae-channel|
|Version|1.0-20010325|
|Type|jar|
----
h1. Issue Tracking
----
h1. Source Repository
h2. 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
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
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
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}
To commit changes to the repository, execute the following command to commit your changes (svn will prompt you for your password)
{noFormat}
$ svn commit --username your-username -m "A message"{noFormat}
h2. 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
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:
{noFormat}
[global]
http-proxy-host = your.proxy.name
http-proxy-port = 3128
{noFormat}
----
h1. Project Dependencies
h2. 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. 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
h2. Dependency Tree
\\
* ** [com.google.gwt:gwt-user:jar|#com.google.gwt_gwt-user_jar]
h2. Dependency File Details
*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/]
*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/]