Merge "Bug 6088 - Threads problem on gathering statistics"
authormichal rehak <mirehak@cisco.com>
Tue, 21 Jun 2016 09:15:59 +0000 (09:15 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 21 Jun 2016 09:15:59 +0000 (09:15 +0000)
1  2 
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/MultipartRequestOnTheFlyCallback.java

index ee3c67bac0391d891b29df52a1b30e891252a22e,625a1eff39d4537080956859964bcab0d170aefa..dcb445b11e03db4717fcc91d1ab4f5b865730695
@@@ -12,7 -12,8 +12,7 @@@ import com.google.common.util.concurren
  import com.google.common.util.concurrent.ListenableFuture;
  import java.util.Collections;
  import java.util.List;
 -
 -import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
 +import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
  import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
  import org.opendaylight.openflowplugin.api.openflow.device.TxFacade;
  import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
@@@ -35,7 -36,7 +35,7 @@@ import org.slf4j.LoggerFactory
  final class MultipartRequestOnTheFlyCallback extends AbstractRequestCallback<List<MultipartReply>> {
      private static final Logger LOG = LoggerFactory.getLogger(MultipartRequestOnTheFlyCallback.class);
      private static final SinglePurposeMultipartReplyTranslator MULTIPART_REPLY_TRANSLATOR = new SinglePurposeMultipartReplyTranslator();
 -    private final DeviceState deviceState;
 +    private final DeviceInfo deviceInfo;
      private final DeviceFlowRegistry registry;
      private boolean virgin = true;
      private boolean finished = false;
                                              final Class<?> requestType,
                                              final MessageSpy messageSpy,
                                              final EventIdentifier eventIdentifier,
 -                                            final DeviceState deviceState,
 +                                            final DeviceInfo deviceInfo,
                                              final DeviceFlowRegistry registry,
                                              final TxFacade txFacade) {
          super(context, requestType, messageSpy, eventIdentifier);
  
 -        this.deviceState = deviceState;
 +        this.deviceInfo = deviceInfo;
          this.registry = registry;
          this.txFacade = txFacade;
  
          //TODO: this is focused on flow stats only - need more general approach if used for more than flow stats
 -        doneEventIdentifier = new EventIdentifier(MultipartType.OFPMPFLOW.name(), deviceState.getNodeId().toString());
 +        doneEventIdentifier = new EventIdentifier(MultipartType.OFPMPFLOW.name(), deviceInfo.getNodeId().toString());
      }
  
      public EventIdentifier getDoneEventIdentifier() {
  
              final MultipartReply singleReply = multipartReply;
              final List<? extends DataObject> multipartDataList = MULTIPART_REPLY_TRANSLATOR.translate(
 -                    deviceState.getFeatures().getDatapathId(), deviceState.getFeatures().getVersion(), singleReply);
 +                    deviceInfo.getDatapathId(), deviceInfo.getVersion(), singleReply);
              final Iterable<? extends DataObject> allMultipartData = multipartDataList;
  
              //TODO: following part is focused on flow stats only - need more general approach if used for more than flow stats
              ListenableFuture<Void> future;
              if (virgin) {
 -                future = StatisticsGatheringUtils.deleteAllKnownFlows(deviceState, registry, txFacade);
 +                future = StatisticsGatheringUtils.deleteAllKnownFlows(deviceInfo, registry, txFacade);
                  virgin = false;
              } else {
                  future = Futures.immediateFuture(null);
                  @Override
                  public Void apply(final Void input) {
                      StatisticsGatheringUtils.writeFlowStatistics((Iterable<FlowsStatisticsUpdate>) allMultipartData,
 -                            deviceState, registry, txFacade);
 +                            deviceInfo, registry, txFacade);
  
                      if (!multipartReply.getFlags().isOFPMPFREQMORE()) {
                          endCollecting();
          EventsTimeCounter.markEnd(getEventIdentifier());
          final RpcResult<List<MultipartReply>> rpcResult = RpcResultBuilder.success(Collections.<MultipartReply>emptyList()).build();
          spyMessage(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_TRANSLATE_OUT_SUCCESS);
-         setResult(rpcResult);
          txFacade.submitTransaction();
+         setResult(rpcResult);
          finished = true;
      }
  }