Bump MRI upstreams
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / AbstractRequestCallback.java
index 1fdfa45edd3bd6a5dc54a8c6dd7c38850489dafe..4544e933f9bb983a7c0b7cc943d5a265ebb615c2 100644 (file)
@@ -9,8 +9,8 @@ package org.opendaylight.openflowplugin.impl.services;
 
 import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.FutureCallback;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.openflowjava.protocol.api.connection.DeviceRequestFailedException;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
@@ -20,7 +20,7 @@ import org.opendaylight.openflowplugin.impl.services.util.RequestContextUtil;
 import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.EventsTimeCounter;
 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.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.ErrorType;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 
@@ -28,7 +28,7 @@ public abstract class AbstractRequestCallback<T> implements FutureCallback<OfHea
     private final RequestContext<T> context;
     private final Class<?> requestType;
     private final MessageSpy spy;
-    private EventIdentifier eventIdentifier;
+    private final EventIdentifier eventIdentifier;
 
     AbstractRequestCallback(final RequestContext<T> context,
                             final Class<?> requestType,
@@ -45,7 +45,7 @@ public abstract class AbstractRequestCallback<T> implements FutureCallback<OfHea
         context.close();
     }
 
-    protected final void spyMessage(@Nonnull final StatisticsGroup group) {
+    protected final void spyMessage(@NonNull final StatisticsGroup group) {
         spy.spyMessage(requestType, Preconditions.checkNotNull(group));
     }
 
@@ -54,7 +54,7 @@ public abstract class AbstractRequestCallback<T> implements FutureCallback<OfHea
     }
 
     @Override
-    public final void onFailure(@Nonnull final Throwable throwable) {
+    public final void onFailure(final Throwable throwable) {
         final RpcResultBuilder<T> builder;
         if (null != eventIdentifier) {
             EventsTimeCounter.markEnd(eventIdentifier);
@@ -65,11 +65,18 @@ public abstract class AbstractRequestCallback<T> implements FutureCallback<OfHea
                                                      err.getTypeString(),
                                                      err.getCodeString());
 
-            builder = RpcResultBuilder.<T>failed().withError(RpcError.ErrorType.APPLICATION, errorString, throwable);
+            builder = RpcResultBuilder.<T>failed().withError(ErrorType.APPLICATION, errorString, throwable);
             spyMessage(StatisticsGroup.TO_SWITCH_SUBMIT_FAILURE);
         } else {
-            builder = RpcResultBuilder.<T>failed()
-                    .withError(RpcError.ErrorType.APPLICATION, throwable.getMessage(), throwable);
+            if (throwable != null) {
+                builder = RpcResultBuilder.<T>failed()
+                        .withError(ErrorType.APPLICATION, throwable.getMessage(), throwable);
+            } else {
+                Throwable deviceReadFailedThrowable = new Throwable("Failed to read from device.");
+                builder = RpcResultBuilder.<T>failed()
+                        .withError(ErrorType.APPLICATION, deviceReadFailedThrowable.getMessage(),
+                                deviceReadFailedThrowable);
+            }
             spyMessage(StatisticsGroup.TO_SWITCH_SUBMIT_ERROR);
         }