Top Description Methods
org.glassfish.grizzly.comet

public Interface CometHandler<E>

Known Direct Implementers
org.glassfish.grizzly.comet.DefaultCometHandler, org.glassfish.grizzly.comet.concurrent.DefaultConcurrentCometHandler
Imports
java.io.IOException, org.glassfish.grizzly.http.server.Response

This interface represents a suspended connection (or response). Passing an instance of this class to CometContext#addCometHandler(CometHandler) automatically tells Grizzly Comet to suspend the underlying connection and to avoid committing the response. Since the response is not committed, the connection is considered as suspended and can be resumed later when an event happens by invoking CometContext#resumeCometHandler(CometHandler), from CometHandler#onEvent. CometContext#resumeCometHandler(CometHandler), resume the connection by committing the response. As an example, a browser icons will spins when a connection is suspended, as the complete response hasn't been sent back.

Components that implement this interface will be notified org.glassfish.grizzly.comet.CometContext#notify() is invoked or when the CometContext#getExpirationDelay() expires.

Method Summary

Modifier and TypeMethod and Description
public CometContext<E>
public Response
getResponse()

Returns: the response associated with the handler.

public void
onEvent(CometEvent<E> event)

Receive CometEvent notification.

public void
onInitialize(CometEvent<E> event)

Receive CometEvent notification when Grizzly is about to suspend the connection.

public void
onInterrupt(CometEvent<E> event)

Receive CometEvent notification when the underlying tcp communication is resumed by Grizzly.

public void
onTerminate(CometEvent<E> event)

Receive CometEvent notification when the response is resumed by a CometHandler or by the CometContext

public void
public void

Method Detail

getCometContextback to summary
public CometContext<E> getCometContext()
getResponseback to summary
public Response getResponse()
Returns:Response

the response associated with the handler.

onEventback to summary
public void onEvent(CometEvent<E> event) throws IOException

Receive CometEvent notification. This method will be invoked every time a CometContext#notify is invoked. The CometEvent will contains the message that can be pushed back to the remote client, cached or ignored. This method can also be used to resume a connection once a notified by invoking CometContext#resumeCometHandler.
its not optimal to flush outputstream in this method for long polling, flush is performed in each CometContext.resume call.
flushing multiple times can fragment the data into several tcp packets, that leads to extra IO and overhead in general due to client ack for each packet etc.

onInitializeback to summary
public void onInitialize(CometEvent<E> event) throws IOException

Receive CometEvent notification when Grizzly is about to suspend the connection. This method is always invoked during the processing of CometContext#addCometHandler operations.

onInterruptback to summary
public void onInterrupt(CometEvent<E> event) throws IOException

Receive CometEvent notification when the underlying tcp communication is resumed by Grizzly. This happens when the CometContext#setExpirationDelay expires or when the remote client close the connection.

onTerminateback to summary
public void onTerminate(CometEvent<E> event) throws IOException

Receive CometEvent notification when the response is resumed by a CometHandler or by the CometContext

setCometContextback to summary
public void setCometContext(CometContext<E> context)
setResponseback to summary
public void setResponse(Response response)