this.broker = broker;
}
public void onTopicAppears(final String topic) {
TimerTask task = new TimerTask() {
@Override
public void run() {
Set<IWebSocketConnection> cons = broker.retrieve(topic);
for (IWebSocketConnection con : cons) {
try {
Event event = new Event("REVISION_CHANGED", topic, "old=35", "new=65");
con.writeMessage(new TextMessage(event.toString()));
} catch (IOException ioe) {
broker.deregister(topic, con);
con.closeQuitly();
}
}
}
};
TimerTask oldTask;
synchronized (openTasks) {
oldTask = openTasks.put(topic, task);
}
if (oldTask != null) {
oldTask.cancel();
}
timer.schedule(task, 1000, 1000);
}