Terracotta DSO

Chatter Sample Application

About

Chatter is a simple chat application that allows multiple users connected to the same Terracotta Server to communicate via text messages. After pressing <ENTER>, the text displays on all client nodes.

Chatter is implemented by sharing a very simple model across a cluster. In this case, the model is the ChatManager which keeps a record of all connected chat users in a Map. Writing to the ChatManager is synchronized across the cluster to ensure data integrity.

One relevant implementation detail is that the listeners to the ChatManager are declared as transient in the source code and the tc-config.xml file declares that the ChatManager class honors the transient modifier. This makes that the listeners registered to the ChatManager are not clustered, even if the entire object itself is.

The ChatManager::sendNewUserEvent() and ChatManager::sendNewMessageEvent methods are declared as distributed. This means that whenever this method is invoked from any one client, it also fires in the context of all the other clients in the cluster.

The program also makes use of terracotta cluster membership events via JMX notifications. By responding to these JMX events, the program can detect the coming and going of other nodes in the cluster, as well as when the terracotta server is unavailable

Build Instructions

This sample application ships built ready to run.  If you modify the application code, use the provided build.xml file to re-build the application with Apache Ant (ant build).

Run Instructions

The command-line steps below for executing scripts on Windows can be replaced by double-clicking the script instead.

This sample application requires a version 1.5+ java runtime
  1. Start a Terracotta server from the samples directory.

    Unix: ./start-demo-server.sh
    Windows: start-demo-server.bat
  2. Start multiple copies of the application from the samples/pojo/chatter directory.

    Unix: ./run.sh &
    ./run.sh &

    Windows: run.bat
    run.bat


  3. View application.
    In each window type text and press <ENTER> to see the text replicated across all nodes in the cluster.

Source Code

Browse configuration file and source code: source.html