org.atmosphere.samples.tictactoe
Class TTTHandler

java.lang.Object
  extended by org.atmosphere.samples.tictactoe.TTTHandler
All Implemented Interfaces:
AtmosphereHandler<HttpServletRequest,HttpServletResponse>

public class TTTHandler
extends Object
implements AtmosphereHandler<HttpServletRequest,HttpServletResponse>

Simple handler that listens for GET and POST requests, and responds appropriately. Uses long polling, with a GET that listens for new data, and a POST that triggers broadcasts to all clients, resuming the GETs and returning that data. Actual game logic is held in a separate class - TTTGame.

Author:
driscoll

Constructor Summary
TTTHandler()
           
 
Method Summary
 AtmosphereEvent onEvent(AtmosphereEvent<HttpServletRequest,HttpServletResponse> event)
          On GET, suspend the conneciton.
 AtmosphereEvent onMessage(AtmosphereEvent<HttpServletRequest,HttpServletResponse> event)
          Resume the underlying response on the first Broadcast
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TTTHandler

public TTTHandler()
Method Detail

onEvent

public AtmosphereEvent onEvent(AtmosphereEvent<HttpServletRequest,HttpServletResponse> event)
                        throws IOException
On GET, suspend the conneciton. On POST, update game logic, send broadcast, and resume the connection.

Specified by:
onEvent in interface AtmosphereHandler<HttpServletRequest,HttpServletResponse>
Parameters:
event -
Returns:
event
Throws:
IOException

onMessage

public AtmosphereEvent onMessage(AtmosphereEvent<HttpServletRequest,HttpServletResponse> event)
                          throws IOException
Resume the underlying response on the first Broadcast

Specified by:
onMessage in interface AtmosphereHandler<HttpServletRequest,HttpServletResponse>
Parameters:
event -
Returns:
event
Throws:
IOException


Copyright © 2009 SUN Microsystems. All Rights Reserved.