Class MongoSherlock


  • public class MongoSherlock
    extends java.lang.Object
    Builds Sherlock that uses MongoDB for locking mechanism.
    • Method Detail

      • builder

        public static MongoSherlock builder()
        Returns:
        new instance of the builder
      • withMongoClient

        public MongoSherlock withMongoClient​(com.mongodb.client.MongoClient mongoClient)
        Parameters:
        mongoClient - mongo client to be used for locking
        Returns:
        the instance
      • withDatabaseName

        public MongoSherlock withDatabaseName​(java.lang.String databaseName)
        Parameters:
        databaseName - database name where locks will be stored
        Returns:
        the instance
      • withCollectionName

        public MongoSherlock withCollectionName​(java.lang.String collectionName)
        Parameters:
        collectionName - collection name where locks will be stored. Default: SherlockDefaults.DEFAULT_DB_TABLE_NAME
        Returns:
        the instance
      • withLockDuration

        public MongoSherlock withLockDuration​(java.time.Duration duration)
        Parameters:
        duration - how much time a lock should be active. When time passes lock is expired and becomes released. Default: SherlockDefaults.DEFAULT_LOCK_DURATION
        Returns:
        the instance
      • withOwnerId

        public MongoSherlock withOwnerId​(java.lang.String ownerId)
        Parameters:
        ownerId - owner id most often should be a unique application instance identifier. Default: SherlockDefaults.DEFAULT_INSTANCE_ID
        Returns:
        the instance
      • withClock

        public MongoSherlock withClock​(java.time.Clock clock)
        Parameters:
        clock - time provider used in locking mechanism. Default: SherlockDefaults.DEFAULT_CLOCK
        Returns:
        the instance
      • build

        public com.coditory.sherlock.Sherlock build()
        Returns:
        sherlock instance
        Throws:
        java.lang.IllegalArgumentException - when some required values are missing