@Override
public void logout(String username) throws ChatException {
// check if there is a HTTP session setup.
HttpSession httpSession = getThreadLocalRequest().getSession(false);
if (httpSession == null) {
throw new ChatException("User: " + username + " is not logged in: no http session");
}
// check if there is a Comet session setup. In a larger application the HTTP session may have been
// setup via other means.
CometSession cometSession = CometServlet.getCometSession(httpSession, false);
if (cometSession == null) {
throw new ChatException("User: " + username + " is not logged in: no comet session");
}
// check the user name parameter matches the HTTP sessions user name
if (!username.equals(httpSession.getAttribute("username"))) {
throw new ChatException("User: " + username + " is not logged in on this session");
}
// remove the mapping of user name to CometSession
users.remove(username, cometSession);
httpSession.invalidate();