Source:
<code>public void collectMetrics(@Observes @Dequeue VariantMetricInformation variantMetricInformation) { PushMessageInformation pushMessageInformation = metricsService.getPushMessageInformation(variantMetricInformation.getPushMessageInformation().getId()); <START> metricsService.lock(pushMessageInformation); <END> final String variantID = variantMetricInformation.getVariantID(); pushMessageInformation.setTotalReceivers(pushMessageInformation.getTotalReceivers() + variantMetricInformation.getReceivers()); int loadedBatches = countLoadedBatches(variantID); variantMetricInformation.setServedBatches(1); variantMetricInformation.setTotalBatches(variantMetricInformation.getTotalBatches() + loadedBatches); boolean updatedExisting = false; for (VariantMetricInformation existingMetric : pushMessageInformation.getVariantInformations()) { if (variantMetricInformation.getVariantID().equals(existingMetric.getVariantID())) { updatedExisting = true; updateExistingMetric(existingMetric, variantMetricInformation); variantMetricInformation = existingMetric; break; } } if (!updatedExisting) { pushMessageInformation.addVariantInformations(variantMetricInformation); } metricsService.updatePushMessageInformation(pushMessageInformation); if (variantMetricInformation.getTotalBatches() == variantMetricInformation.getServedBatches()) { if (areAllBatchesLoaded(variantID)) { pushMessageInformation.setServedVariants(pushMessageInformation.getServedVariants() + 1); logger.fine(String.format("All batches for variant %s were processed", variantMetricInformation.getVariantID())); variantCompleted.fire(new VariantCompleted(pushMessageInformation.getId(), variantMetricInformation.getVariantID())); if (pushMessageInformation.getServedVariants() == pushMessageInformation.getTotalVariants()) { logger.fine(String.format("All batches for application %s were processed", pushMessageInformation.getId())); pushMessageCompleted.fire(new PushMessageCompleted(pushMessageInformation.getId())); } } } }</code><technical_language>Do need lock hand? Optimistic locking default</technical_language>

Target:
public void collectMetrics(@Observes @Dequeue VariantMetricInformation variantMetricInformation) { PushMessageInformation pushMessageInformation = metricsService.getPushMessageInformation(variantMetricInformation.getPushMessageInformation().getId()); metricsService.lock(pushMessageInformation); final String variantID = variantMetricInformation.getVariantID(); pushMessageInformation.setTotalReceivers(pushMessageInformation.getTotalReceivers() + variantMetricInformation.getReceivers()); int loadedBatches = countLoadedBatches(variantID); variantMetricInformation.setServedBatches(1); variantMetricInformation.setTotalBatches(variantMetricInformation.getTotalBatches() + loadedBatches); boolean updatedExisting = false; for (VariantMetricInformation existingMetric : pushMessageInformation.getVariantInformations()) { if (variantMetricInformation.getVariantID().equals(existingMetric.getVariantID())) { updatedExisting = true; updateExistingMetric(existingMetric, variantMetricInformation); variantMetricInformation = existingMetric; break; } } if (!updatedExisting) { pushMessageInformation.addVariantInformations(variantMetricInformation); } metricsService.updatePushMessageInformation(pushMessageInformation); if (variantMetricInformation.getTotalBatches() == variantMetricInformation.getServedBatches()) { if (areAllBatchesLoaded(variantID)) { pushMessageInformation.setServedVariants(pushMessageInformation.getServedVariants() + 1); logger.fine(String.format("All batches for variant %s were processed", variantMetricInformation.getVariantID())); variantCompleted.fire(new VariantCompletedEvent(pushMessageInformation.getId(), variantMetricInformation.getVariantID())); if (pushMessageInformation.getServedVariants() == pushMessageInformation.getTotalVariants()) { logger.fine(String.format("All batches for application %s were processed", pushMessageInformation.getId())); pushMessageCompleted.fire(new PushMessageCompletedEvent(pushMessageInformation.getId())); } } } }