Class AmazonDynamoDBLockClientOptions.AmazonDynamoDBLockClientOptionsBuilder
- java.lang.Object
-
- com.amazonaws.services.dynamodbv2.AmazonDynamoDBLockClientOptions.AmazonDynamoDBLockClientOptionsBuilder
-
- Enclosing class:
- AmazonDynamoDBLockClientOptions
public static class AmazonDynamoDBLockClientOptions.AmazonDynamoDBLockClientOptionsBuilder extends Object
A builder for setting up an AmazonDynamoDBLockClientOptions object. By default, it is setup to have a partition key name of "key," a lease duration of 20 seconds, and a default heartbeat period of 5 seconds. These defaults can be overriden.
-
-
Method Summary
-
-
-
Method Detail
-
withPartitionKeyName
public AmazonDynamoDBLockClientOptions.AmazonDynamoDBLockClientOptionsBuilder withPartitionKeyName(String partitionKeyName)
- Parameters:
partitionKeyName- The partition key name. If not specified, the default partition key name of "key" is used.- Returns:
- a reference to this builder for fluent method chaining
-
withSortKeyName
public AmazonDynamoDBLockClientOptions.AmazonDynamoDBLockClientOptionsBuilder withSortKeyName(String sortKeyName)
- Parameters:
sortKeyName- The sort key name. If not specified, we assume that the table does not have a sort key defined.- Returns:
- a reference to this builder for fluent method chaining
-
withOwnerName
public AmazonDynamoDBLockClientOptions.AmazonDynamoDBLockClientOptionsBuilder withOwnerName(String ownerName)
- Parameters:
ownerName- The person that is acquiring the lock (for example, box.amazon.com)- Returns:
- a reference to this builder for fluent method chaining
-
withLeaseDuration
public AmazonDynamoDBLockClientOptions.AmazonDynamoDBLockClientOptionsBuilder withLeaseDuration(Long leaseDuration)
- Parameters:
leaseDuration- The length of time that the lease for the lock will be granted for. If this is set to, for example, 30 seconds, then the lock will expire if the heartbeat is not sent for at least 30 seconds (which would happen if the box or the heartbeat thread dies, for example.)- Returns:
- a reference to this builder for fluent method chaining
-
withHeartbeatPeriod
public AmazonDynamoDBLockClientOptions.AmazonDynamoDBLockClientOptionsBuilder withHeartbeatPeriod(Long heartbeatPeriod)
- Parameters:
heartbeatPeriod- How often to update DynamoDB to note that the instance is still running (recommendation is to make this at least 3 times smaller than the leaseDuration -- for example heartBeatPeriod=1 second, leaseDuration=10 seconds could be a reasonable configuration, make sure to include a buffer for network latency.)- Returns:
- a reference to this builder for fluent method chaining
-
withTimeUnit
public AmazonDynamoDBLockClientOptions.AmazonDynamoDBLockClientOptionsBuilder withTimeUnit(TimeUnit timeUnit)
- Parameters:
timeUnit- What time unit to use for all times in this object, including heartbeatPeriod and leaseDuration.- Returns:
- a reference to this builder for fluent method chaining
-
withCreateHeartbeatBackgroundThread
public AmazonDynamoDBLockClientOptions.AmazonDynamoDBLockClientOptionsBuilder withCreateHeartbeatBackgroundThread(Boolean createHeartbeatBackgroundThread)
- Parameters:
createHeartbeatBackgroundThread- Whether or not to create a thread to automatically heartbeat (if false, you must call sendHeartbeat manually)- Returns:
- a reference to this builder for fluent method chaining
-
withHoldLockOnServiceUnavailable
public AmazonDynamoDBLockClientOptions.AmazonDynamoDBLockClientOptionsBuilder withHoldLockOnServiceUnavailable(Boolean holdLockOnServiceUnavailable)
This parameter should be set to true only in the applications which do not have strict locking requirements. When this is set to true, on DynamoDB service unavailable errors it is possible that two different clients can hold the lock. When heartbeat fails for lease duration period, the lock expires. If this parameter is set to true, and if a heartbeat receives AmazonServiceException with a status code of HttpStatus.SC_SERVICE_UNAVAILABLE(503), the lock client will assume that the heartbeat was a success and update the local state accordingly and it will keep holding the lock.- Parameters:
holdLockOnServiceUnavailable- Whether or not to hold the lock if DynamoDB Service is unavailable- Returns:
- a reference to this builder for fluent method chaining
-
withMaxLockObservationCacheSize
public AmazonDynamoDBLockClientOptions.AmazonDynamoDBLockClientOptionsBuilder withMaxLockObservationCacheSize(Integer maxLockObservationCacheSize)
- Parameters:
maxLockObservationCacheSize- Maximum number of lock observations to keep for shouldSkipBlockingWait stale lock detection. This is an approximate maximum under concurrent access, and this value must be greater than zero. If an observation is evicted, a skip-blocking-wait caller must observe the same record version number again before it can acquire the stale lock.- Returns:
- a reference to this builder for fluent method chaining
-
build
public AmazonDynamoDBLockClientOptions build()
Builds an AmazonDynamoDBLockClientOptions. If required parametes are not set, will throw an IllegalArgumentsException.- Returns:
- Returns the AmazonDynamoDBLockClientOptions which can be passed to the lock client constructor.
-
-