Grizzly's support for Comet includes a small set of APIs that make it easy to add Comet functionality to your web applications. The Grizzly Comet APIs that developers will use most often are the following:
CometContext: A Comet context, which is a shareable space to which applications subscribe in order to receive updates.
CometEngine: The entry point to any component using Comet. Components can be servlets, JavaServer PagesTM (JSPTM), JavaServer Faces components, or pure Java classes.
CometEvent: Contains the state of the CometContext object
CometHandler: The interface an application implements to be part of one or more Comet contexts.
The way a developer would use this API in a web component is to perform the following tasks:
Register the context path of the application with the CometContext object:
CometEngine cometEngine = CometEngine.getEngine(); CometContext cometContext = cometEngine.register(contextPath)
Register the CometHandler implementation with the CometContext object:
cometContext.addCometHandler(handler)
Notify one or more CometHandler implementations when an event happens:
cometContext.notify((Object)(handler))