This document is DEPRECATED.

Please consider any information here as out of date. DO NOT use this document.

Instead, refer to

Please update your bookmarks accordingly.

Skip to end of metadata
Go to start of metadata

The Infinispan WebSocket Server can be used to expose an Infinispan Cache instance over a WebSocket Interface via a very simple Javascript "Cache" API. The WebSocket Interface was introduced as part of the HTML 5 specification.  It defines a full-duplex communication channel to the browser, operating over a single socket (unlike Comet or Ajax) and is exposed to the browser via a Javascript interface.

Starting The Server

The Infinispan WebSocket server is included in Infinispan distributions from 4.1.0.BETA1 onwards, in both the and archives.  To start the server, use the bin/ (or bin\startServer.bat) command-line scripts, using the -r websocket switch.

For more help on available switches, check out the server command line options article.

Javascript API

Writing a web page that uses the Infinispan Cache API is trivial.  The page simply needs to include a <script> declaration for the infinispan-ws.js Javascript source file.  This script is served up by WebSocket Server.

So, for loading infinispan-ws.js from a WebSocket Server instance running on (default port):

Creating a Client-Side Cache Object Instance

The client-side interface to a server-side Infinispan cache is the Cache Javascript object.  It can be constructed as follows:

By default, the Cache instance will interface to the default Infinispan Cache associated with the WebSocket Server from which the infinispan-ws.js Javascript source file was loaded.  So, in the above case, the Cache object instance will connect to the WebSocket Server running on (i.e. ws://

The Infinispan Cache name and WebSocket Server address can be specified in the {{Cache} object constructor as follows:

Cache Operations

A number of cache operations can be performed via the Cache object instance such as get, put, remove, notify and unnotify.

The get and notify operations require a callback function to be registered with the Cache object instance.  This callback function receives all add/update/remove notifications on any cache entries for which the notify function was invoked.  It also asynchronously receives the result of a single invocation of the get function i.e. get can be thought of as "notify once, immediately".

The callback function is registered with the Cache object instance via the registerCallback function.  The function should have 2 parameters - key and value, relating to the cache key and value.

Getting and updating data in the cache is done by simply calling the get, put and remove functions on the Cache object instance.  These operations could be triggered by user interaction with a web form e.g.

Sample code

Infinispan's source tree contains a sample HTML document that makes use of the WebSocket server.  Browse through the source of this HTML document here.

Browser Support

At the time of writing, Google Chrome was the only browser with native WebSocket support.  However, the jWebSocket project provides a client side Javascript library that adds WebSocket support to any Flash enabled browser.


See the following demo of the Infinispan WebSocket Server in action.




Browse Infinispan's Git repository.

server server Delete
datagrid datagrid Delete
infinispan infinispan Delete
websocket websocket Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.