Providing Push Capabilities to Distrix Web Interfaces

In a previous article, various considerations for making information from a Distrix system available on the web were discussed. The techniques presented were suitable for creating a traditional web application in which each request from a browser results in a snapshot of the information in the system at that point in time being returned from the server. However, in a system with frequently changing data, it is becoming common for modern web applications to push data from the server to the web browser as it changes. This provides both the advantage of maintaining more up to date state in the web browser, and is also more efficient in terms of bandwidth and processing as the user does not need to reload the entire page in order to view the newly updated data. A common way to accomplish this is to use a technique known as long polling or comet.

Long polling typically works by having the client browser initiate an AJAX (asyncronous javascript) request to the server as soon as the page loads. The server will accept the request but will not immediately provide a response. Instead, it will block until an event occurs or a piece of data changes. At this time, it will return a response containing information about the event or the new piece of data. The handler for the original request in the client browser will receive this response, and can dynamically update the page to reflect the new information.

A technique like this is a natural fit for a Distrix system in which distributed object updates occur automatically and asynchronously. One implementation method consists of handling incoming HTTP requests in separate threads (one thread for each request) and blocking on a condition variable as soon as the request is received. Then, in the agent thread, when a Distrix proxy update fires its change callback, the condition variable can be signaled. All HTTP request threads waiting on the condition variable will then wake up, and can return the relevant information from the object as part of their HTTP response. An example Distrix project written in Python using this technique can be found here.