For-fun Project: NSF StateManager

Tue May 20 17:25:51 EDT 2014

Earlier this year, I created a StateManager for XPages using Couchbase as a back end. Mostly, this was just to give myself an excuse to mess around with XPages internals and Couchbase. But even still, it had an interesting characteristic: by storing the state of an XPage between requests in a location available to multiple servers, the XPages became cluster-friendly - you could load an XPage on one server and make later requests to another (though it would take further work to handle other scopes).

I was prompted today by a discussion on the possibilities of this sort of thing to go back to that code and adapt it to storing the data in Domino. The initial work was pretty straightforward: using the baked-in Database#getDocumentByKey and MIMEBean capabilities of the OpenNTF Domino API, the same key-value concepts I used for the Couchbase version transferred neatly. At that point, I had the same cool cluster/failover-friendliness as before, but now using NSF for storage.

But then Nathan egged me on further: he pointed out that there's no reason to stop at just storing the last state; I could store every revision. Suddenly, a world of possibilities are open: an audit trail of page state, the ability to view this trail from externally (tied to context information like DB path and username), and the ability for the user to step back through the tree. I set to implementing that last one immediately:

(Download)

If you'll forgive the off-by-one problem in the history display and the sparse layout, you can see it in action: the user is able to revert the view to a previous state, with the entire viewScope coming along for the ride. Additionally, I realized I could store this traversal history as a tree (I told you they come in handy) to visualize the act of a user stepping back in state and creating a new branch from there:

Domino State Viewer

Currently, this is largely of nerdy-interest concern, but there are a lot of ways this could be built up into a real useful tool. Users could have a built-in "undo" tool (assuming you're undoing actions without external side effects), an admin could see the specific actions taken and buttons clicked by a user using a page, the app could peer into the state of all users using a given page to present a collaborative UI, and so forth.

I created a "Miscellany" project on GitHub intended to house pie-in-the-sky one-offs/test projects like this, and so the curious can find the code there:

https://github.com/jesse-gallagher/Miscellany

New Comment