Class MongoCustomizedResourceLockRepository

    • Constructor Detail

      • MongoCustomizedResourceLockRepository

        public MongoCustomizedResourceLockRepository​(org.springframework.data.mongodb.core.MongoTemplate template,
                                                     ResourceLockProperties resourceLockProperties)
    • Method Detail

      • lockResource

        public String lockResource​(@NonNull
                                   @NonNull String contextId,
                                   @NonNull
                                   @NonNull Class<?> type,
                                   @Nullable
                                   String sandboxId,
                                   @Nullable
                                   String conceptKey)
        Description copied from interface: ResourceLockRepository
        Lock a resource indefinitely based on identifying information. Will return a token representing the lock that is suitable to be passed to ResourceLockRepository.unlockResource(String) when the work requiring the lock is complete. If unable to acquire the lock, a ResourceLockException is thrown.
        Specified by:
        lockResource in interface ResourceLockRepository<MongoResourceLock,​org.bson.types.ObjectId>
        Parameters:
        contextId - a unique id of the obtain a lock for
        type - grouping for the contextId
        sandboxId - sandbox associated with the entity
        conceptKey - a generally descriptive key that identifies the overall concept for which the lock is taking place
        Returns:
        The token that identifies the lock
      • lockResourceTemporarily

        public String lockResourceTemporarily​(@NonNull
                                              @NonNull String contextId,
                                              @NonNull
                                              @NonNull Class<?> type,
                                              @Nullable
                                              String sandboxId,
                                              @Nullable
                                              String conceptKey,
                                              @NonNull
                                              @NonNull Duration stagnationThreshold)
        Description copied from interface: ResourceLockRepository
        Lock a resource temporarily based on identifying information. Will return a token representing the lock that is suitable to be passed to ResourceLockRepository.unlockResource(String) when the work requiring the lock is complete. If unable to acquire the lock, a ResourceLockException is thrown.
        Specified by:
        lockResourceTemporarily in interface ResourceLockRepository<MongoResourceLock,​org.bson.types.ObjectId>
        Parameters:
        contextId - a unique id of the obtain a lock for
        type - grouping for the contextId
        sandboxId - sandbox associated with the entity
        conceptKey - a generally descriptive key that identifies the overall concept for which the lock is taking place
        stagnationThreshold - how long the lock should be held
        Returns:
        The token that identifies the lock
      • purgeLocks

        public void purgeLocks​(@NonNull
                               @NonNull Class<?> type,
                               @NonNull
                               @NonNull Duration lockTtl)
        Description copied from interface: ResourceLockRepository
        Deletes all non-expiring locks that are out of date according to the lockTtl and have JpaResourceLock.getTypeAlias() equal to the provided type.
        Specified by:
        purgeLocks in interface ResourceLockRepository<MongoResourceLock,​org.bson.types.ObjectId>
        Parameters:
        type - The type of lock that is to be removed
        lockTtl - How long the lock should be held. If the lock is too old, then it should be removed.
      • identifyLocksToBePurged

        protected List<MongoResourceLock> identifyLocksToBePurged​(@NonNull
                                                                  @NonNull Class<?> type,
                                                                  @NonNull
                                                                  @NonNull Duration lockTtl,
                                                                  @Nullable
                                                                  org.bson.types.ObjectId startingId)
        Identifies locks that are eligible to be purged
        Parameters:
        type - The type of lock that should be identified
        lockTtl - How long the lock should be held. If the lock is too old, then it should be removed.
        startingId - The id from which to start the retrieval of a batch of candidate records.
        Returns:
        The list of locks that are eligible to be purged
      • releaseLock

        protected void releaseLock​(MongoResourceLock lock)
        Deletes the provided lock, if its lock timestamp has not been updated since the lock was identified
        Parameters:
        lock - The lock that is to be released
      • getSandboxIdOrDefault

        protected String getSandboxIdOrDefault​(@Nullable
                                               String sandboxId)
      • getConceptKeyOrDefault

        protected String getConceptKeyOrDefault​(@Nullable
                                                String conceptKey)