branch feature/8145-2 updated (364af86 -> 78784e8)
This is an automated email from the git hooks/post-receive script. New change to branch feature/8145-2 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git from 364af86 Gestion du nettoyage du cache avant la suppresion de lot ou de trait new f30734c Amélioration du cache new 78784e8 Passage en log debug sur le cache The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 78784e8a4646fac9b27688edf1543a878b026d92 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Mar 21 03:44:44 2016 +0100 Passage en log debug sur le cache commit f30734ce95b47faa2862d3a3292497d1aacc7b6d Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Mar 21 03:44:31 2016 +0100 Amélioration du cache Summary of changes: .../ifremer/tutti/service/PersistenceService.java | 95 ++++++++++-- .../service/samplingCache/CruiseSamplingCache.java | 172 +++++++++++++++------ .../samplingCache/CruiseSamplingCacheLoader.java | 40 ++++- .../samplingCache/CruiseSamplingInternalCache.java | 146 ++++------------- .../src/main/filtered-resources/log4j.properties | 3 +- 5 files changed, 272 insertions(+), 184 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/8145-2 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit f30734ce95b47faa2862d3a3292497d1aacc7b6d Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Mar 21 03:44:31 2016 +0100 Amélioration du cache --- .../ifremer/tutti/service/PersistenceService.java | 95 ++++++++++-- .../service/samplingCache/CruiseSamplingCache.java | 172 +++++++++++++++------ .../samplingCache/CruiseSamplingCacheLoader.java | 40 ++++- .../samplingCache/CruiseSamplingInternalCache.java | 146 ++++------------- 4 files changed, 271 insertions(+), 182 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java index 4312a55..f0eab54 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java @@ -50,6 +50,7 @@ import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocols; +import fr.ifremer.tutti.persistence.entities.protocol.Zone; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.Gear; import fr.ifremer.tutti.persistence.entities.referential.Gears; @@ -66,6 +67,7 @@ import fr.ifremer.tutti.persistence.model.ProgramDataModel; import fr.ifremer.tutti.persistence.service.TuttiPersistenceServiceLocator; import fr.ifremer.tutti.persistence.service.UpdateSchemaContextSupport; import fr.ifremer.tutti.service.samplingCache.CruiseSamplingCache; +import fr.ifremer.tutti.service.samplingCache.CruiseSamplingCacheLoader; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; @@ -619,8 +621,7 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer driver.init(); } - TIME_LOG.log(t0, "Persistence driver *" + - driver.getImplementationName() + "* opened."); + TIME_LOG.log(t0, "Persistence driver *" + driver.getImplementationName() + "* opened."); } @Override @@ -636,8 +637,7 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer IOUtils.closeQuietly(driver); - TIME_LOG.log(t0, "Persistence driver *" + - driverName + "* closed."); + TIME_LOG.log(t0, "Persistence driver *" + driverName + "* closed."); } //------------------------------------------------------------------------// @@ -1304,9 +1304,7 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer if (Objects.equals(bean.getGearShootingStartDate(), bean.getGearShootingEndDate())) { bean.setGearShootingEndDate(null); } - FishingOperation fishingOperation = driver.createFishingOperation(bean); - //FIXME Update samplingCache - return fishingOperation; + return driver.createFishingOperation(bean); } @Override @@ -1315,8 +1313,44 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer if (Objects.equals(bean.getGearShootingStartDate(), bean.getGearShootingEndDate())) { bean.setGearShootingEndDate(null); } + Optional<CruiseSamplingCache> optionalCruiseSamplingCache = getOptionalCruiseSamplingCache(); + + boolean reloadSamplingCache = false; + + if (optionalCruiseSamplingCache.isPresent()) { + + FishingOperation oldFishingOperation = getFishingOperation(bean.getIdAsInt()); + + CruiseSamplingCache cruiseSamplingCache = optionalCruiseSamplingCache.get(); + + Optional<Zone> oldOptionalZone = cruiseSamplingCache.tryFindZone(oldFishingOperation); + Optional<Zone> newOptionalZone = cruiseSamplingCache.tryFindZone(bean); + + if (!Objects.equals(oldOptionalZone, newOptionalZone)) { + + if (log.isInfoEnabled()) { + log.info("Zone has changed for fishingOperation: " + bean.getId() + ", remove fishing operation from cruiseSamplingCache."); + } + // les strates ou sous-strates ont changées, il faut recalculer le cache des échantillons + reloadSamplingCache = true; + cruiseSamplingCache.removeFishingOperation(oldFishingOperation); + + } + + } FishingOperation fishingOperation = driver.saveFishingOperation(bean); - //FIXME Update samplingCache + + if (reloadSamplingCache) { + + if (log.isInfoEnabled()) { + log.info("Zone has changed for fishingOperation: " + bean.getId() + ", recompute fishing operation from cruiseSamplingCache."); + } + + CruiseSamplingCache cruiseSamplingCache = optionalCruiseSamplingCache.get(); + CruiseSamplingCacheLoader cruiseSamplingCacheLoader = new CruiseSamplingCacheLoader(this, context.getService(DecoratorService.class), null); + cruiseSamplingCacheLoader.loadCruiseSamplingCacheForFishingOperation(cruiseSamplingCache, fishingOperation); + + } return fishingOperation; } @@ -1329,10 +1363,16 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer @Override public void deleteFishingOperation(Integer id) { - Optional<CruiseSamplingCache> optionalCruiseSamplingCache = context.getDataContext().getOptionalCruiseSamplingCache(); + Optional<CruiseSamplingCache> optionalCruiseSamplingCache = getOptionalCruiseSamplingCache(); if (optionalCruiseSamplingCache.isPresent()) { + + CruiseSamplingCache cruiseSamplingCache = optionalCruiseSamplingCache.get(); + if (log.isInfoEnabled()) { + log.info("Remove fishing operation: " + id + " from cruiseSamplingCache: " + cruiseSamplingCache); + } FishingOperation fishingOperation = getFishingOperation(id); - optionalCruiseSamplingCache.get().removeFishingOperation(fishingOperation); + cruiseSamplingCache.removeFishingOperation(fishingOperation); + } driver.deleteFishingOperation(id); } @@ -1496,8 +1536,7 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer } @Override - public List<SpeciesBatchFrequency> saveBenthosBatchFrequency(Integer benthosBatchId, - List<SpeciesBatchFrequency> frequencies) { + public List<SpeciesBatchFrequency> saveBenthosBatchFrequency(Integer benthosBatchId, List<SpeciesBatchFrequency> frequencies) { return driver.saveBenthosBatchFrequency(benthosBatchId, frequencies); } @@ -1589,8 +1628,7 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer } @Override - public List<IndividualObservationBatch> saveBatchIndividualObservation(Integer batchId, - List<IndividualObservationBatch> individualObservation) { + public List<IndividualObservationBatch> saveBatchIndividualObservation(Integer batchId, List<IndividualObservationBatch> individualObservation) { return driver.saveBatchIndividualObservation(batchId, individualObservation); } @@ -1605,21 +1643,44 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer } protected void beforeDeleteBatch(Integer id, boolean addBatchId) { - Optional<CruiseSamplingCache> optionalCruiseSamplingCache = context.getDataContext().getOptionalCruiseSamplingCache(); + + Optional<CruiseSamplingCache> optionalCruiseSamplingCache = getOptionalCruiseSamplingCache(); if (optionalCruiseSamplingCache.isPresent()) { - FishingOperation fishingOperation = context.getDataContext().getFishingOperation(); + CruiseSamplingCache cruiseSamplingCache = optionalCruiseSamplingCache.get(); + + FishingOperation fishingOperation = context.getDataContext().getFishingOperation(); + Integer fishingOperationId = fishingOperation.getIdAsInt(); + Optional<Zone> optionalZone = cruiseSamplingCache.tryFindZone(fishingOperation); + Set<Integer> batchIds = new LinkedHashSet<>(); if (addBatchId) { batchIds.add(id); } batchIds.addAll(getBatchChildIds(id)); + batchIds.forEach(speciesBatchId -> { + List<IndividualObservationBatch> allIndividualObservationBatchsForBatch = getAllIndividualObservationBatchsForBatch(id); - cruiseSamplingCache.removeIndividualObservations(fishingOperation, allIndividualObservationBatchsForBatch); + + if (!allIndividualObservationBatchsForBatch.isEmpty()) { + + if (log.isInfoEnabled()) { + log.info("Remove for species or benthos batch: " + id + " - " + allIndividualObservationBatchsForBatch.size() + " individual observations from cruiseSamplingCache: " + cruiseSamplingCache); + } + + cruiseSamplingCache.removeIndividualObservations(fishingOperationId, optionalZone, allIndividualObservationBatchsForBatch); + + } + }); } + + } + + private Optional<CruiseSamplingCache> getOptionalCruiseSamplingCache() { + return context.getDataContext().getOptionalCruiseSamplingCache(); } } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/samplingCache/CruiseSamplingCache.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/samplingCache/CruiseSamplingCache.java index c5ed6fc..32e03f1 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/samplingCache/CruiseSamplingCache.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/samplingCache/CruiseSamplingCache.java @@ -179,12 +179,16 @@ public class CruiseSamplingCache implements Closeable { /** * Ajout d'un échantillon dans le cache. * - * @param fishingOperation l'opération de pêche contenant l'observation individuelle + * @param fishingOperationId l'identifiant de l'opération de pêche concernée + * @param optionalZone la zone (facultative) de l'opération de pêche concernée * @param individualObservationBatch l'observation individuelle à ajouter au cache */ - public void addIndividualObservation(FishingOperation fishingOperation, IndividualObservationBatch individualObservationBatch) { + public void addIndividualObservation(Integer fishingOperationId, + Optional<Zone> optionalZone, + IndividualObservationBatch individualObservationBatch) { - Objects.requireNonNull(fishingOperation); + Objects.requireNonNull(fishingOperationId); + Objects.requireNonNull(optionalZone); Objects.requireNonNull(individualObservationBatch); Species species = individualObservationBatch.getSpecies(); @@ -192,10 +196,11 @@ public class CruiseSamplingCache implements Closeable { Boolean maturity = null; Float lengthStep = individualObservationBatch.getSize(); + Objects.requireNonNull(lengthStep); CaracteristicQualitativeValue gender = individualObservationBatch.getCaracteristics().getQualitativeValue(sexCaracteristic); - addIndividualObservation(fishingOperation, species, gender, maturity, lengthStep); + addIndividualObservation(fishingOperationId, optionalZone, species, gender, maturity, lengthStep); } @@ -217,6 +222,32 @@ public class CruiseSamplingCache implements Closeable { Objects.requireNonNull(fishingOperation); Objects.requireNonNull(species); + Optional<Zone> optionalZone = tryFindZone(fishingOperation); + + addIndividualObservation(fishingOperation.getIdAsInt(), optionalZone, species, gender, maturity, lengthStep); + + } + + /** + * Ajout d'un échantillon dans le cache. + * + * @param fishingOperationId l'identifiant de l'opération de pêche concernée + * @param optionalZone la zone (facultative) de l'opération de pêche concernée + * @param species l'espèces concernée + * @param gender le sexe de l'échantillon (peut-être null) + * @param maturity la maturité de l'échantillon (peut-être null) + * @param lengthStep la classe de taille de l'échantillon + */ + public void addIndividualObservation(Integer fishingOperationId, + Optional<Zone> optionalZone, + Species species, + CaracteristicQualitativeValue gender, + Boolean maturity, + float lengthStep) { + + Objects.requireNonNull(fishingOperationId); + Objects.requireNonNull(species); + Optional<CalcifiedPiecesSamplingDefinition> cpsDefinitionOpt = getCalcifiedPiecesSamplingDefinition(species, maturity, lengthStep); if (cpsDefinitionOpt.isPresent()) { @@ -234,17 +265,16 @@ public class CruiseSamplingCache implements Closeable { if (!cpsDefinition.isSex()) { gender = null; } - CruiseSamplingInternalCache.CruiseSamplingInternalCacheKey samplingKey = CruiseSamplingInternalCache.newCruiseSamplingInternalCacheKey(species, gender, maturity, lengthStep); - - Optional<Zone> zone = findZone(fishingOperation); + String samplingKey = CruiseSamplingInternalCache.createSamplingKey(species, gender, maturity, lengthStep); int totalValue = totalCruiseCache.increment(samplingKey); int zoneValue = 0; - if (zone.isPresent()) { - CruiseSamplingInternalCache.ZoneCruiseSamplingInternalCacheKey zoneKey = samplingKey.toZoneKey(zone.get()); + if (optionalZone.isPresent()) { + String zoneKey = CruiseSamplingInternalCache.addPrefixKey(optionalZone.get().getId(), samplingKey); zoneValue = zoneCache.increment(zoneKey); } - CruiseSamplingInternalCache.FishingOperationCruiseSamplingInternalCacheKey operationKey = samplingKey.toFishingOperationKey(fishingOperation); + String operationKey = CruiseSamplingInternalCache.addPrefixKey(fishingOperationId, samplingKey); + int operationValue = operationCache.increment(operationKey); if (log.isInfoEnabled()) { @@ -265,29 +295,32 @@ public class CruiseSamplingCache implements Closeable { /** * Suppression d'un échantillon du cache. * - * @param fishingOperation l'opération de pêche concernée + * @param fishingOperationId l'identifiant de l'opération de pêche concernée + * @param optionalZone la zone (facultative) de l'opération de pêche concernée * @param individualObservationBatches les observations individuelles à supprimer du cache */ - public void removeIndividualObservations(FishingOperation fishingOperation, Collection<IndividualObservationBatch> individualObservationBatches) { + public void removeIndividualObservations(Integer fishingOperationId, + Optional<Zone> optionalZone, + Collection<IndividualObservationBatch> individualObservationBatches) { - Objects.requireNonNull(fishingOperation); + Objects.requireNonNull(fishingOperationId); + Objects.requireNonNull(optionalZone); Objects.requireNonNull(individualObservationBatches); individualObservationBatches.forEach(individualObservationBatch -> { - Species species = individualObservationBatch.getSpecies(); Objects.requireNonNull(species); Boolean maturity = null; Float lengthStep = individualObservationBatch.getSize(); + Objects.requireNonNull(lengthStep); CaracteristicQualitativeValue gender = individualObservationBatch.getCaracteristics().getQualitativeValue(sexCaracteristic); - removeIndividualObservation(fishingOperation, species, gender, maturity, lengthStep); + removeIndividualObservation(fishingOperationId, optionalZone, species, gender, maturity, lengthStep); }); - } /** @@ -309,6 +342,34 @@ public class CruiseSamplingCache implements Closeable { Objects.requireNonNull(species); Objects.requireNonNull(lengthStep); + Optional<Zone> optionalZone = tryFindZone(fishingOperation); + + removeIndividualObservation(fishingOperation.getIdAsInt(), optionalZone, species, gender, maturity, lengthStep); + + } + + /** + * Suppression d'un échantillon du cache. + * + * @param fishingOperationId l'identifiant de l'opération de pêche concernée + * @param optionalZone la zone (facultative) de l'opération de pêche concernée + * @param species l'espèces concernée + * @param gender le sexe de l'échantillon (peut-être null) + * @param maturity la maturité de l'échantillon (peut-être null) + * @param lengthStep la classe de taille de l'échantillon + */ + public void removeIndividualObservation(Integer fishingOperationId, + Optional<Zone> optionalZone, + Species species, + CaracteristicQualitativeValue gender, + Boolean maturity, + Float lengthStep) { + + Objects.requireNonNull(fishingOperationId); + Objects.requireNonNull(optionalZone); + Objects.requireNonNull(species); + Objects.requireNonNull(lengthStep); + Optional<CalcifiedPiecesSamplingDefinition> cpsDefinitionOpt = getCalcifiedPiecesSamplingDefinition(species, maturity, lengthStep); if (cpsDefinitionOpt.isPresent()) { @@ -326,24 +387,24 @@ public class CruiseSamplingCache implements Closeable { gender = null; } - CruiseSamplingInternalCache.CruiseSamplingInternalCacheKey samplingKey = CruiseSamplingInternalCache.newCruiseSamplingInternalCacheKey(species, gender, maturity, lengthStep); - - Optional<Zone> zone = findZone(fishingOperation); + String samplingKey = CruiseSamplingInternalCache.createSamplingKey(species, gender, maturity, lengthStep); int totalValue = totalCruiseCache.decrement(samplingKey); int zoneValue = 0; - if (zone.isPresent()) { - CruiseSamplingInternalCache.ZoneCruiseSamplingInternalCacheKey zoneKey = samplingKey.toZoneKey(zone.get()); + if (optionalZone.isPresent()) { + String zoneKey = CruiseSamplingInternalCache.addPrefixKey(optionalZone.get().getId(), samplingKey); zoneValue = zoneCache.decrement(zoneKey); } - CruiseSamplingInternalCache.FishingOperationCruiseSamplingInternalCacheKey operationKey = samplingKey.toFishingOperationKey(fishingOperation); + String operationKey = CruiseSamplingInternalCache.addPrefixKey(fishingOperationId, samplingKey); + int operationValue = operationCache.decrement(operationKey); if (log.isInfoEnabled()) { - log.info("removeIndividualObservation " + samplingKey + " => op " + operationValue + " / zone " + zoneValue + " / cruise " + totalValue); + log.info("remove individual observation " + samplingKey + " ⇒ op " + operationValue + " / zone " + zoneValue + " / cruise " + totalValue); } } } + } /** @@ -355,18 +416,52 @@ public class CruiseSamplingCache implements Closeable { Objects.requireNonNull(fishingOperation); + String fishingOperationId = fishingOperation.getId(); + + if (log.isInfoEnabled()) { + log.info("Remove fishing operation: " + fishingOperationId + " from CruiseSamplingCache: " + this); + } + // suppression de toutes les entrées du cache des opérations (et récupération des clefs) - Set<String> removedKeys = operationCache.removeAllWhereKeyStartingWith(fishingOperation.getId()); + Set<String> removedKeys = operationCache.removeAllWhereKeyStartingWith(fishingOperationId); + + if (log.isInfoEnabled()) { + log.info("Fishing operation: " + fishingOperationId + " removed from operationCache: " + operationCache.size()); + } removedKeys.forEach(totalCruiseCache::decrement); - Optional<Zone> zone = findZone(fishingOperation); + if (log.isInfoEnabled()) { + log.info("Fishing operation: " + fishingOperationId + " removed from totalCruiseCache: " + totalCruiseCache.size()); + } + + Optional<Zone> optionalZone = tryFindZone(fishingOperation); + + if (optionalZone.isPresent()) { + String zoneId = optionalZone.get().getId(); + removedKeys.forEach(key -> zoneCache.decrementIfExist(CruiseSamplingInternalCache.addPrefixKey(zoneId, key))); + + if (log.isInfoEnabled()) { + log.info("Fishing operation: " + fishingOperationId + " removed from zoneCache: " + zoneCache.size()); + } + } - if (zone.isPresent()) { - String id = zone.get().getId(); - removedKeys.forEach(key -> zoneCache.decrementIfExist(CruiseSamplingInternalCache.addPrefixKey(id, key))); + if (log.isInfoEnabled()) { + log.info("Fishing operation: " + fishingOperationId + " removed from CruiseSamplingCache: " + this); } - + + } + + public Optional<Zone> tryFindZone(FishingOperation operation) { + Optional<Zone> result; + if (operation.getSubStrata() != null) { + result = Optional.ofNullable(zonesByLocations.get(operation.getSubStrata())); + } else if (operation.getStrata() != null) { + result = Optional.ofNullable(zonesByLocations.get(operation.getStrata())); + } else { + result = Optional.empty(); + } + return result; } public void addSamplingListener(SamplingListener listener) { @@ -387,25 +482,6 @@ public class CruiseSamplingCache implements Closeable { .findFirst(); } - protected Optional<Zone> findZone(FishingOperation operation) { - - Optional<Zone> result; - - if (operation.getSubStrata() != null) { - - result = Optional.ofNullable(zonesByLocations.get(operation.getSubStrata())); - - } else if (operation.getStrata() != null) { - - result = Optional.ofNullable(zonesByLocations.get(operation.getStrata())); - - } else { - result = Optional.empty(); - } - - return result; - } - protected int getSamplingNumber(int value, int interval) { return 1 + (value - 1) / interval; } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/samplingCache/CruiseSamplingCacheLoader.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/samplingCache/CruiseSamplingCacheLoader.java index b7edd93..39f5ad6 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/samplingCache/CruiseSamplingCacheLoader.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/samplingCache/CruiseSamplingCacheLoader.java @@ -4,6 +4,7 @@ import fr.ifremer.tutti.persistence.ProgressionModel; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.IndividualObservationBatch; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; +import fr.ifremer.tutti.persistence.entities.protocol.Zone; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.service.PersistenceService; @@ -12,6 +13,7 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; import java.util.List; +import java.util.Optional; /** * Pour charger le cache. @@ -51,7 +53,6 @@ public class CruiseSamplingCacheLoader { log.info("Loading cruise sampling cache: " + cruiseSamplingCache); } - Decorator<FishingOperation> fishingOperationDecorator = decoratorService.getDecoratorByType(FishingOperation.class); persistenceService.getAllFishingOperationIds(cruiseId).forEach(fishingOperationId -> { @@ -63,8 +64,10 @@ public class CruiseSamplingCacheLoader { List<IndividualObservationBatch> allIndividualObservationBatchsForFishingOperation = persistenceService.getAllIndividualObservationBatchsForFishingOperation(fishingOperationId); + Optional<Zone> optionalZone = cruiseSamplingCache.tryFindZone(fishingOperation); + allIndividualObservationBatchsForFishingOperation.forEach( - individualObservationBatch -> cruiseSamplingCache.addIndividualObservation(fishingOperation, individualObservationBatch)); + individualObservationBatch -> cruiseSamplingCache.addIndividualObservation(fishingOperationId, optionalZone, individualObservationBatch)); }); @@ -81,4 +84,37 @@ public class CruiseSamplingCacheLoader { } } + + public void loadCruiseSamplingCacheForFishingOperation(CruiseSamplingCache cruiseSamplingCache, FishingOperation fishingOperation) { + + cruiseSamplingCache.setLoading(true); + + try { + + Integer fishingOperationId = fishingOperation.getIdAsInt(); + + Optional<Zone> optionalZone = cruiseSamplingCache.tryFindZone(fishingOperation); + + if (log.isInfoEnabled()) { + log.info("Loading cruise sampling cache for fishing operation: " + fishingOperationId + " - " + cruiseSamplingCache); + } + + List<IndividualObservationBatch> allIndividualObservationBatchsForFishingOperation = + persistenceService.getAllIndividualObservationBatchsForFishingOperation(fishingOperationId); + + allIndividualObservationBatchsForFishingOperation.forEach( + individualObservationBatch -> cruiseSamplingCache.addIndividualObservation(fishingOperationId, optionalZone, individualObservationBatch)); + + if (log.isInfoEnabled()) { + log.info("Cruise sampling cache loaded for fishing operation: " + fishingOperationId + " - " + cruiseSamplingCache); + } + + } finally { + + cruiseSamplingCache.setLoading(false); + + } + + } + } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/samplingCache/CruiseSamplingInternalCache.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/samplingCache/CruiseSamplingInternalCache.java index c12dda1..4e3a2e4 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/samplingCache/CruiseSamplingInternalCache.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/samplingCache/CruiseSamplingInternalCache.java @@ -1,7 +1,5 @@ package fr.ifremer.tutti.service.samplingCache; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.persistence.entities.protocol.Zone; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; import org.apache.commons.lang3.mutable.MutableInt; @@ -9,6 +7,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.io.Closeable; +import java.io.Serializable; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map; @@ -27,40 +26,55 @@ class CruiseSamplingInternalCache implements Closeable { /** Logger. */ private static final Log log = LogFactory.getLog(CruiseSamplingInternalCache.class); - public static String addPrefixKey(String prefix, String key) { - return prefix + CruiseSamplingInternalCacheKey.KEY_SEPARATOR + key; - } - - private final Map<String, MutableInt> data = new TreeMap<>(); + private static final String KEY_SEPARATOR = "#"; - public static CruiseSamplingInternalCacheKey newCruiseSamplingInternalCacheKey(Species species, CaracteristicQualitativeValue gender, Boolean maturity, Float lengthStep) { + public static String createSamplingKey(Species species, CaracteristicQualitativeValue gender, Boolean maturity, Float lengthStep) { Objects.requireNonNull(species); Objects.requireNonNull(lengthStep); - return new CruiseSamplingInternalCacheKey(species, gender, maturity, lengthStep); + return species.getReferenceTaxonId() + + KEY_SEPARATOR + (gender == null ? null : gender.getId()) + + KEY_SEPARATOR + maturity + + KEY_SEPARATOR + lengthStep; } - public int increment(CruiseSamplingInternalCacheKey samplingKey) { - MutableInt value = data.computeIfAbsent(samplingKey.toString(), s -> new MutableInt(0)); - value.increment(); - return value.intValue(); + public static String addPrefixKey(Serializable prefix, String key) { + Objects.requireNonNull(prefix); + Objects.requireNonNull(key); + return prefix + KEY_SEPARATOR + key; } - public int decrement(CruiseSamplingInternalCacheKey samplingKey) { - return decrement(samplingKey.toString()); + private final Map<String, MutableInt> data = new TreeMap<>(); + + public int increment(String samplingKey) { + Objects.requireNonNull(samplingKey); + MutableInt value = data.computeIfAbsent(samplingKey, s -> new MutableInt(0)); + value.increment(); + if (log.isDebugEnabled()) { + log.debug(samplingKey + " → " + value); + } + return value.intValue(); } public int decrement(String samplingKey) { + Objects.requireNonNull(samplingKey); MutableInt value = data.get(samplingKey); value.decrement(); + if (log.isDebugEnabled()) { + log.debug(samplingKey + " → " + value); + } return value.intValue(); } public Integer decrementIfExist(String samplingKey) { + Objects.requireNonNull(samplingKey); Integer result = null; MutableInt value = data.get(samplingKey); if (value != null) { value.decrement(); result = value.intValue(); + if (log.isDebugEnabled()) { + log.debug(samplingKey + " → " + value); + } } return result; } @@ -84,7 +98,8 @@ class CruiseSamplingInternalCache implements Closeable { * @return l'ensemble des clefs supprimées du cache (amputées du préfixe de concordance). */ public Set<String> removeAllWhereKeyStartingWith(String id) { - String keyPrefix = id + CruiseSamplingInternalCacheKey.KEY_SEPARATOR; + Objects.requireNonNull(id); + String keyPrefix = addPrefixKey(id, ""); if (log.isDebugEnabled()) { log.debug("Ask to remove all keys starting with: " + keyPrefix); } @@ -106,103 +121,4 @@ class CruiseSamplingInternalCache implements Closeable { return result; } - /** - * Représente la clef d'un objet du cache. - * - * Created on 19/03/16. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.5 - */ - static class CruiseSamplingInternalCacheKey { - - protected static final String KEY_SEPARATOR = "#"; - - private final Species species; - private final CaracteristicQualitativeValue gender; - private final Boolean maturity; - private final Float lengthStep; - - CruiseSamplingInternalCacheKey(Species species, CaracteristicQualitativeValue gender, Boolean maturity, Float lengthStep) { - Objects.requireNonNull(species); - Objects.requireNonNull(lengthStep); - - this.species = species; - this.gender = gender; - this.maturity = maturity; - this.lengthStep = lengthStep; - } - - CruiseSamplingInternalCacheKey(CruiseSamplingInternalCacheKey cruiseSamplingInternalCacheKey) { - this(cruiseSamplingInternalCacheKey.species, - cruiseSamplingInternalCacheKey.gender, - cruiseSamplingInternalCacheKey.maturity, - cruiseSamplingInternalCacheKey.lengthStep); - } - - public ZoneCruiseSamplingInternalCacheKey toZoneKey(Zone zone) { - Objects.requireNonNull(zone); - return new ZoneCruiseSamplingInternalCacheKey(this, zone); - } - - public FishingOperationCruiseSamplingInternalCacheKey toFishingOperationKey(FishingOperation fishingOperation) { - Objects.requireNonNull(fishingOperation); - return new FishingOperationCruiseSamplingInternalCacheKey(this, fishingOperation); - } - - @Override - public String toString() { - return species.getReferenceTaxonId() - + KEY_SEPARATOR + (gender != null ? gender.getId() : null) - + KEY_SEPARATOR + maturity - + KEY_SEPARATOR + lengthStep; - } - - } - - /** - * Représente la clef d'un objet du cache. - * - * Created on 19/03/16. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.5 - */ - static class FishingOperationCruiseSamplingInternalCacheKey extends CruiseSamplingInternalCacheKey { - - private final FishingOperation fishingOperation; - - FishingOperationCruiseSamplingInternalCacheKey(CruiseSamplingInternalCacheKey cruiseSamplingInternalCacheKey, FishingOperation fishingOperation) { - super(cruiseSamplingInternalCacheKey); - this.fishingOperation = fishingOperation; - } - - @Override - public String toString() { - return fishingOperation.getId() + KEY_SEPARATOR + super.toString(); - } - } - - /** - * Représente la clef d'un objet du cache. - * - * Created on 19/03/16. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.5 - */ - static class ZoneCruiseSamplingInternalCacheKey extends CruiseSamplingInternalCacheKey { - - private final Zone zone; - - ZoneCruiseSamplingInternalCacheKey(CruiseSamplingInternalCacheKey cruiseSamplingInternalCacheKey, Zone zone) { - super(cruiseSamplingInternalCacheKey); - this.zone = zone; - } - - @Override - public String toString() { - return zone.getId() + KEY_SEPARATOR + super.toString(); - } - } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/8145-2 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 78784e8a4646fac9b27688edf1543a878b026d92 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Mar 21 03:44:44 2016 +0100 Passage en log debug sur le cache --- tutti-ui-swing/src/main/filtered-resources/log4j.properties | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tutti-ui-swing/src/main/filtered-resources/log4j.properties b/tutti-ui-swing/src/main/filtered-resources/log4j.properties index 4f2f96c..775ffb5 100644 --- a/tutti-ui-swing/src/main/filtered-resources/log4j.properties +++ b/tutti-ui-swing/src/main/filtered-resources/log4j.properties @@ -31,10 +31,9 @@ log4j.appender.stdout.layout.ConversionPattern=[%20t] %d{ISO8601} %5p (%c:%L) - # tutti levels log4j.logger.fr.ifremer=INFO -log4j.logger.fr.ifremer.tutti.ui.swing.util.SoundUtil=DEBUG +log4j.logger.fr.ifremer.tutti.service.samplingCache.CruiseSamplingInternalCache=DEBUG # Keep this one to Info to show batch tree log4j.logger.fr.ifremer.tutti.persistence.service.util.tree=INFO -log4j.logger.fr.ifremer.tutti.service.toconfirmreport=DEBUG log4j.logger.fr.ifremer.tutti.persistence.service.util.SynchronizationStatusHelper=WARN log4j.logger.fr.ifremer.adagio.core.service.technical.CacheServiceImpl=WARN -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm