if (r instanceof AtmosphereEventLifecycle) {
((AtmosphereEventLifecycle) r).addEventListener(el);
}
}
Broadcaster bc = s.broadcaster();
if (bc == null){
bc = (Broadcaster) servletReq.getAttribute(INJECTED_BROADCASTER);
}
suspend(sessionSupported, resumeOnBroadcast, outputJunk,
translateTimeUnit(s.period().value(),s.period().timeUnit()), request, response,bc, r);
break;
case SUSPEND:
case SUSPEND_RESUME:
outputJunk = outputJunk(request,outputComments);
resumeOnBroadcast = resumeOnBroadcast(request,(action == Action.SUSPEND_RESUME));
for (Class<? extends AtmosphereResourceEventListener> listener : listeners) {
try {
AtmosphereResourceEventListener el = listener.newInstance();
InjectorProvider.getInjector().inject(el);
if (r instanceof AtmosphereEventLifecycle) {
((AtmosphereEventLifecycle) r).addEventListener(el);
}
} catch (Throwable t) {
throw new WebApplicationException(
new IllegalStateException("Invalid AtmosphereResourceEventListener " + listener, t));
}
}
suspend(sessionSupported, resumeOnBroadcast, outputJunk, suspendTimeout, request, response, (
Broadcaster) servletReq.getAttribute(INJECTED_BROADCASTER), r);
break;
case RESUME:
if (response.getEntity() != null) {
try {
response.write();
} catch (IOException ex) {
throw new WebApplicationException(ex);
}
}
if (sessionSupported) {
r = (AtmosphereResource) servletReq.getSession().getAttribute(SUSPENDED_RESOURCE);
} else {
String path = response.getContainerRequest().getPath();
r = resumeCandidates.remove(path.substring(path.lastIndexOf("/") + 1));
}
if (r != null) {
resume(r);
} else {
throw new WebApplicationException(
new IllegalStateException("Unable to retrieve suspended Response. " +
"Either session-support is not enabled in atmosphere.xml or the" +
"path used to resume is invalid."));
}
break;
case BROADCAST:
case RESUME_ON_BROADCAST:
AtmosphereResource ar = (AtmosphereResource) servletReq.getAttribute(SUSPENDED_RESOURCE);
if (ar != null) {
r = ar;
}
broadcast(response, r, suspendTimeout);
break;
case SCHEDULE:
case SCHEDULE_RESUME:
Object o = response.getEntity();
Broadcaster b = r.getBroadcaster();
if (response.getEntity() instanceof Broadcastable) {
b = ((Broadcastable) response.getEntity()).getBroadcaster();
o = ((Broadcastable) response.getEntity()).getMessage();
response.setEntity(((Broadcastable) response.getEntity()).getResponseMessage());
}
if (response.getEntity() != null) {
try {
response.write();
} catch (IOException ex) {
throw new WebApplicationException(ex);
}
}
if (action == Action.SCHEDULE_RESUME) {
configureResumeOnBroadcast(b);
}
b.scheduleFixedBroadcast(o, waitFor, suspendTimeout, TimeUnit.SECONDS);
break;
}
return response;
}