@Override
public void onSuccess(int opsApplied, HashedVersion newVersion, ResponseCode responseCode,
String errorMessage) throws ChannelException {
if (connectionIsCurrent()) {
if (opsApplied < 0) {
throw new ChannelException("Delta channel: invalid submit delta response, opsApplied: "
+ opsApplied, NOT_RECOVERABLE);
}
// TODO(danilatos): (1/12/2009) Remove this if statement once the
// error code field is made required in the proto.
if (errorMessage != null && responseCode == ResponseCode.OK) {
responseCode = ResponseCode.INTERNAL_ERROR;
}
if (opsApplied > 0 || responseCode == ResponseCode.OK) {
// It is not necessarily the case that
// opsApplied == delta.getOpListSize() since ops may disappear in
// transform. Zero ops applied is a valid ack when the server
// transforms all operations away.
lastAckedVersion = newVersion;
onServerMessage(new ServerMessage.Ack(opsApplied, newVersion));
}
if (responseCode == ResponseCode.TOO_OLD) {
throw new ChannelException(ResponseCode.TOO_OLD, "Delta targeted too old version",
null, Recoverable.RECOVERABLE, null, null);
} else if (responseCode != ResponseCode.OK) {
// Using lastServerVersion when opsApplied is 0 is a harmless cop out to deal with the
// fact that the view server access control responds with a bogus version and 0
// opsApplied when it rejects a delta.
onServerMessage(new ServerMessage.Nack(
(opsApplied > 0) ? newVersion.getVersion() : lastServerVersion,
responseCode, errorMessage));
}
lastTransmitDelta = transmitDelta;
transmitDelta = null; // Enables flushServerMessages() to transmit.
flushServerMessages();
// Check the ack didn't leave a gap in the queue.
if (!queue.isEmpty() &&
(queue.get(0).startVersion() != (newVersion.getVersion() - opsApplied))) {
throw new ChannelException(
"Delta channel couldn't flush messages after submit response: lastServerVersion "
+ lastServerVersion + ", queued message version " + queue.get(0).startVersion()
+ " response version " + newVersion + ", opsApplied " + opsApplied + ", code "
+ responseCode + ", errorMessage " + errorMessage,
Recoverable.NOT_RECOVERABLE);
}
}
}
@Override
public void onFailure(String reason) throws ChannelException {
if (connectionIsCurrent()) {
throw new ChannelException("Delta channel: submission failed: " + reason, RECOVERABLE);
}
}
/**
* Checks whether the channel is connected and connection tag is current,