com.smartgwt.client.rpc

## Class Messaging

- java.lang.Object
- - com.smartgwt.client.rpc.Messaging

-     public class Messaging
      extends java.lang.Object

  The Messaging class provides APIs to make use of SmartGWT Real-Time Messaging module, an optional module available with SmartGWT Power or Enterprise Edition which allows browser based web applications to publish and subscribe to HTTP Messaging channels, allowing the application to receive (and send) messages delivered via server push for "real-time" updates from the server without polling.

  To use this class, you will need to inherit `RealtimeMessaging` or `RealtimeMessagingNoScript` from the `messaging.jar` (required for client side functionality only), and include the `isomorphic_messaging` and `isomorphic_js_parser` jar files for deployment on the server.

  See the Messaging Quick Reference PDF file for more information on the optional Messaging module.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Messaging()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `connected()` Returns true if we are currently connected to any channels.
    `static void` | `disconnect()` disconnect from all channels
    `static int` | `getConnectTimeout()`
    `static java.lang.String` | `getMessagingURL()` Get the URL of the messaging servlet.
    `static java.lang.String[]` | `getSubscribedChannels()` Returns list of channels that we're currently subscribed to.
    `static boolean` | `messagingLoaded()` Static method indicating whether the optional RealtimeMessaging module is loaded for the page.
    `static void` | `send(java.lang.String[] channels, java.lang.Object data, RPCCallback callback)` Actually send data to a list of channels.
    `static void` | `send(java.lang.String channel, java.lang.Object data, RPCCallback callback)` Actually send data to a channel.
    `static void` | `setConnectionDownCallback(MessagingConnectionDownCallback callback)` Called when the messaging connection allowing the server to send messages to the client is disconnected.
    `static void` | `setConnectionUpCallback(MessagingConnectionUpCallback callback)` Called when the messaging connection allowing the server to send messages to the client is established - whether that's the result of an initial connect() or a re-establishment after it is severed.
    `static void` | `setConnectTimeout(int timeout)` Specifies how long we wait for the handshake to the server to complete, before trying again.
    `static void` | `setMessagingURL(java.lang.String URL)` Set the url of the messaging servlet.
    `static void` | `subscribe(java.lang.String channel, MessagingCallback callback)` Call to subscribe to channel.
    `static void` | `subscribe(java.lang.String channel, MessagingCallback callback, java.lang.String selector)` Call to subscribe to channel.
    `static void` | `unsubscribe(java.lang.String channel)` call to unsubscribe from channel(s).

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Messaging

          public Messaging()

  - ### Method Detail

    - #### setMessagingURL

          public static void setMessagingURL(java.lang.String URL)

      Set the url of the messaging servlet.
      Parameters:
        `URL` - May be prefixed with [ISOMORPHIC] to use the isomorphicDir

    - #### getMessagingURL

          public static java.lang.String getMessagingURL()

      Get the URL of the messaging servlet.
      Returns:

    - #### setConnectTimeout

          public static void setConnectTimeout(int timeout)

      Specifies how long we wait for the handshake to the server to complete, before trying again.
      Parameters:
        `timeout` - in ms

    - #### getConnectTimeout

          public static int getConnectTimeout()

    - #### send

          public static void send(java.lang.String[] channels,
                                  java.lang.Object data,
                                  RPCCallback callback)

      Actually send data to a list of channels. Each browser subscribed to the specified channel will be sent this data from the server in realtime.

      Note that the data is of type Object - typically this will be just a String. To send a complex data type such as a Map to the server, use the JSOHelper utility to get a JavaScript equivalent and pass in the JavaScriptObject.

      Parameters:
        `channels` -
        `data` -
        `callback` -

    - #### send

          public static void send(java.lang.String channel,
                                  java.lang.Object data,
                                  RPCCallback callback)

      Actually send data to a channel. Each browser subscribed to the specified channel will be sent this data from the server in realtime.

      Note that the data is of type Object - typically this will be just a String. To send a complex data type such as a Map to the server, use the JSOHelper utility to get a JavaScript equivalent and pass in the JavaScriptObject.

      Parameters:
        `channels` -
        `data` -
        `callback` -

    - #### getSubscribedChannels

          public static java.lang.String[] getSubscribedChannels()

      Returns list of channels that we're currently subscribed to.
      Returns:

    - #### subscribe

          public static void subscribe(java.lang.String channel,
                                       MessagingCallback callback)

      Call to subscribe to channel. This will cause a reconnect to the server - for this reason we defer the actuall reconnect to allow for multiple subscribe() calls in sequence.
      Parameters:
        `channel` - name of the channel we are subscribing to.
        `callback` - this will execute whenever data is received from the server on this messaging channel.

    - #### subscribe

          public static void subscribe(java.lang.String channel,
                                       MessagingCallback callback,
                                       java.lang.String selector)

      Call to subscribe to channel. This will cause a reconnect to the server - for this reason we defer the actuall reconnect to allow for multiple subscribe() calls in sequence.
      Parameters:
        `channel` - name of the channel we are subscribing to.
        `callback` - this will execute whenever data is received from the server on this messaging channel.
        `selector` - JMS selector used with Queues to filter the messages that arrive to the channel (optional).

    - #### unsubscribe

          public static void unsubscribe(java.lang.String channel)

      call to unsubscribe from channel(s). This will cause a reconnect to the server - for this reason we defer the actual reconnect to allow for multiple unsubscribeToChannel() calls in sequence.
      Parameters:
        `channel` -

    - #### connected

          public static boolean connected()

      Returns true if we are currently connected to any channels.
      Returns:

    - #### disconnect

          public static void disconnect()

      disconnect from all channels

    - #### messagingLoaded

          public static boolean messagingLoaded()

      Static method indicating whether the optional RealtimeMessaging module is loaded for the page. The Messaging class cannot function without this module being present.
      Returns:
        true if the RealtimeMessaging module is present

    - #### setConnectionDownCallback

          public static void setConnectionDownCallback(MessagingConnectionDownCallback callback)

      Called when the messaging connection allowing the server to send messages to the client is disconnected. This can occur either when you explicitly disconnect the connection or if a keepalive packet from the server does not arrive on time. This latter is defined as the `keepaliveInterval` plus the `keepaliveReestablishDelay`. With default settings, a maximum of 4 seconds will elapse between the connection actually going down and you receiving this callback.
      Parameters:
        `callback` - MessagingConnectionDownCallback the callback to set.

    - #### setConnectionUpCallback

          public static void setConnectionUpCallback(MessagingConnectionUpCallback callback)

      Called when the messaging connection allowing the server to send messages to the client is established - whether that's the result of an initial connect() or a re-establishment after it is severed.
      Parameters:
        `callback` - MessagingConnectionUpCallback the callback to set.