Table of Contents Previous Section

Example: FaultTolerantApplication

The following example, FaultTolerantApplication, shows one approach to implementing a custom storage solution. FaultTolerantApplication is a subclass of WOWebScriptApplication that archives state in the file system. Its name derives from the fact that because it archives state in the file system, no more than the last interaction in a session can ever be lost.

FaultTolerantApplication includes the following methods:

This method invokes [super stateID], which stores the state in the application and returns a new stateID. The method then invokes the WOApplication method stateDataForID:, which takes the state in the application, archives it into an NSData object, and returns the NSData object. Finally, the method stores the NSData object in the file system and removes the state from the server.
This method retrieves the NSData object that the stateID method stored in the file system. It then invokes [super restoreToStateWithID:aStateID data:stateData], which restores the session's state from the NSData object.
This method constructs a storeID out of the first two fields of the stateID, and returns it. This method is invoked from stateFilePathForStateID:, which uses the returned storeID to construct a path for the file used to store the state.
Given a stateID, this method returns a file path based on the stateID. This method is invoked by both stateID and restoreToStateWithID:, which use it respectively to create and find the file holding the application's state.

Fault Tolerant Application .h and .m Files

Table of Contents Next Section