Package org.glassfish.grizzly.comet
Interface CometHandler<E>
- All Known Implementing Classes:
DefaultCometHandler,DefaultConcurrentCometHandler
public interface CometHandler<E>
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 onEvent(org.glassfish.grizzly.comet.CometEvent). 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 Object.notify() is invoked
or when the CometContext.getExpirationDelay() expires.-
Method Summary
Modifier and TypeMethodDescriptionorg.glassfish.grizzly.http.server.ResponsevoidonEvent(CometEvent event) ReceiveCometEventnotification.voidonInitialize(CometEvent event) ReceiveCometEventnotification when Grizzly is about to suspend the connection.voidonInterrupt(CometEvent event) ReceiveCometEventnotification when the underlying tcp communication is resumed by Grizzly.voidonTerminate(CometEvent event) ReceiveCometEventnotification when the response is resumed by aCometHandleror by theCometContextvoidsetCometContext(CometContext<E> context) voidsetResponse(org.glassfish.grizzly.http.server.Response response)
-
Method Details
-
getResponse
org.glassfish.grizzly.http.server.Response getResponse()- Returns:
- the response associated with the handler.
-
setResponse
void setResponse(org.glassfish.grizzly.http.server.Response response) -
getCometContext
CometContext<E> getCometContext() -
setCometContext
-
onEvent
ReceiveCometEventnotification. This method will be invoked every time aCometContext.notify(E)is invoked. TheCometEventwill 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 invokingCometContext.resumeCometHandler(org.glassfish.grizzly.comet.CometHandler).
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.- Throws:
IOException
-
onInitialize
ReceiveCometEventnotification when Grizzly is about to suspend the connection. This method is always invoked during the processing ofCometContext.addCometHandler(org.glassfish.grizzly.comet.CometHandler<E>)operations.- Throws:
IOException
-
onTerminate
ReceiveCometEventnotification when the response is resumed by aCometHandleror by theCometContext- Throws:
IOException
-
onInterrupt
ReceiveCometEventnotification when the underlying tcp communication is resumed by Grizzly. This happens when theCometContext.setExpirationDelay(long)expires or when the remote client close the connection.- Throws:
IOException
-