com.sun.grizzly.comet
Interface CometHandler<E>

All Known Subinterfaces:
CometHandler<E>
All Known Implementing Classes:
AjaxCometServlet.ChatListnerHandler, CometServlet.CometRequestHandler, CometServlet.CometRequestHandler, DataHandler, DefaultConcurrentCometHandler, ReflectorCometHandler, StickyHandler

public interface CometHandler<E>

This interface represents a suspended connection (or response). Passing an instance of this class to CometContext.addCometHandler(com.sun.grizzly.comet.CometHandler, boolean) automatically tells Grizzly Comet to suspend the underlying connection and to avoid commiting the response. Since the response is not commited, the connection is considered as suspended and can be resumed later when an event happens by invoking CometContext.resumeCometHandler(CometHandler), from onEvent(com.sun.grizzly.comet.CometEvent). CometContext#resumeCometHandler(CometHandler), resume the connection by commiting 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 {@link CometContext#notify(String)} is invoked or when the {@link CometContext#getExpirationDelay()} expires. With {@link Servlet}, it is recommended to attach the {@link HttpServletResponse} and use this object to push back messages to the client.

Author:
Jeanfrancois Arcand

Method Summary
 void attach(E attachment)
          Attach an intance of E to this class.
 void onEvent(CometEvent event)
          Receive CometEvent notification.
 void onInitialize(CometEvent event)
          Receive CometEvent notification when Grizzly is about to suspend the connection.
 void onInterrupt(CometEvent event)
          Receive CometEvent notification when the underlying tcp communication is resumed by Grizzly.
 void onTerminate(CometEvent event)
          Receive CometEvent notification when the response is resumed by a CometHandler or by the CometContext
 

Method Detail

attach

void attach(E attachment)
Attach an intance of E to this class.


onEvent

void onEvent(CometEvent event)
             throws IOException
Receive CometEvent notification. This method will be invoked everytime a CometContext.notify(java.lang.Object) 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(com.sun.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

void onInitialize(CometEvent 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(com.sun.grizzly.comet.CometHandler, boolean) operations.

Throws:
IOException

onTerminate

void onTerminate(CometEvent event)
                 throws IOException
Receive CometEvent notification when the response is resumed by a CometHandler or by the CometContext

Throws:
IOException

onInterrupt

void onInterrupt(CometEvent event)
                 throws IOException
Receive CometEvent notification when the underlying tcp communication is resumed by Grizzly. This happens when the CometContext.setExpirationDelay(long) expires or when the remote client close the connection.

Throws:
IOException


Copyright © 2012 Oracle Corporation. All Rights Reserved.