OpenCoweb Application with Persistence
A guide for adding persistence to an OpenCoweb application. You might be interested in seeing our tutorial on developing a tree structured OpenCoweb application first.
1. The OpenCoweb Moderator
The OpenCoweb framework allows application programmers to write a custom Java class that lives on the server and receives remote sync events. The moderator class is responsible for honoring all remote sync events, and is responsible for sending its application state to new session clients (as opposed to other browser clients sending their application state via onStateRequest.

The cool feature is that even after all browser clients have left the session, the moderator instance will continue to persist on the server (including whatever application state it has managed). Whenever a new client open the application with the same session key, the application will be loaded from the moderator state. Every collaborative session remains persistent on the server.


2. The SessionModerator Class
Below are the extendable methods of DefaultSessionModerator (which itself extends SessionModerator). The most interesting method to override will likely be onSync. For a more complete documentation, see the SessionModerator javadocs.
import org.cometd.bayeux.Message;
import org.cometd.bayeux.server.ServerSession;
import java.util.Map;

public boolean onSync(Map<String, Object> data);

public Map<String, Object> getLateJoinState();

public boolean canClientJoinSession(ServerSession client);

public void onClientJoinSession(ServerSession client);

public void onClientLeaveSession(ServerSession client);

public boolean canClientSubscribeService(ServerSession client);

public boolean canClientMakeServiceRequest(ServerSession client, Message botMessage);

public void onServiceResponse(Message botResponse);

public void onSessionEnd();


3. Turning the Moderator On
Use the OpenCoweb configuration file to make your custom moderator as the updater for new clients. The three important configuration options are sessionModerator>, moderatorIsUpdater and operationEngine. An example file is shown for the persistent CoTree.
{
  // Full java classname of moderator class
  "sessionModerator"   : "org.coweb.CotreeModerator",
  // The moderator instance will send the full application state to new clients.
  "moderatorIsUpdater" : true,
  // Use an OperationEngine on the server (moderatorIsUpdater automatically implies operationEngine anyway)
  "operationEngine"    : true,
  // An array of bot configs (optional)
  "bots": []
}


4. Adding a Moderator to CoTree
Most of the above information should be enough to motivate you to write the custom moderator; take a look at the source, and the comments will describe the important details.