Persevere Adds Comet Support

by Kris ZypMay 12th, 2008

The latest release of the Persevere Server (0.9.5) now includes Comet support. The Persevere Server is a web accessible database and service side JavaScript server that exposes persistent data storage as RESTful HTTP/JSON web services, which can be queried through JSONPath, and supports distributed method calls through JSON-RPC.

Various underlying sources such as database tables, XML files, web services, and object repositories can plug into Persevere, and such persisted graphs can even span domains. With Comet support, it is now possible for clients to subscribe to persisted objects/resources and be notified of changes through a Comet connection. This means that a client can not only directly access persisted data from the server, it can maintain a live synchronization with the persisted data.

Persevere uses a new HTTP Channels transport protocol I have been developing (based on discussions) which can be used with Bayeux. Persevere supports Bayeux service negotiation, and eventually full Bayeux support through integration with Jetty’s Cometd implementation.

Demonstration

View a demo of a live data grid.

Data Grid Demo

This grid can be opened from multiple browsers/locations. When a change is made and saved by one user, that change will notify other clients that have the grid open, and their grids will automatically be updated.

This demo is using a forthcoming Dojo implementation of HTTP Channels connecting to the Persevere server (running on Jetty). HTTP Channels integrates with the new Dojo REST store, and notifications from the server automatically trigger data store notifications and visual grid updates without requiring any extra coding. I will discuss and demonstrate this new experimental Dojo module in a subsequent article, but for now it is included as a demonstration with the Persevere download.

Interacting with Persevere is straightforward. Normally if you want to retrieve a persisted object/resource, you can simply do a request to the corresponding URL; you could request:

GET /Customer/2

And Persevere would respond with a JSON representation of that object. Now with Comet/subscription support, you can include an extra header X-Subscribe to indicate that you not only want the object, but you want to be notified of any changes to that object:

GET /Customer/2
X-Subscribe: *

Persevere will still respond with a JSON representation of the object, but you can also maintain a Comet connection (with a separate request) that will receive notifications of changes to any of these subscribed objects. If someone else makes a modification, for example:

PUT /Customer/2
 
{"name":"Changed Name",...}

This PUT will provide new values for that object, and a notification will be triggered and sent to the subscriber(s). The notification will include the path/id for the object that was modified (/Customer/2), the new data that replaced the object, and the event that triggered the change (PUT).

With Persevere, a Comet connection is made by connecting to /channels. When an monitored object is modified, Persevere will send a message/response on the Comet connection like:

HTTP/1.1 200 OK
X-Event: PUT
Content-Location: /Customer/2
 
{"name":"Changed Name",...}

Please see the coming HTTP Channels proposal for more detailed information about the format of messages and how connections are correlated. Persevere also supports deterministic message ordering as defined in the HTTP Channels proposal as well.

Users can also send POST requests to add new items to a table of objects, or send DELETE requests to delete objects. These modifications will also result in notifications as well. In addition, you can subscribe to a query, in which case you are implicitly subscribing to all the objects returned in the query. The grid example uses this technique. A single query request (with the subscription header) is made for all the customers in a list, in order to populate the grid. When any object that is returned from the query is modified elsewhere, a notification is sent and the grid can be updated. Notifications will also be sent when new objects are added or objects are deleted. Clients can use these notifications to track changes and maintain synchronized data.

With the addition of a Comet support Persevere can be used not only as RESTful persistent object storage solution, but also for web applications that need to provide a live view of frequently changing data.

2 Responses to “Persevere Adds Comet Support”

  1. Comet Daily » Blog Archive » Introducing HTTP Channels Says:

    [...] Comet communication with REST, but with improvements based on suggestions, further research, and an actual implementation in Persevere. HTTP Channels can also use HTTP tunneling in conjunction with XHR streaming where available [...]

  2. SitePen Blog » When to Use Persevere: a Comparison with CouchDB and Others Says:

    [...] Persevere, it is possible to have a real-time view of data by subscribing to objects and receiving notification…. This capability is specifically designed for web applications. Notifications can be received from [...]


Copyright 2015 Comet Daily, LLC. All Rights Reserved