private void removeAssociationValueFromCache(Class<?> sagaType, String sagaIdentifier, AssociationValue associationValue) { String key = cacheKey(associationValue, sagaType); Set<String> associations = associationsCache.get(key); if (associations != null && associations.remove(sagaIdentifier)) { associationsCache.put(key, associations); } }
/** * Registers the associations of a saga with given {@code sagaIdentifier} and given {@code sagaType} with the * associations cache. * * @param associationValues the association values of the saga * @param sagaIdentifier the identifier of the saga * @param sagaType the type of the saga */ protected void addCachedAssociations(Iterable<AssociationValue> associationValues, String sagaIdentifier, Class<?> sagaType) { for (AssociationValue associationValue : associationValues) { String key = cacheKey(associationValue, sagaType); Set<String> identifiers = associationsCache.get(key); if (identifiers != null && identifiers.add(sagaIdentifier)) { associationsCache.put(key, identifiers); } } }
@Override public Set<String> findSagas(Class<? extends T> sagaType, AssociationValue associationValue) { final String key = cacheKey(associationValue, sagaType); // this is a dirty read, but a cache should be thread safe anyway Set<String> associations = associationsCache.get(key); if (associations == null) { associations = delegate.findSagas(sagaType, associationValue); associationsCache.put(key, associations); } return new HashSet<>(associations); }
@Override public <S extends T> Entry<S> loadSaga(Class<S> sagaType, String sagaIdentifier) { Entry<S> saga = sagaCache.get(sagaIdentifier); if (saga == null) { saga = delegate.loadSaga(sagaType, sagaIdentifier); if (saga != null) { sagaCache.put(sagaIdentifier, new CacheEntry<T>(saga)); } } return saga; }
/** * Perform the actual loading of an aggregate. The necessary locks have been obtained. If the aggregate is * available in the cache, it is returned from there. Otherwise the underlying persistence logic is called to * retrieve the aggregate. * * @param aggregateIdentifier the identifier of the aggregate to load * @param expectedVersion The expected version of the aggregate * @return the fully initialized aggregate */ @Override protected EventSourcedAggregate<T> doLoadWithLock(String aggregateIdentifier, Long expectedVersion) { EventSourcedAggregate<T> aggregate = null; AggregateCacheEntry<T> cacheEntry = cache.get(aggregateIdentifier); if (cacheEntry != null) { aggregate = cacheEntry.recreateAggregate(aggregateModel(), eventStore, repositoryProvider, snapshotTriggerDefinition); } if (aggregate == null) { aggregate = super.doLoadWithLock(aggregateIdentifier, expectedVersion); } else if (aggregate.isDeleted()) { throw new AggregateDeletedException(aggregateIdentifier); } return aggregate; } }
EventSourcedAggregate<T> aggregateRoot = firstLevelCache.get(aggregateIdentifier); if (aggregateRoot == null) { Object cachedItem = cache.get(aggregateIdentifier); if (AggregateCacheEntry.class.isInstance(cachedItem)) { EventSourcedAggregate<T> cachedAggregate = ((AggregateCacheEntry<T>) cachedItem).recreateAggregate(
private void removeAssociationValueFromCache(Class<?> sagaType, String sagaIdentifier, AssociationValue associationValue) { String key = cacheKey(associationValue, sagaType); Set<String> associations = associationsCache.get(key); if (associations != null && associations.remove(sagaIdentifier)) { associationsCache.put(key, associations); } }
private void removeAssociationValueFromCache(Class<?> sagaType, String sagaIdentifier, AssociationValue associationValue) { String key = cacheKey(associationValue, sagaType); Set<String> associations = associationsCache.get(key); if (associations != null && associations.remove(sagaIdentifier)) { associationsCache.put(key, associations); } }
/** * Registers the associations of a saga with given {@code sagaIdentifier} and given {@code sagaType} with the * associations cache. * * @param associationValues the association values of the saga * @param sagaIdentifier the identifier of the saga * @param sagaType the type of the saga */ protected void addCachedAssociations(Iterable<AssociationValue> associationValues, String sagaIdentifier, Class<?> sagaType) { for (AssociationValue associationValue : associationValues) { String key = cacheKey(associationValue, sagaType); Set<String> identifiers = associationsCache.get(key); if (identifiers != null && identifiers.add(sagaIdentifier)) { associationsCache.put(key, identifiers); } } }
@Override public Set<String> findSagas(Class<? extends T> sagaType, AssociationValue associationValue) { final String key = cacheKey(associationValue, sagaType); // this is a dirty read, but a cache should be thread safe anyway Set<String> associations = associationsCache.get(key); if (associations == null) { associations = delegate.findSagas(sagaType, associationValue); associationsCache.put(key, associations); } return new HashSet<>(associations); }
/** * Registers the associations of a saga with given {@code sagaIdentifier} and given {@code sagaType} with the * associations cache. * * @param associationValues the association values of the saga * @param sagaIdentifier the identifier of the saga * @param sagaType the type of the saga */ protected void addCachedAssociations(Iterable<AssociationValue> associationValues, String sagaIdentifier, Class<?> sagaType) { for (AssociationValue associationValue : associationValues) { String key = cacheKey(associationValue, sagaType); Set<String> identifiers = associationsCache.get(key); if (identifiers != null && identifiers.add(sagaIdentifier)) { associationsCache.put(key, identifiers); } } }
@Override public Set<String> findSagas(Class<? extends T> sagaType, AssociationValue associationValue) { final String key = cacheKey(associationValue, sagaType); // this is a dirty read, but a cache should be thread safe anyway Set<String> associations = associationsCache.get(key); if (associations == null) { associations = delegate.findSagas(sagaType, associationValue); associationsCache.put(key, associations); } return new HashSet<>(associations); }
@Override public <S extends T> Entry<S> loadSaga(Class<S> sagaType, String sagaIdentifier) { Entry<S> saga = sagaCache.get(sagaIdentifier); if (saga == null) { saga = delegate.loadSaga(sagaType, sagaIdentifier); if (saga != null) { sagaCache.put(sagaIdentifier, new CacheEntry<T>(saga)); } } return saga; }
@Override public <S extends T> Entry<S> loadSaga(Class<S> sagaType, String sagaIdentifier) { Entry<S> saga = sagaCache.get(sagaIdentifier); if (saga == null) { saga = delegate.loadSaga(sagaType, sagaIdentifier); if (saga != null) { sagaCache.put(sagaIdentifier, new CacheEntry<T>(saga)); } } return saga; }
/** * Perform the actual loading of an aggregate. The necessary locks have been obtained. If the aggregate is * available in the cache, it is returned from there. Otherwise the underlying persistence logic is called to * retrieve the aggregate. * * @param aggregateIdentifier the identifier of the aggregate to load * @param expectedVersion The expected version of the aggregate * @return the fully initialized aggregate */ @Override protected EventSourcedAggregate<T> doLoadWithLock(String aggregateIdentifier, Long expectedVersion) { EventSourcedAggregate<T> aggregate = null; AggregateCacheEntry<T> cacheEntry = cache.get(aggregateIdentifier); if (cacheEntry != null) { aggregate = cacheEntry.recreateAggregate(aggregateModel(), eventStore, repositoryProvider, snapshotTriggerDefinition); } if (aggregate == null) { aggregate = super.doLoadWithLock(aggregateIdentifier, expectedVersion); } else if (aggregate.isDeleted()) { throw new AggregateDeletedException(aggregateIdentifier); } return aggregate; }
/** * Perform the actual loading of an aggregate. The necessary locks have been obtained. If the aggregate is * available in the cache, it is returned from there. Otherwise the underlying persistence logic is called to * retrieve the aggregate. * * @param aggregateIdentifier the identifier of the aggregate to load * @param expectedVersion The expected version of the aggregate * @return the fully initialized aggregate */ @Override protected EventSourcedAggregate<T> doLoadWithLock(String aggregateIdentifier, Long expectedVersion) { EventSourcedAggregate<T> aggregate = null; AggregateCacheEntry<T> cacheEntry = cache.get(aggregateIdentifier); if (cacheEntry != null) { aggregate = cacheEntry.recreateAggregate(aggregateModel(), eventStore, repositoryProvider, snapshotTriggerDefinition); } if (aggregate == null) { aggregate = super.doLoadWithLock(aggregateIdentifier, expectedVersion); } else if (aggregate.isDeleted()) { throw new AggregateDeletedException(aggregateIdentifier); } return aggregate; } }
EventSourcedAggregate<T> aggregateRoot = firstLevelCache.get(aggregateIdentifier); if (aggregateRoot == null) { Object cachedItem = cache.get(aggregateIdentifier); if (AggregateCacheEntry.class.isInstance(cachedItem)) { EventSourcedAggregate<T> cachedAggregate = ((AggregateCacheEntry<T>) cachedItem).recreateAggregate(
EventSourcedAggregate<T> aggregateRoot = firstLevelCache.get(aggregateIdentifier); if (aggregateRoot == null) { Object cachedItem = cache.get(aggregateIdentifier); if (AggregateCacheEntry.class.isInstance(cachedItem)) { EventSourcedAggregate<T> cachedAggregate = ((AggregateCacheEntry<T>) cachedItem).recreateAggregate(