prefix = prefix + "/";
}
//boolean streamingSupported = isHttpStreamAcceptable(req);
CometSerializer serializer = getCometSerializer(req);
serializer.setResponse(resp);
final EventStream eventStream = getEventStream(req);
if (eventStream == null) {
resp.setStatus(404); // The client id was not found
resp.getOutputStream().print("The client ID was not found");
return;
}
Notification notification = eventStream.eventAvailable() ? eventStream.take(0) : null;
if (notification != null) { // we are resuming
try {
if (sendEvent(notification, eventStream, serializer))
return; // done
else {
org.mortbay.util.ajax.Continuation continuation = org.mortbay.util.ajax.ContinuationSupport.getContinuation(req, null);
if (continuation.isResumed())
continuation.suspend(req.getSession().getMaxInactiveInterval() * 500); // suspend again
else
notification = suspend(eventStream, req);
continuation.suspend(req.getSession().getMaxInactiveInterval() * 500); // suspend again
}
throw new RuntimeException("Continuation failed");
}
catch (ConnectionConflictException e) {
resp.setStatus(409);
}
catch (IOException e) {
//e.printStackTrace();
eventStream.finished();
}
return;
}
if (req.getHeader("xdomainrequest") == null) {
// if it is not IE8, we do not want to have multiple connections
HttpSession session = req.getSession(true);
Client otherConnection = (Client) session.getAttribute("org.persvr.channel");
if (otherConnection != null && otherConnection != eventStream) {
//TODO: Send reconnect advice
otherConnection.fire(new ConnectionConflict()); // if there is another connection, we need to notify it
}
session.setAttribute("org.persvr.channel",eventStream);
}
else
resp.setHeader("XDomainRequestAllowed", "1"); // allow this so we can support streaming in IE8
//final ServletOutputStream outStream = resp.getOutputStream();
// System.err.println("eventStream.ping" + eventStream.pingCallback);
boolean writtenTo = false;
while (!writtenTo || serializer.isStreamingAvailable() || eventStream.eventAvailable()) {
notification = suspend(eventStream, req); // implementation specific handling
if (notification == null) // if the suspend returns null, the suspend will resume the operation
return;
serializer.sendNotification(notification, (Client) eventStream,!writtenTo);