У меня есть этот класс:
public class CometServlet extends HttpServlet implements CometProcessor{
private static final Integer TIMEOUT = 20 * 1000;
@Override
public void event(final CometEvent event) throws IOException, ServletException {
HttpServletRequest request = event.getHttpServletRequest();
HttpServletResponse response = event.getHttpServletResponse();
if (event.getEventType() == CometEvent.EventType.BEGIN) {
request.setAttribute("org.apache.tomcat.comet.timeout", TIMEOUT);
System.out.println("Begin for session: " + request.getSession(true).getId());
} else if (event.getEventType() == CometEvent.EventType.ERROR) {
System.out.println("Error for sessions: " + request.getSession(true).getId());
if(event.getEventSubType() == EventSubType.TIMEOUT) {
System.out.println("timeout for session: " + request.getSession(true).getId());
}
else if(event.getEventSubType() == EventSubType.IOEXCEPTION) {
System.out.println("ioexception for session: " + request.getSession(true).getId());
}
else if(event.getEventSubType() == EventSubType.CLIENT_DISCONNECT) {
System.out.println("client disconnect for session: " + request.getSession(true).getId());
}
response.getWriter().close();
event.close();
} else if (event.getEventType() == CometEvent.EventType.END) {
System.out.println("End for session: " + request.getSession(true).getId());
if(event.getEventSubType() == EventSubType.WEBAPP_RELOAD) {
System.out.println("webappreload for session: " + request.getSession(true).getId());
}
else if(event.getEventSubType() == EventSubType.SESSION_END) {
System.out.println("sessionend for session: " + request.getSession(true).getId());
}
response.getWriter().close();
event.close();
} else if (event.getEventType() == CometEvent.EventType.READ) {
InputStream is = request.getInputStream();
byte[] buf = new byte[512];
do {
int n = is.read(buf); //can throw an IOException
if (n > 0) {
log("Read " + n + " bytes: " + new String(buf, 0, n)
+ " for session: " + request.getSession(true).getId());
} else if (n < 0) {
System.out.println("error(event, request, response)");
return;
}
} while (is.available() > 0);
}
}
}
Но я не могу поймать event.getEventSubType() == EventSubType.CLIENT_DISCONNECT
.
Можете ли вы помочь мне, пожалуйста?