Class PromotionCacheInvalidationHelper
java.lang.Object
com.broadleafcommerce.promotion.offer.service.messaging.cache.PromotionCacheInvalidationHelper
Provides supporting functionality related to cache invalidation components based on the
getSupportedProjectionTypes()
registered. This also provides the convenience of only
having to declare those supporting types in one spot, rather than repeating that declaration (and
possible code support) in multiple components.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Pojo defining the types supported for cache invalidation, as well as the send delay for cache invalidation messages (may be zero delay, in which case sending is immediate). -
Constructor Summary
ConstructorDescriptionPromotionCacheInvalidationHelper
(Supplier<com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager> managerSupplier, PromotionCacheInvalidationMessagingProperties properties) -
Method Summary
Modifier and TypeMethodDescriptionbuildRemoteEvent
(Object projection) Build a cache invalidation event for a specific mutated entitybuildRemoteRegionEvent
(Class<?> projection) Build a cache invalidation event for an entire cache regioncom.broadleafcommerce.common.messaging.notification.IdInformation
getIdInformation
(Object projection, String channelModifier) Retrieve information used during message construction for notification of cache invalidation.Class<?>
getNormalizedType
(Class<?> candidateProjection) Get the top-most type based on a possibly more derived projection type.Class<?>
getProjectionType
(Class<?> domainType) Based on a repository domain type, retrieve the associated projection setup in the system.getSendDelay
(Class<?> projection) Retrieve the send delay (if applicable) configured for the given projection type.void
init()
mapProjection
(Object entity) Given a repository domain instance, map to an instance of the associated projection.void
setSupportedProjectionTypes
(List<PromotionCacheInvalidationHelper.SupportedType> supportedProjectionTypes) boolean
shouldSendImmediately
(Class<?> projection) Whether or not the cache invalidation resulting from a mutation event for the given projection is configured to send immediately without a configured delay.
-
Constructor Details
-
PromotionCacheInvalidationHelper
public PromotionCacheInvalidationHelper(Supplier<com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager> managerSupplier, PromotionCacheInvalidationMessagingProperties properties)
-
-
Method Details
-
init
@PostConstruct public void init() -
getNormalizedType
Get the top-most type based on a possibly more derived projection type.- Parameters:
candidateProjection
- The possibly more derived projection type- Returns:
- The top-most projection (if the candidate is derived). Otherwise, will return the candidateProjection passed in. Will return null if not found.
-
getProjectionType
Based on a repository domain type, retrieve the associated projection setup in the system.- Parameters:
domainType
- The repository domain type- Returns:
- The associated projection in the system. Will return null if not found.
-
mapProjection
Given a repository domain instance, map to an instance of the associated projection.- Parameters:
entity
- A repository domain instance- Returns:
- An instance of the associated projection
-
shouldSendImmediately
Whether or not the cache invalidation resulting from a mutation event for the given projection is configured to send immediately without a configured delay. Delays are generally specified for types inPromotionCacheInvalidationMessagingProperties
, whose values are then expressed in the delay component ofPromotionCacheInvalidationHelper.SupportedType
ingetSupportedProjectionTypes()
.- Parameters:
projection
- The projection instance of the recently mutated entity- Returns:
- Whether or not the cache invalidation should be sent without delay
-
getSendDelay
Retrieve the send delay (if applicable) configured for the given projection type. SeeshouldSendImmediately(Class)
.- Parameters:
projection
- The projection instance of the recently mutated entity- Returns:
- The send delay (if applicable) configured for the given projection type. Will return null if not found.
-
getIdInformation
@Nullable public com.broadleafcommerce.common.messaging.notification.IdInformation getIdInformation(Object projection, String channelModifier) Retrieve information used during message construction for notification of cache invalidation.- Parameters:
projection
- The projection instance of the recently mutated entitychannelModifier
- A modifier key that is useful to match against a particular channel. SeeNotificationHandler.getChannelModifier()
.- Returns:
- Id related information used during message construction. Will return null if the projection is not supported.
- See Also:
-
IdInformation
-
buildRemoteEvent
Build a cache invalidation event for a specific mutated entity- Parameters:
projection
- The projection instance of the recently mutated entity- Returns:
- The cache invalidation event for that entity
-
buildRemoteRegionEvent
Build a cache invalidation event for an entire cache region- Parameters:
projection
- The class (region) for which all cache members should be evicted- Returns:
- The cache invalidation event for that region
-
getSupportedProjectionTypes
-
setSupportedProjectionTypes
public void setSupportedProjectionTypes(List<PromotionCacheInvalidationHelper.SupportedType> supportedProjectionTypes)
-