com.sun.grizzly.samples.comet
Class AjaxCometServlet.ChatListnerHandler

java.lang.Object
  extended by com.sun.grizzly.samples.comet.AjaxCometServlet.ChatListnerHandler
All Implemented Interfaces:
CometHandler<PrintWriter>
Enclosing class:
AjaxCometServlet

public class AjaxCometServlet.ChatListnerHandler
extends Object
implements CometHandler<PrintWriter>


Constructor Summary
AjaxCometServlet.ChatListnerHandler()
           
 
Method Summary
 void attach(PrintWriter writer)
          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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AjaxCometServlet.ChatListnerHandler

public AjaxCometServlet.ChatListnerHandler()
Method Detail

attach

public void attach(PrintWriter writer)
Description copied from interface: CometHandler
Attach an intance of E to this class.

Specified by:
attach in interface CometHandler<PrintWriter>

onEvent

public void onEvent(CometEvent event)
             throws IOException
Description copied from interface: CometHandler
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.

Specified by:
onEvent in interface CometHandler<PrintWriter>
Throws:
IOException

onInitialize

public void onInitialize(CometEvent event)
                  throws IOException
Description copied from interface: CometHandler
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.

Specified by:
onInitialize in interface CometHandler<PrintWriter>
Throws:
IOException

onInterrupt

public void onInterrupt(CometEvent event)
                 throws IOException
Description copied from interface: CometHandler
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.

Specified by:
onInterrupt in interface CometHandler<PrintWriter>
Throws:
IOException

onTerminate

public void onTerminate(CometEvent event)
                 throws IOException
Description copied from interface: CometHandler
Receive CometEvent notification when the response is resumed by a CometHandler or by the CometContext

Specified by:
onTerminate in interface CometHandler<PrintWriter>
Throws:
IOException


Copyright © 2012 Oracle Corporation. All Rights Reserved.