@Override
public void onStateChange(AtmosphereResourceEvent r) throws IOException {
if (r.getMessage() != null) {
response.get().append(r.getMessage());
if (count.decrementAndGet() == 0) {
r.getResource().getResponse().write(response.toString());
r.getResource().resume();
}
}
}