BUG-3219: introduce OutboundQueueException 12/20612/5
authorRobert Varga <rovarga@cisco.com>
Sat, 16 May 2015 22:46:48 +0000 (00:46 +0200)
committerRobert Varga <rovarga@cisco.com>
Mon, 18 May 2015 01:12:37 +0000 (03:12 +0200)
Original API has not specified an encapsulation exception for errors
incurred during local processing. This patch fixes that by introducing
OutboundQueueException.

Change-Id: I01197710c9d60bd778009c098ec640511eea23c6
Signed-off-by: Robert Varga <rovarga@cisco.com>
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/DeviceRequestFailedException.java
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/OutboundQueue.java
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/OutboundQueueException.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueImpl.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueManager.java

index a353886dd881c12e72606711ae10e94244370097..347d73d0a0bf37bfb23344e76cce293b4231991f 100644 (file)
@@ -15,7 +15,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  * Exception which is used to report that a particular request failed on the
  * remote device (switch).
  */
-public class DeviceRequestFailedException extends Exception {
+public class DeviceRequestFailedException extends OutboundQueueException {
     private static final long serialVersionUID = 1L;
     private final Error error;
 
index 06b66c5e046f320537f8dcddefb42db981a10d86..afe5b056b2192cb183d5c4b6f7d9426b38c700a6 100644 (file)
@@ -33,6 +33,11 @@ public interface OutboundQueue {
      * If this request fails on the remote device, {@link FutureCallback#onFailure(Throwable)
      * will be called with an instance of {@link DeviceRequestFailedException}.
      *
+     * If the request fails due to local reasons, {@link FutureCallback#onFailure(Throwable)
+     * will be called with an instance of {@link OutboundQueueException}. In particular, if
+     * this request failed because the device disconnected, {@link OutboundQueueException#DEVICE_DISCONNECTED}
+     * will be reported.
+     *
      * @param xid Previously-reserved XID
      * @param message Message which should be sent out, or null if the reservation
      *                should be cancelled.
diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/OutboundQueueException.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/OutboundQueueException.java
new file mode 100644 (file)
index 0000000..497c7a2
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2015 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowjava.protocol.api.connection;
+
+/**
+ * Exception reported when an exceptional event occurs on an {@link OutboundQueue},
+ * which the {@link OutboundQueueHandler} needs to be aware of.
+ */
+public class OutboundQueueException extends Exception {
+    /**
+     * Exception reported when the device disconnects.
+     */
+    public static final OutboundQueueException DEVICE_DISCONNECTED = new OutboundQueueException("Device disconnected");
+
+    private static final long serialVersionUID = 1L;
+
+    public OutboundQueueException(final String message) {
+        super(message);
+    }
+
+    public OutboundQueueException(final String message, final Throwable cause) {
+        super(message, cause);
+    }
+}
index e8e2307ca2be3108053d94cba24013377b7e1989..f61e8fffa6d86abb58fa1028e425073e01796482 100644 (file)
@@ -12,8 +12,9 @@ import com.google.common.base.Verify;
 import com.google.common.util.concurrent.FutureCallback;
 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
 import javax.annotation.Nonnull;
-import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
 import org.opendaylight.openflowjava.protocol.api.connection.DeviceRequestFailedException;
+import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
+import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueException;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 import org.slf4j.Logger;
@@ -272,7 +273,7 @@ final class OutboundQueueImpl implements OutboundQueue {
         completeRequests(queue.length);
     }
 
-    int failAll(final Throwable cause) {
+    int failAll(final OutboundQueueException cause) {
         int ret = 0;
         for (int i = lastBarrierOffset + 1; i < queue.length; ++i) {
             final OutboundQueueEntry entry = queue[i];
index 4864b95d655d8e63a2dc9851a364f060eadee1d5..5c9a3515cea1de1a0d28a7d29c2d3c646dd9996c 100644 (file)
@@ -15,9 +15,9 @@ import java.util.ArrayDeque;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Queue;
-import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
+import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueException;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandler;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
@@ -397,9 +397,8 @@ final class OutboundQueueManager<T extends OutboundQueueHandler> extends Channel
         LOG.debug("Channel shutdown, flushing queue...");
         handler.onConnectionQueueChanged(null);
 
-        final Throwable cause = new RejectedExecutionException("Channel disconnected");
         for (OutboundQueueImpl queue : activeQueues) {
-            entries += queue.failAll(cause);
+            entries += queue.failAll(OutboundQueueException.DEVICE_DISCONNECTED);
         }
         activeQueues.clear();