View Source

{note}This tutorial is currently under construction. The contents will prove useful to those that want to understand Cloud Push more thoroughly, but deployment configuration and example are incomplete at this time.{note}
h1. Overview

h2. User Notification

User Notification is the first aspect of cloud push that you must understand. When a user is actively working with an application on a mobile device, the user interface (UI) of that application can continually update information displayed to the user as the state of the application changes. For instances, an email application can update the number of emails in the inbox as new emails arrive. When the user is not actively using an application, that application can not rely on its UI to convey new information to the user, because the UI is not visible at the moment. Mobile devices provide a number of ways to alert the user of a state change occurring in an inactive application. A status bar can display an alerting icon, or a sound or vibration can occur. For instance, an email application can display an icon indicating that new mail has arrived since the user last viewed her inbox.

h2. Cloud Push

When a user notification is the result of some state change coming from outside the device over a network connection, we refer to that as Cloud Push. The dominant mobile platforms all provide Cloud Push mechanisms that can be incorporated into an application. Specifically, the mechanisms are:

* [Apple Push Notification Service|http://support.apple.com/kb/HT3576]
* [Android Cloud To Device Messaging|http://code.google.com/android/c2dm/index.html(C2DM)]
* [Blackberry Push Service|http://us.blackberry.com/developers/platform/pushapi.jsp]

These mechanisms can be integrated directly with a native mobile application to achieve appropriate user notifications triggered from the network cloud.

Beyond these proprietary push mechanisms, other common network protocols can be considered for cloud push notification, such as:

* Email
* SMS text messaging

These mechanisms have the advantage of ubiquitous support across mobile platforms, relying on the device's built in support for these protocols, but won't necessarily integrate tightly with the native application.

h2. Web Applications

The concept of push in web applications was completely foreign until the advent of Ajax, and more specifically [Ajax Push|http://www.icefaces.org/main/ajax-java/ajaxpush.iface]. Ajax Push makes pushing asynchronous state changes to a web application possible, so an active web application can behave much like an active native application, pushing state changes to the UI in a spontaneous fashion as the state of the application changes.

When a web application becomes inactive, not only is the UI unavailable, the network connection back to the server is also unavailable, so Ajax Push connections cannot be maintained. In order to support cloud push to web applications, ICEmobile-Faces augments Ajax Push with a priority push mechanism that utilizes a cloud push connector to a native [Device Container|ICEmoble Containers]. Even when the web application is idle, Ajax Push can send priority notifications over a cloud push connector to the device, and alert the user with standard user notification mechanisms on the device.

h1. Ajax Push

We now review the Ajax Push mechanism with respect to active and inactive web applications.

h2. Push to Active Applications

When the web application is active, the Ajax Push mechanism relies on HTTP and the notification protocol in [ICEpush|http://www.icepush.org], which uses reverse polling over a blocking connection to facilitate asynchronous page updates. The basic process is illustrated below.
!ICEfaces-2.0-Ajax-Push.png|align=center!

# Some state change in the application triggers an Ajax Push event.
# ICEpush notification is delivered to the browser client over a dedicated ICEpush connection.
# Notification at client browser causes a JSF Ajax request with an empty execute phase.
# Render phase captures new state of client, and Direct-to-DOM Rendering delivers incremental page updates to client.

h2. Push to Inactive Applications

Once an ICEfaces page loads in the ICEmobile device container, the container notifies the ICEpush bridge, describing the cloud push connector type/credentials associated with the client device (if there is one). When the web application goes inactive on the device, the ICEpush bridge connection is parked on the server for that client's session. While the connection remains parked, any priority push requests that occur for that client will be sent via the specified cloud connector, to be received at the device container (in the case of a platform-specific connector), or by the email client (in the case of an email connector). In the case of the device container, the cloud push will result in a user notification carrying a specific subject/message. The process is illustrated below.

!icemobile-cloud-push.png|align=center!

# Cloud Push park credentials established.
# Inactive state detected and client session parked.
# Some state change in the application triggers a priority Ajax Push event.
# ICEpush notification is delivered to the device using the specified cloud connector.
# Notification received at device, and user notification is given.

At some time later the user acknowledges the notification by reactivating the application, causing the ICEpush bridge to reestablish itself, and a page update to occur reflecting the current state of the application.

h1. Programming Model

While there is some relatively complex infrastructure in ICEmobile-Faces to handle cloud push, the programming model is simple, and well-aligned with the standard ICEfaces 2 [Ajax Push APIs|http://wiki.icefaces.org/display/ICE/Ajax+Push+-+APIs].

A standard Ajax Push notification is generated using:

{code}
import org.icefaces.application.PushRenderer;
...
PushRenderer.render("myGroup");
{code}
A priority push, with option to do a cloud push is generated using:

{code}
import org.icefaces.application.PushRenderer;
import org.icefaces.application.PushMessage;
...
PushMessage myMessage = new PushMessage("myMsgSubject", "myMsgBody");
PushRenderer.render("myGroup", myMessage);
{code}
From the developers perspective, there are no additional considerations beyond supplying the additional PushMessage. Selection of the normal or cloud push transport, as well as selection of the cloud push connector type, is transparent to the developer and handled by the ICEpush core.

h1. Deployment Infrastructure

Specific deployment infrastructure is required on both the server and client for cloud push to operate correctly.
{note}Device-specific cloud push features require ICEmobile-EE capabilities, and are not discussed here. Email is the only cloud push connector available in ICEmobile Open Source, and is the focus of the remainder of this tutorial. {note}

h2. Server Requirements

Deployments that support cloud push must include proper configuration for each cloud push mechanism to be supported.

h3. Email Connector

The email connector requires a SMTP server account for sending the email messages. Your web application can be configured to login into the server with context parameters in the web.xml. The following attributes are available to configure the email client.
||Attribute||Description||Value||Default||
|smtp.host|host name of SMTP server|any valid host name|none|
|smtp.from|email address of sender|any valid email address|none|
|smtp.port|port number for SMTP server|any valid port|25|
|smtp.user|user name for SMTP server access|any valid user name|none|
|smtp.password|password for user|user password|none|
|smtp.security|type of security for SMTP connection|NONE SSL TLS|
|smtp.verify-server-certificate|certificate verification|true false|true|

{code}
<context-param>
<param-name>smtp.host</param-name>
<param-value>yourSMTPServer</param-value>
</context-param>
<context-param>
<param-name>smtp.from</param-name>
<param-value>yourWebapplicationEmail</param-value>
</context-param>
<context-param>
<param-name>smtp.port</param-name><!--default is 25-->
<param-value>yourSMTPServerPort</param-value>
</context-param>
<context-param>
<param-name>smtp.user</param-name>
<param-value>yourSMTPUsername</param-value>
</context-param>
<context-param>
<param-name>smtp.password</param-name>
<param-value>yourSMTPPassword</param-value>
</context-param>
{code}

h2. Device Requirements

h3. Email

If the email connector is used, there must be an email client configured on the device to match the email address associated with the client. This email address can either be configured as part of the web application itself,
or if a device container is used, it can be configured from the container preferences.
{note}Need details on how to do this in the web page.{note}
h3. Android

For an Android device to participate in cloud push over C2DM, the device must have a valid Google account. Cloud push preferences are established using the device container options page as illustrated below:
!device.png|align=center!
C2DM is selected through a checkbox, and email notification is selected by providing an email address. If both are configured, C2DM takes priority over email.

h3. iOS

An iOS device will automatically receive notifications unless explicitly denied by the user in notification setup. To configure email notification in place of APNS, provide a notification email address in the preferences screen as seen below:
!iphone2.png|align=center!

h3. Blackberry
{note}Need details{note}
h1. Example

The example applications is based on the Notification example found in mobileshowcase.
{note}Still to come...{note}