queue.setActivationCallback(new QueueActivationCallback() {
@Override
public void activate(final MessageQueue queue) {
try {
queue.poll(new OutputStreamWriteAdapter(asyncContext.getResponse().getOutputStream()));
queue.setActivationCallback(null);
queue.heartBeat();
}
catch (IOException e) {
log.debug("Closing queue with id: " + queue.getSession().getSessionId() + " due to IOException", e);