org.atmosphere.samples.tictactoe
Class TTTHandler
java.lang.Object
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
|
Method Summary |
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 |
TTTHandler
public TTTHandler()
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
Copyright © 2010 SUN Microsystems. All Rights Reserved.