private final List<TransactionModification> modifications = new ArrayList<>(1);
private final TransactionIdentifier identifier;
private final ActorRef replyTo;
- private PersistenceProtocol protocol = null;
+ private PersistenceProtocol protocol;
+ private Long sequence;
public ModifyTransactionRequestBuilder(final TransactionIdentifier identifier, final ActorRef replyTo) {
this.identifier = Preconditions.checkNotNull(identifier);
return identifier;
}
- private void checkFinished() {
- Preconditions.checkState(protocol != null, "Batch has already been finished");
+ private void checkNotFinished() {
+ Preconditions.checkState(protocol == null, "Batch has already been finished");
}
public void addModification(final TransactionModification modification) {
- checkFinished();
+ checkNotFinished();
modifications.add(Preconditions.checkNotNull(modification));
}
+ public void setSequence(final long sequence) {
+ this.sequence = sequence;
+ }
+
public void setAbort() {
- checkFinished();
+ checkNotFinished();
// Transaction is being aborted, no need to transmit operations
modifications.clear();
protocol = PersistenceProtocol.ABORT;
}
public void setCommit(final boolean coordinated) {
- checkFinished();
+ checkNotFinished();
protocol = coordinated ? PersistenceProtocol.THREE_PHASE : PersistenceProtocol.SIMPLE;
}
@Override
public ModifyTransactionRequest build() {
- final ModifyTransactionRequest ret = new ModifyTransactionRequest(identifier, replyTo, modifications, protocol);
+ Preconditions.checkState(sequence != null, "Request sequence has not been set");
+
+ final ModifyTransactionRequest ret = new ModifyTransactionRequest(identifier, sequence, replyTo, modifications,
+ protocol);
modifications.clear();
protocol = null;
+ sequence = null;
return ret;
}
}