import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.FutureCallback;
-
+import edu.umd.cs.findbugs.annotations.Nullable;
import java.util.function.Function;
import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueException;
final class OutboundQueueEntry {
private static final Logger LOG = LoggerFactory.getLogger(OutboundQueueEntry.class);
- public static final Function<OfHeader, Boolean> DEFAULT_IS_COMPLETE = new Function<OfHeader, Boolean>() {
-
- @Override
- public Boolean apply(final OfHeader message) {
- if (message instanceof MultipartReplyMessage) {
- return !((MultipartReplyMessage) message).getFlags().isOFPMPFREQMORE();
- }
-
- return true;
+ public static final Function<OfHeader, Boolean> DEFAULT_IS_COMPLETE = message -> {
+ if (message instanceof MultipartReplyMessage) {
+ return !((MultipartReplyMessage) message).getFlags().isOFPMPFREQMORE();
}
+ return true;
};
private FutureCallback<OfHeader> callback;
private boolean completed;
private boolean barrier;
private volatile boolean committed;
- private OutboundQueueException lastException = null;
private Function<OfHeader, Boolean> isCompletedFunction = DEFAULT_IS_COMPLETE;
- void commit(final OfHeader message, final FutureCallback<OfHeader> callback) {
- commit(message, callback, DEFAULT_IS_COMPLETE);
+ void commit(final OfHeader messageToCommit, final FutureCallback<OfHeader> commitCallback) {
+ commit(messageToCommit, commitCallback, DEFAULT_IS_COMPLETE);
}
- void commit(final OfHeader message, final FutureCallback<OfHeader> callback,
- final Function<OfHeader, Boolean> isCompletedFunction) {
+ void commit(final OfHeader messageToCommit, final FutureCallback<OfHeader> commitCallback,
+ final Function<OfHeader, Boolean> isCommitCompletedFunction) {
if (this.completed) {
LOG.warn("Can't commit a completed message.");
- if (callback != null) {
- callback.onFailure(lastException);
+ if (commitCallback != null) {
+ commitCallback.onFailure(new OutboundQueueException("Can't commit a completed message."));
}
} else {
- this.message = message;
- this.callback = callback;
- this.barrier = message instanceof BarrierInput;
- this.isCompletedFunction = isCompletedFunction;
+ this.message = messageToCommit;
+ this.callback = commitCallback;
+ this.barrier = messageToCommit instanceof BarrierInput;
+ this.isCompletedFunction = isCommitCompletedFunction;
// Volatile write, needs to be last
this.committed = true;
}
private void checkCompletionNeed() {
- if (callback == null || (message instanceof PacketOutInput)) {
+ if (callback == null || message instanceof PacketOutInput) {
completed = true;
if (callback != null) {
callback.onSuccess(null);
}
}
- boolean complete(final OfHeader response) {
+ boolean complete(@Nullable final OfHeader response) {
Preconditions.checkState(!completed, "Attempted to complete a completed message with response %s", response);
// Multipart requests are special, we have to look at them to see
void fail(final OutboundQueueException cause) {
if (!completed) {
- lastException = cause;
completed = true;
if (callback != null) {
callback.onFailure(cause);
callback = null;
}
} else {
- LOG.warn("Ignoring failure {} for completed message", cause);
+ LOG.warn("Ignoring failure for completed message", cause);
}
}
@VisibleForTesting
/** This method is only for testing to prove that after queue entry is completed there is not callback future */
boolean hasCallback() {
- return (callback != null);
+ return callback != null;
}
}