X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fservices%2FAbstractRequestCallback.java;h=4544e933f9bb983a7c0b7cc943d5a265ebb615c2;hb=777c94332871b8c34f56f7f2010de1536cb759ba;hp=95c0071e750c7fa374a0aa8f5f245cf523502086;hpb=b856e3c6051c1b9a8962fbcac1c3f34b0148f441;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/AbstractRequestCallback.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/AbstractRequestCallback.java index 95c0071e75..4544e933f9 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/AbstractRequestCallback.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/AbstractRequestCallback.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the @@ -9,37 +9,31 @@ 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; import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy; -import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy.STATISTIC_GROUP; +import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy.StatisticsGroup; +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; -abstract class AbstractRequestCallback implements FutureCallback { +public abstract class AbstractRequestCallback implements FutureCallback { private final RequestContext context; private final Class requestType; private final MessageSpy spy; - private EventIdentifier eventIdentifier; + private final EventIdentifier eventIdentifier; - - protected AbstractRequestCallback(final RequestContext context, final Class requestType, final MessageSpy spy) { - this.context = Preconditions.checkNotNull(context); - this.requestType = Preconditions.checkNotNull(requestType); - this.spy = Preconditions.checkNotNull(spy); - } - - protected AbstractRequestCallback(final RequestContext context, - final Class requestType, - final MessageSpy spy, - final EventIdentifier eventIdentifier) { + AbstractRequestCallback(final RequestContext context, + final Class requestType, + final MessageSpy spy, + final EventIdentifier eventIdentifier) { this.context = Preconditions.checkNotNull(context); this.requestType = Preconditions.checkNotNull(requestType); this.spy = Preconditions.checkNotNull(spy); @@ -51,7 +45,7 @@ abstract class AbstractRequestCallback implements FutureCallback { context.close(); } - protected final void spyMessage(@Nonnull final STATISTIC_GROUP group) { + protected final void spyMessage(@NonNull final StatisticsGroup group) { spy.spyMessage(requestType, Preconditions.checkNotNull(group)); } @@ -60,23 +54,33 @@ abstract class AbstractRequestCallback implements FutureCallback { } @Override - public final void onFailure(final Throwable t) { + public final void onFailure(final Throwable throwable) { final RpcResultBuilder builder; if (null != eventIdentifier) { EventsTimeCounter.markEnd(eventIdentifier); } - if (t instanceof DeviceRequestFailedException) { - final Error err = ((DeviceRequestFailedException) t).getError(); - final String errorString = String.format("Device reported error type %s code %s", err.getTypeString(), err.getCodeString()); + if (throwable instanceof DeviceRequestFailedException) { + final Error err = ((DeviceRequestFailedException) throwable).getError(); + final String errorString = String.format("Device reported error type %s code %s", + err.getTypeString(), + err.getCodeString()); - builder = RpcResultBuilder.failed().withError(RpcError.ErrorType.APPLICATION, errorString, t); - spyMessage(MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_FAILURE); + builder = RpcResultBuilder.failed().withError(ErrorType.APPLICATION, errorString, throwable); + spyMessage(StatisticsGroup.TO_SWITCH_SUBMIT_FAILURE); } else { - builder = RpcResultBuilder.failed().withError(RpcError.ErrorType.APPLICATION, t.getMessage(), t); - spyMessage(MessageSpy.STATISTIC_GROUP.TO_SWITCH_SUBMIT_ERROR); + if (throwable != null) { + builder = RpcResultBuilder.failed() + .withError(ErrorType.APPLICATION, throwable.getMessage(), throwable); + } else { + Throwable deviceReadFailedThrowable = new Throwable("Failed to read from device."); + builder = RpcResultBuilder.failed() + .withError(ErrorType.APPLICATION, deviceReadFailedThrowable.getMessage(), + deviceReadFailedThrowable); + } + spyMessage(StatisticsGroup.TO_SWITCH_SUBMIT_ERROR); } context.setResult(builder.build()); - RequestContextUtil.closeRequstContext(context); + RequestContextUtil.closeRequestContext(context); } }