Merge "Sending each flow/group in separate bundle add rpc instead of adding all messa...
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / core / connection / OutboundQueueEntry.java
index d88566b8d3635efc24309b4c28ed791577ac7331..4739ba8344375b084b7844209d1217138fc2988e 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.openflowjava.protocol.impl.core.connection;
 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;
@@ -24,17 +24,12 @@ import org.slf4j.LoggerFactory;
 
 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;
@@ -42,25 +37,24 @@ final class OutboundQueueEntry {
     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;
@@ -99,7 +93,7 @@ final class OutboundQueueEntry {
     }
 
     private void checkCompletionNeed() {
-        if (callback == null || (message instanceof PacketOutInput)) {
+        if (callback == null || message instanceof PacketOutInput) {
             completed = true;
             if (callback != null) {
                 callback.onSuccess(null);
@@ -109,7 +103,7 @@ final class OutboundQueueEntry {
         }
     }
 
-    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
@@ -130,20 +124,19 @@ final class OutboundQueueEntry {
 
     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;
     }
 }