OPNFLWPLUG-1087: ODL controller to provide view of openflow node reconciliation status
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / AbstractMultipartRequestOnTheFlyCallback.java
old mode 100644 (file)
new mode 100755 (executable)
index 1277c78..038612c
@@ -7,10 +7,9 @@
  */
 package org.opendaylight.openflowplugin.impl.services;
 
+import com.google.common.util.concurrent.Service;
 import java.util.Collections;
 import java.util.List;
-import java.util.Objects;
-import org.opendaylight.openflowplugin.api.openflow.OFPContext.ContextState;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceRegistry;
@@ -32,15 +31,16 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public abstract class AbstractMultipartRequestOnTheFlyCallback<T extends OfHeader> extends AbstractMultipartRequestCallback<T> {
+public abstract class AbstractMultipartRequestOnTheFlyCallback<T extends OfHeader>
+                                                        extends AbstractMultipartRequestCallback<T> {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractMultipartRequestOnTheFlyCallback.class);
     private final DeviceInfo deviceInfo;
     private final EventIdentifier doneEventIdentifier;
     private final TxFacade txFacade;
     private final MultipartWriterProvider statisticsWriterProvider;
     private final DeviceRegistry deviceRegistry;
-    private volatile ContextState gatheringState = ContextState.INITIALIZATION;
-    private ConvertorExecutor convertorExecutor;
+    private volatile Service.State gatheringState = Service.State.NEW;
+    private final ConvertorExecutor convertorExecutor;
 
     public AbstractMultipartRequestOnTheFlyCallback(final RequestContext<List<T>> context, Class<?> requestType,
                                                     final DeviceContext deviceContext,
@@ -49,7 +49,8 @@ public abstract class AbstractMultipartRequestOnTheFlyCallback<T extends OfHeade
                                                     final ConvertorExecutor convertorExecutor) {
         super(context, requestType, deviceContext, eventIdentifier);
         deviceInfo = deviceContext.getDeviceInfo();
-        doneEventIdentifier = new EventIdentifier(getMultipartType().name(), deviceContext.getDeviceInfo().getNodeId().toString());
+        doneEventIdentifier =
+                new EventIdentifier(getMultipartType().name(), deviceContext.getDeviceInfo().getNodeId().toString());
         txFacade = deviceContext;
         deviceRegistry = deviceContext;
         this.statisticsWriterProvider = statisticsWriterProvider;
@@ -57,18 +58,18 @@ public abstract class AbstractMultipartRequestOnTheFlyCallback<T extends OfHeade
     }
 
     @Override
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings({"unchecked", "checkstyle:IllegalCatch"})
     public void onSuccess(final OfHeader result) {
-        if (Objects.isNull(result)) {
+        if (result == null) {
             LOG.warn("Response received was null.");
 
-            if (!ContextState.TERMINATION.equals(gatheringState)) {
+            if (!Service.State.TERMINATED.equals(gatheringState)) {
                 endCollecting(true);
             }
 
             return;
-        } else if (ContextState.TERMINATION.equals(gatheringState)) {
-            LOG.warn("Unexpected response received: xid={}, {}", result.getXid(), result.getImplementedInterface());
+        } else if (Service.State.TERMINATED.equals(gatheringState)) {
+            LOG.warn("Unexpected response received: xid={}, {}", result.getXid(), result.implementedInterface());
             return;
         }
 
@@ -80,7 +81,7 @@ public abstract class AbstractMultipartRequestOnTheFlyCallback<T extends OfHeade
         } else {
             final T resultCast = (T) result;
 
-            if (ContextState.INITIALIZATION.equals(gatheringState)) {
+            if (Service.State.NEW.equals(gatheringState)) {
                 startCollecting();
             }
 
@@ -94,13 +95,15 @@ public abstract class AbstractMultipartRequestOnTheFlyCallback<T extends OfHeade
                                         .ifPresent(writer -> writer.write(reply, false));
                             } catch (final Exception ex) {
                                 LOG.warn("Stats processing of type {} for node {} failed during write-to-tx step",
-                                        getMultipartType(), deviceInfo.getLOGValue(), ex);
+                                        getMultipartType(), deviceInfo, ex);
                             }
                         });
             } catch (final Exception ex) {
                 LOG.warn("Unexpected exception occurred while translating response: {}.", result.getClass(), ex);
                 setResult(RpcResultBuilder.<List<T>>failed().withError(RpcError.ErrorType.APPLICATION,
-                        String.format("Unexpected exception occurred while translating response: %s. %s", result.getClass(), ex)).build());
+                        String.format("Unexpected exception occurred while translating response: %s. %s",
+                                      result.getClass(),
+                                      ex)).build());
                 endCollecting(false);
                 return;
             }
@@ -112,7 +115,7 @@ public abstract class AbstractMultipartRequestOnTheFlyCallback<T extends OfHeade
     }
 
     /**
-     * Get tx facade
+     * Get tx facade.
      * @return tx facade
      */
     protected TxFacade getTxFacade() {
@@ -120,11 +123,11 @@ public abstract class AbstractMultipartRequestOnTheFlyCallback<T extends OfHeade
     }
 
     /**
-     * Starts collecting of multipart data
+     * Starts collecting of multipart data.
      */
     private synchronized void startCollecting() {
         EventsTimeCounter.markStart(doneEventIdentifier);
-        gatheringState = ContextState.WORKING;
+        gatheringState = Service.State.RUNNING;
 
         final InstanceIdentifier<FlowCapableNode> instanceIdentifier = deviceInfo
                 .getNodeInstanceIdentifier()
@@ -136,28 +139,33 @@ public abstract class AbstractMultipartRequestOnTheFlyCallback<T extends OfHeade
                         getTxFacade(),
                         instanceIdentifier,
                         deviceRegistry.getDeviceFlowRegistry());
+                deviceRegistry.getDeviceFlowRegistry().processMarks();
                 break;
             case OFPMPMETERCONFIG:
                 StatisticsGatheringUtils.deleteAllKnownMeters(
                         getTxFacade(),
                         instanceIdentifier,
                         deviceRegistry.getDeviceMeterRegistry());
+                deviceRegistry.getDeviceMeterRegistry().processMarks();
                 break;
             case OFPMPGROUPDESC:
                 StatisticsGatheringUtils.deleteAllKnownGroups(
                         getTxFacade(),
                         instanceIdentifier,
                         deviceRegistry.getDeviceGroupRegistry());
+                deviceRegistry.getDeviceGroupRegistry().processMarks();
                 break;
+            default:
+                // no operation
         }
     }
 
     /**
-     * Ends collecting of multipart data
+     * Ends collecting of multipart data.
      * @param setResult set empty success result
      */
     private void endCollecting(final boolean setResult) {
-        gatheringState = ContextState.TERMINATION;
+        gatheringState = Service.State.TERMINATED;
         EventsTimeCounter.markEnd(doneEventIdentifier);
         EventsTimeCounter.markEnd(getEventIdentifier());
         spyMessage(MessageSpy.StatisticsGroup.FROM_SWITCH_TRANSLATE_OUT_SUCCESS);
@@ -178,13 +186,14 @@ public abstract class AbstractMultipartRequestOnTheFlyCallback<T extends OfHeade
             case OFPMPGROUPDESC:
                 deviceRegistry.getDeviceGroupRegistry().processMarks();
                 break;
+            default:
+                // no operation
         }
     }
 
     /**
-     * Get multipart type
+     * Get multipart type.
      * @return multipart type
      */
     protected abstract MultipartType getMultipartType();
-
 }