org.atmosphere.samples.tictactoe
Class TTTHandler

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

public class TTTHandler
extends Object
implements AtmosphereHandler<javax.servlet.http.HttpServletRequest,javax.servlet.http.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
 void destroy()
           
 void onRequest(AtmosphereResource<javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse> event)
          On GET, suspend the conneciton.
 void onStateChange(AtmosphereResourceEvent<javax.servlet.http.HttpServletRequest,javax.servlet.http.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

onRequest

public void onRequest(AtmosphereResource<javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse> event)
               throws IOException
On GET, suspend the conneciton. On POST, update game logic, send broadcast, and resume the connection.

Specified by:
onRequest in interface AtmosphereHandler<javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse>
Parameters:
event -
Throws:
IOException

onStateChange

public void onStateChange(AtmosphereResourceEvent<javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse> event)
                   throws IOException
Resume the underlying response on the first Broadcast

Specified by:
onStateChange in interface AtmosphereHandler<javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse>
Parameters:
event -
Throws:
IOException

destroy

public void destroy()
Specified by:
destroy in interface AtmosphereHandler<javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse>


Copyright © 2011. All Rights Reserved.