From 763e430f61196740c5ea1c7356022396adf55065 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 17 May 2015 00:46:48 +0200 Subject: [PATCH] BUG-3219: introduce OutboundQueueException 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 --- .../DeviceRequestFailedException.java | 2 +- .../api/connection/OutboundQueue.java | 5 ++++ .../connection/OutboundQueueException.java | 29 +++++++++++++++++++ .../core/connection/OutboundQueueImpl.java | 5 ++-- .../core/connection/OutboundQueueManager.java | 5 ++-- 5 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/OutboundQueueException.java diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/DeviceRequestFailedException.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/DeviceRequestFailedException.java index a353886d..347d73d0 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/DeviceRequestFailedException.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/DeviceRequestFailedException.java @@ -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; diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/OutboundQueue.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/OutboundQueue.java index 06b66c5e..afe5b056 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/OutboundQueue.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/OutboundQueue.java @@ -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 index 00000000..497c7a25 --- /dev/null +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/OutboundQueueException.java @@ -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); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueImpl.java index e8e2307c..f61e8fff 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueImpl.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueImpl.java @@ -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]; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueManager.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueManager.java index 4864b95d..5c9a3515 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueManager.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueManager.java @@ -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 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(); -- 2.36.6