* {@inheritDoc}
*/
public Action service(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
Action action = null;
try {
action = suspended(req, res);
if (action.type == Action.TYPE.SUSPEND) {
logger.debug("Suspending response: {}", res);
suspend(action, req, res);
} else if (action.type == Action.TYPE.RESUME) {
logger.debug("Resuming response: {}", res);
int latchId = (req.getAttribute(LATCH) == null ? 0 : (Integer)req.getAttribute(LATCH));
if (req.getSession(true).getAttribute(LATCH) != null) {
latchId = (Integer) req.getSession(true).getAttribute(LATCH);
}
CountDownLatch latch = latchs.get(latchId);
if (latch == null && req.getAttribute(AtmosphereResourceImpl.PRE_SUSPEND) == null) {
logger.debug("response wasn't suspended: {}", res);
return action;
}
latch.countDown();
Action nextAction = resumed(req, res);
if (nextAction.type == Action.TYPE.SUSPEND) {
logger.debug("Suspending after resuming response: {}", res);
suspend(action, req, res);
}
}