public void onOpenFinished() throws ChannelException {
if (connectionTag == expectedTag) {
if (missingWavelets == null) {
// TODO(anorth): Add an error code for a protocol error and use
// it here.
throw new ChannelException(ResponseCode.INTERNAL_ERROR,
"Multiplexer received openFinished twice", null, Recoverable.NOT_RECOVERABLE,
waveId, null);
}
// If a missing wavelet could be reconnected at version zero then
// fake the resync message here. The server no longer knows about
// the wavelet so we should resubmit changes from version zero.
Iterator<WaveletId> itr = missingWavelets.iterator();
while (itr.hasNext()) {
WaveletId maybeMissing = itr.next();
List<HashedVersion> resyncVersions = expectedWavelets.get(maybeMissing);
Preconditions.checkState(!resyncVersions.isEmpty(),
"Empty resync versions for wavelet " + maybeMissing);
if (resyncVersions.get(0).getVersion() == 0) {
Stacklet stacklet = channels.get(maybeMissing);
if (stacklet == null) {
Preconditions.illegalState("Resync wavelet has no stacklet. Channels: "
+ channels.keySet() + ", resync: " + expectedWavelets.keySet());
}
WaveletName wavelet = WaveletName.of(waveId, maybeMissing);
List<TransformedWaveletDelta> resyncDeltaList = createVersionZeroResync(wavelet);
HashedVersion v0 = hashFactory.createVersionZero(wavelet);
stacklet.onWaveletUpdate(resyncDeltaList, v0, v0);
itr.remove();
}
}
// Check we received a message for each expected wavelet.
if (!missingWavelets.isEmpty()) {
throw new ChannelException(ResponseCode.NOT_AUTHORIZED,
"Server didn't acknowledge known wavelets; perhaps access has been lost: "
+ missingWavelets, null, Recoverable.NOT_RECOVERABLE, waveId, null);
}
missingWavelets = null;
maybeOpenFinished();