Package org.glassfish.grizzly.comet
Class DefaultCometHandler<E>
java.lang.Object
org.glassfish.grizzly.comet.DefaultCometHandler<E>
- All Implemented Interfaces:
CometHandler<E>
A basic default implementation of CometHandler to take care of tracking the Response and CometContext.
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultCometHandler(CometContext<E> cometContext, org.glassfish.grizzly.http.server.Response response) -
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> cometContext) voidsetResponse(org.glassfish.grizzly.http.server.Response response)
-
Constructor Details
-
DefaultCometHandler
public DefaultCometHandler() -
DefaultCometHandler
public DefaultCometHandler(CometContext<E> cometContext, org.glassfish.grizzly.http.server.Response response)
-
-
Method Details
-
getResponse
public org.glassfish.grizzly.http.server.Response getResponse()- Specified by:
getResponsein interfaceCometHandler<E>- Returns:
- the response associated with the handler.
-
setResponse
public void setResponse(org.glassfish.grizzly.http.server.Response response) - Specified by:
setResponsein interfaceCometHandler<E>
-
getCometContext
- Specified by:
getCometContextin interfaceCometHandler<E>
-
setCometContext
- Specified by:
setCometContextin interfaceCometHandler<E>
-
onEvent
Description copied from interface:CometHandlerReceiveCometEventnotification. 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.- Specified by:
onEventin interfaceCometHandler<E>- Throws:
IOException
-
onInitialize
Description copied from interface:CometHandlerReceiveCometEventnotification 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.- Specified by:
onInitializein interfaceCometHandler<E>- Throws:
IOException
-
onTerminate
Description copied from interface:CometHandlerReceiveCometEventnotification when the response is resumed by aCometHandleror by theCometContext- Specified by:
onTerminatein interfaceCometHandler<E>- Throws:
IOException
-
onInterrupt
Description copied from interface:CometHandlerReceiveCometEventnotification when the underlying tcp communication is resumed by Grizzly. This happens when theCometContext.setExpirationDelay(long)expires or when the remote client close the connection.- Specified by:
onInterruptin interfaceCometHandler<E>- Throws:
IOException
-