// This robot is proxying so set the proxy field.
messages.setProxyingFor(robotName.getProxyFor());
}
// Sending any operations will cause an exception.
OpBasedWavelet wavelet =
new OpBasedWavelet(snapshot.getWaveId(), snapshot,
// This doesn't thrown an exception, the sinks will
new BasicWaveletOperationContextFactory(null),
ParticipationHelper.DEFAULT, SilentOperationSink.VOID, SilentOperationSink.VOID);
ObservableConversation conversation = getRootConversation(wavelet);
if (conversation == null) {
return messages;
}
// Start listening
EventGeneratingConversationListener conversationListener =
new EventGeneratingConversationListener(conversation, capabilities, messages, robotName);
conversation.addListener(conversationListener);
EventGeneratingWaveletListener waveletListener =
new EventGeneratingWaveletListener(capabilities);
wavelet.addListener(waveletListener);
Map<String, EventGeneratingDocumentHandler> docHandlers = Maps.newHashMap();
try {
for (TransformedWaveletDelta delta : waveletAndDeltas.getDeltas()) {
// TODO(ljvderijk): Set correct timestamp and hashed version once
// wavebus sends them along
long timestamp = 0L;
conversationListener.deltaBegin(delta.getAuthor(), timestamp);
for (WaveletOperation op : delta) {
// Check if we need to attach a doc handler.
if ((op instanceof WaveletBlipOperation)) {
attachDocHandler(conversation, op, docHandlers, capabilities, messages,
delta.getAuthor(), timestamp);
}
op.apply(snapshot);
}
conversationListener.deltaEnd();
}
} catch (OperationException e) {
throw new IllegalStateException("Operation failed to apply when generating events", e);
} finally {
conversation.removeListener(conversationListener);
wavelet.removeListener(waveletListener);
for (EventGeneratingDocumentHandler docHandler : docHandlers.values()) {
docHandler.doc.removeListener(docHandler);
}
}