*/
package org.opendaylight.controller.cluster.datastore;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.base.MoreObjects;
-import com.google.common.base.Preconditions;
import com.google.common.base.Verify;
import java.util.ArrayDeque;
-import java.util.Iterator;
+import java.util.Optional;
import java.util.Queue;
-import javax.annotation.Nullable;
-import javax.annotation.concurrent.NotThreadSafe;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest;
import org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceSuccess;
import org.opendaylight.controller.cluster.access.commands.OutOfOrderRequestException;
import org.slf4j.LoggerFactory;
/**
- * Frontend common transaction state as observed by the shard leader.
+ * Frontend common transaction state as observed by the shard leader. This class is NOT thread-safe.
*
* @author Robert Varga
*/
-@NotThreadSafe
abstract class FrontendTransaction implements Identifiable<TransactionIdentifier> {
private static final Logger LOG = LoggerFactory.getLogger(FrontendTransaction.class);
private RequestException previousFailure;
FrontendTransaction(final AbstractFrontendHistory history, final TransactionIdentifier id) {
- this.history = Preconditions.checkNotNull(history);
- this.id = Preconditions.checkNotNull(id);
+ this.history = requireNonNull(history);
+ this.id = requireNonNull(id);
}
@Override
return history().persistenceId();
}
- final java.util.Optional<TransactionSuccess<?>> replaySequence(final long sequence) throws RequestException {
+ final Optional<TransactionSuccess<?>> replaySequence(final long sequence) throws RequestException {
// Fast path check: if the requested sequence is the next request, bail early
if (expectedSequence == sequence) {
- return java.util.Optional.empty();
+ return Optional.empty();
}
// Check sequencing: we do not need to bother with future requests
// machinery is asynchronous, hence a reply may be in the works and not available.
long replaySequence = firstReplaySequence;
- final Iterator<?> it = replayQueue.iterator();
- while (it.hasNext()) {
- final Object replay = it.next();
+ for (Object replay : replayQueue) {
if (replaySequence == sequence) {
if (replay instanceof RequestException) {
throw (RequestException) replay;
}
Verify.verify(replay instanceof TransactionSuccess);
- return java.util.Optional.of((TransactionSuccess<?>) replay);
+ return Optional.of((TransactionSuccess<?>) replay);
}
replaySequence++;
}
// Not found
- return java.util.Optional.empty();
+ return Optional.empty();
}
final void purgeSequencesUpTo(final long sequence) {
// Request order has already been checked by caller and replaySequence()
@SuppressWarnings("checkstyle:IllegalCatch")
- @Nullable
- final TransactionSuccess<?> handleRequest(final TransactionRequest<?> request, final RequestEnvelope envelope,
- final long now) throws RequestException {
+ final @Nullable TransactionSuccess<?> handleRequest(final TransactionRequest<?> request,
+ final RequestEnvelope envelope, final long now) throws RequestException {
if (request instanceof IncrementTransactionSequenceRequest) {
final IncrementTransactionSequenceRequest incr = (IncrementTransactionSequenceRequest) request;
expectedSequence += incr.getIncrement();
}
}
- @Nullable
- abstract TransactionSuccess<?> doHandleRequest(TransactionRequest<?> request, RequestEnvelope envelope,
+ abstract @Nullable TransactionSuccess<?> doHandleRequest(TransactionRequest<?> request, RequestEnvelope envelope,
long now) throws RequestException;
abstract void retire();