com.sun.grizzly.comet.handlers
Class ReflectorCometHandler

java.lang.Object
  extended by com.sun.grizzly.comet.handlers.ReflectorCometHandler
All Implemented Interfaces:
CometHandler<PrintWriter>

public class ReflectorCometHandler
extends Object
implements CometHandler<PrintWriter>

Simple CometHandler that write (using a PrintWriter) all messages (CometEvent.attachment it receive. This CometHandler just reflect everything, without filtering, the result of a {@link CometContext#notify).

Author:
Jeanfrancois Arcand

Field Summary
protected  PrintWriter printWriter
           
 
Constructor Summary
ReflectorCometHandler()
          Create a reflector.
ReflectorCometHandler(boolean useStreaming)
          Create a reflector.
ReflectorCometHandler(boolean useStreaming, String startingMessage, String endingMessage)
          Create a reflector.
 
Method Summary
 void attach(PrintWriter printWriter)
          Attach a PrintWriter that will be used to write the returned value of CometEvent.attachment
 void onEvent(CometEvent event)
          Write CometEvent.attachment and resume the connection if useStreaming is false
 void onInitialize(CometEvent event)
          Send the startingMessage before the connection get suspended.
 void onInterrupt(CometEvent event)
          Send the endingMessage before the connection get interupted.
 void onTerminate(CometEvent event)
          Send the endingMessage before the connection get terminated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

printWriter

protected PrintWriter printWriter
Constructor Detail

ReflectorCometHandler

public ReflectorCometHandler()
Create a reflector.


ReflectorCometHandler

public ReflectorCometHandler(boolean useStreaming)
Create a reflector.

Parameters:
useStreaming - should the connection be resumed on the first push, or never resumed from the onEvent(com.sun.grizzly.comet.CometEvent). Default is true.

ReflectorCometHandler

public ReflectorCometHandler(boolean useStreaming,
                             String startingMessage,
                             String endingMessage)
Create a reflector.

Parameters:
useStreaming - should the connection be resumed on the first push, or never resumed from the onEvent(com.sun.grizzly.comet.CometEvent). Default is true.
endingMessage - Message send when the connection is about to be suspended (onInitialize(com.sun.grizzly.comet.CometEvent)) or gets interrupted (onInterrupt(com.sun.grizzly.comet.CometEvent))
endingMessage - Message send when the connection terminate (onTerminate(com.sun.grizzly.comet.CometEvent)) or gets interrupted (onInterrupt(com.sun.grizzly.comet.CometEvent))
Method Detail

attach

public void attach(PrintWriter printWriter)
Attach a PrintWriter that will be used to write the returned value of CometEvent.attachment

Specified by:
attach in interface CometHandler<PrintWriter>
Parameters:
printWriter - PrintWriter that will be used to write the returned value of CometEvent.attachment

onEvent

public void onEvent(CometEvent event)
             throws IOException
Write CometEvent.attachment and resume the connection if useStreaming is false

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

onInitialize

public void onInitialize(CometEvent event)
                  throws IOException
Send the startingMessage before the connection get suspended.

Specified by:
onInitialize in interface CometHandler<PrintWriter>
Parameters:
event - (@link CometEvent}
Throws:
IOException

onTerminate

public void onTerminate(CometEvent event)
                 throws IOException
Send the endingMessage before the connection get terminated.

Specified by:
onTerminate in interface CometHandler<PrintWriter>
Parameters:
event - (@link CometEvent}
Throws:
IOException

onInterrupt

public void onInterrupt(CometEvent event)
                 throws IOException
Send the endingMessage before the connection get interupted.

Specified by:
onInterrupt in interface CometHandler<PrintWriter>
Parameters:
event - (@link CometEvent}
Throws:
IOException


Copyright © 2012 Oracle Corporation. All Rights Reserved.